From d4dd06591bce0921fbbd4844def92570df59d5f1 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Tue, 24 May 2011 11:55:39 +0200 Subject: [PATCH] MDL-27594 backup - out unused (and incorrect) condition + stronger tests --- .../simplified_parser_processor.class.php | 4 +-- .../util/xml/parser/simpletest/testparser.php | 30 ++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/backup/util/xml/parser/processors/simplified_parser_processor.class.php b/backup/util/xml/parser/processors/simplified_parser_processor.class.php index c65a4be093f..c3c5cdd3306 100644 --- a/backup/util/xml/parser/processors/simplified_parser_processor.class.php +++ b/backup/util/xml/parser/processors/simplified_parser_processor.class.php @@ -174,12 +174,12 @@ abstract class simplified_parser_processor extends progressive_parser_processor */ public function after_path($path) { $toprocess = false; - // If the path being closed matches (same or parent) the last path in the stack + // If the path being closed matches (same or parent) the first path in the stack // we process pending startend notifications until one matching end is found if ($element = reset($this->startendinfo)) { $elepath = $element['path']; $eleaction = $element['action']; - if ($eleaction = 'end' && strpos($elepath, $path) === 0) { + if (strpos($elepath, $path) === 0) { $toprocess = true; } diff --git a/backup/util/xml/parser/simpletest/testparser.php b/backup/util/xml/parser/simpletest/testparser.php index 589f8c939b9..cae713f224b 100644 --- a/backup/util/xml/parser/simpletest/testparser.php +++ b/backup/util/xml/parser/simpletest/testparser.php @@ -652,43 +652,45 @@ class progressive_parser_test extends UnitTestCase { function helper_check_notifications_order_integrity($notifications) { $numerrors = 0; $notifpile = array('pilebase' => 'start'); - $lastpile = 'start:pilebase'; + $lastnotif = 'start:pilebase'; foreach ($notifications as $notif) { - $lastpilelevel = strlen(preg_replace('/[^\/]/', '', $lastpile)); - $lastpiletype = preg_replace('/:.*/', '', $lastpile); - $lastpilepath = preg_replace('/.*:/', '', $lastpile); - $notiflevel = strlen(preg_replace('/[^\/]/', '', $notif)); + $lastpiletype = end($notifpile); + $lastpilepath = key($notifpile); + $lastpilelevel = strlen(preg_replace('/[^\/]/', '', $lastpilepath)); + + $lastnotiftype = preg_replace('/:.*/', '', $lastnotif); + $lastnotifpath = preg_replace('/.*:/', '', $lastnotif); + $lastnotiflevel = strlen(preg_replace('/[^\/]/', '', $lastnotifpath)); + $notiftype = preg_replace('/:.*/', '', $notif); $notifpath = preg_replace('/.*:/', '', $notif); + $notiflevel = strlen(preg_replace('/[^\/]/', '', $notifpath)); switch ($notiftype) { case 'process': - if ($lastpilepath != $notifpath or $lastpiletype != 'start') { - $numerrors++; // Only start for same path is allowed before process + if ($lastnotifpath != $notifpath or $lastnotiftype != 'start') { + $numerrors++; // Only start for same path from last notification is allowed before process } $notifpile[$notifpath] = 'process'; // Update the status in the pile break; case 'end': if ($lastpilepath != $notifpath or ($lastpiletype != 'process' and $lastpiletype != 'start')) { - $numerrors++; // Only process for same path is allowed before end + $numerrors++; // Only process and start for same path from last pile is allowed before end } unset($notifpile[$notifpath]); // Delete from the pile break; case 'start': if (array_key_exists($notifpath, $notifpile) or $notiflevel <= $lastpilelevel) { - $numerrors++; // If same path exists or the level is < than the last one + $numerrors++; // Only non existing in pile and with level > last pile is allowed on start } $notifpile[$notifpath] = 'start'; // Add to the pile break; default: $numerrors++; // Incorrect type of notification => error } - // Update lastpile - end($notifpile); - $path = key($notifpile); - $type = $notifpile[$path]; - $lastpile = $type. ':' . $path; + // Update lastnotif + $lastnotif = $notif; } return $numerrors; }