Merge branch 'MDL-27594' of git://github.com/stronk7/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2011-05-25 10:16:10 +02:00
commit 28e2b08582
2 changed files with 18 additions and 16 deletions

View File

@ -174,12 +174,12 @@ abstract class simplified_parser_processor extends progressive_parser_processor
*/ */
public function after_path($path) { public function after_path($path) {
$toprocess = false; $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 // we process pending startend notifications until one matching end is found
if ($element = reset($this->startendinfo)) { if ($element = reset($this->startendinfo)) {
$elepath = $element['path']; $elepath = $element['path'];
$eleaction = $element['action']; $eleaction = $element['action'];
if ($eleaction = 'end' && strpos($elepath, $path) === 0) { if (strpos($elepath, $path) === 0) {
$toprocess = true; $toprocess = true;
} }

View File

@ -652,43 +652,45 @@ class progressive_parser_test extends UnitTestCase {
function helper_check_notifications_order_integrity($notifications) { function helper_check_notifications_order_integrity($notifications) {
$numerrors = 0; $numerrors = 0;
$notifpile = array('pilebase' => 'start'); $notifpile = array('pilebase' => 'start');
$lastpile = 'start:pilebase'; $lastnotif = 'start:pilebase';
foreach ($notifications as $notif) { 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); $notiftype = preg_replace('/:.*/', '', $notif);
$notifpath = preg_replace('/.*:/', '', $notif); $notifpath = preg_replace('/.*:/', '', $notif);
$notiflevel = strlen(preg_replace('/[^\/]/', '', $notifpath));
switch ($notiftype) { switch ($notiftype) {
case 'process': case 'process':
if ($lastpilepath != $notifpath or $lastpiletype != 'start') { if ($lastnotifpath != $notifpath or $lastnotiftype != 'start') {
$numerrors++; // Only start for same path is allowed before process $numerrors++; // Only start for same path from last notification is allowed before process
} }
$notifpile[$notifpath] = 'process'; // Update the status in the pile $notifpile[$notifpath] = 'process'; // Update the status in the pile
break; break;
case 'end': case 'end':
if ($lastpilepath != $notifpath or ($lastpiletype != 'process' and $lastpiletype != 'start')) { 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 unset($notifpile[$notifpath]); // Delete from the pile
break; break;
case 'start': case 'start':
if (array_key_exists($notifpath, $notifpile) or $notiflevel <= $lastpilelevel) { 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 $notifpile[$notifpath] = 'start'; // Add to the pile
break; break;
default: default:
$numerrors++; // Incorrect type of notification => error $numerrors++; // Incorrect type of notification => error
} }
// Update lastpile // Update lastnotif
end($notifpile); $lastnotif = $notif;
$path = key($notifpile);
$type = $notifpile[$path];
$lastpile = $type. ':' . $path;
} }
return $numerrors; return $numerrors;
} }