コード例 #1
0
 /**
  * test how the grouped processor and the order of start/process/end events happens
  * with one real fragment of one backup 1.9 file, where some problems
  * were found by David, hence we honor him in the name of the test ;-)
  */
 function test_grouped_david_backup19_file_fragment()
 {
     global $CFG;
     // Instantiate progressive_parser
     $pp = new progressive_parser();
     // Instantiate grouped_parser_processor
     $pr = new mock_grouped_parser_processor();
     // Add interesting paths
     $pr->add_path('/MOODLE_BACKUP/COURSE');
     $pr->add_path('/MOODLE_BACKUP/COURSE/SECTIONS/SECTION', true);
     $pr->add_path('/MOODLE_BACKUP/COURSE/SECTIONS/SECTION/MODS/MOD');
     $pr->add_path('/MOODLE_BACKUP/COURSE/SECTIONS/SECTION/MODS/MOD/ROLES_OVERRIDES');
     $this->assertTrue($pr instanceof progressive_parser_processor);
     // Assign processor to parser
     $pp->set_processor($pr);
     // Set file from fixtures
     $pp->set_file($CFG->dirroot . '/backup/util/xml/parser/simpletest/fixtures/test5.xml');
     // Process the file
     $pp->process();
     // Get all the simplified chunks and perform various validations
     $chunks = $pr->get_chunks();
     $this->assertEqual(count($chunks), 1);
     // Only 1, the SECTION one
     // Now check start notifications
     $snotifs = $pr->get_start_notifications();
     // Check we have received the correct number of notifications
     $this->assertEqual(count($snotifs), 2);
     // Check first and last notifications
     $this->assertEqual($snotifs[0], '/MOODLE_BACKUP/COURSE');
     $this->assertEqual($snotifs[1], '/MOODLE_BACKUP/COURSE/SECTIONS/SECTION');
     // Now check end notifications
     $enotifs = $pr->get_end_notifications();
     // Check we have received the correct number of notifications
     $this->assertEqual(count($snotifs), 2);
     // End tags are dispatched for empties (ROLES_OVERRIDES)
     // Check first, and last notifications
     $this->assertEqual($enotifs[0], '/MOODLE_BACKUP/COURSE/SECTIONS/SECTION');
     $this->assertEqual($enotifs[1], '/MOODLE_BACKUP/COURSE');
     // Check start and end notifications are balanced
     sort($snotifs);
     sort($enotifs);
     $this->assertEqual($snotifs, $enotifs);
     // Now verify that the start/process/end order is correct
     $allnotifs = $pr->get_all_notifications();
     $this->assertEqual(count($allnotifs), count($snotifs) + count($enotifs) + count($chunks));
     // The count
     // Check integrity of the notifications
     $errcount = $this->helper_check_notifications_order_integrity($allnotifs);
     $this->assertEqual($errcount, 0);
     // No errors found, plz
 }
コード例 #2
0
ファイル: parser_test.php プロジェクト: evltuma/moodle
 /**
  */
 function test_grouped_at_empty_node()
 {
     global $CFG;
     // Instantiate progressive_parser.
     $pp = new progressive_parser();
     // Instantiate grouped_parser_processor.
     $pr = new mock_grouped_parser_processor();
     $this->assertTrue($pr instanceof progressive_parser_processor);
     // Add interesting paths - moodle1 style.
     $pr->add_path('/test/MOODLE_BACKUP/COURSE/FORMATDATA', true);
     $pr->add_path('/test/MOODLE_BACKUP/COURSE/FORMATDATA/WEEKS/WEEK');
     $pr->add_path('/test/MOODLE_BACKUP/COURSE/EMPTYGROUPED', true);
     $pr->add_path('/test/MOODLE_BACKUP/COURSE/SECONDGROUPED', true);
     $pr->add_path('/test/MOODLE_BACKUP/COURSE/SECONDGROUPED/SUBS/SUB');
     // Add interesting paths - moodle2 style.
     $pr->add_path('/test/moodle2/grouped', true);
     $pr->add_path('/test/moodle2/grouped/subs/sub');
     $pr->add_path('/test/moodle2/groupedemptywithattr', true);
     $pr->add_path('/test/moodle2/groupednonemptywithattr', true);
     $pr->add_path('/test/moodle2/groupednonemptywithattr/subs/sub');
     // Assign processor to parser.
     $pp->set_processor($pr);
     // Set file from fixtures.
     $pp->set_file($CFG->dirroot . '/backup/util/xml/parser/tests/fixtures/test6.xml');
     // Process the file.
     $pp->process();
     // Get all the simplified chunks and perform various validations.
     $chunks = $pr->get_chunks();
     $this->assertEquals(count($chunks), 6);
     // All grouped elements.
     // Check some random data.
     $this->assertEquals('/test/MOODLE_BACKUP/COURSE/FORMATDATA', $chunks[0]['path']);
     $this->assertEquals(2, $chunks[0]['tags']['WEEKS']['WEEK'][1]['SECTION']);
     $this->assertEquals('/test/MOODLE_BACKUP/COURSE/EMPTYGROUPED', $chunks[1]['path']);
     $this->assertEquals(array(), $chunks[1]['tags']);
     $this->assertEquals('/test/MOODLE_BACKUP/COURSE/SECONDGROUPED', $chunks[2]['path']);
     $this->assertEquals('Unit tests rock!', $chunks[2]['tags']['SUBS']['SUB'][0]['PROP']);
     $this->assertEquals('/test/moodle2/grouped', $chunks[3]['path']);
     $this->assertFalse(isset($chunks[3]['tags']['id']));
     // No final elements, this should be fixed one day.
     $this->assertEquals(34, $chunks[3]['tags']['subs']['sub'][0]['id']);
     // We have final element so this is parsed.
     $this->assertEquals('Oh yeah', $chunks[3]['tags']['subs']['sub'][0]['prop']);
     $this->assertEquals('/test/moodle2/groupednonemptywithattr', $chunks[4]['path']);
     $this->assertEquals(78, $chunks[4]['tags']['id']);
     // We have final element so this is parsed.
     $this->assertEquals('Go baby go', $chunks[4]['tags']['prop']);
     $this->assertEquals(89, $chunks[4]['tags']['subs']['sub'][0]['id']);
     $this->assertEquals('http://moodle.org', $chunks[4]['tags']['subs']['sub'][0]['prop']);
     $this->assertEquals('/test/moodle2/groupedemptywithattr', $chunks[5]['path']);
     $this->assertFalse(isset($chunks[5]['tags']['attr']));
     // No final elements, this should be fixed one day.
     // Now check start notifications.
     $snotifs = $pr->get_start_notifications();
     // Check we have received the correct number of notifications.
     $this->assertEquals(count($snotifs), 6);
     // Check the order of notifications (in order they appear in test6.xml).
     $this->assertEquals('/test/MOODLE_BACKUP/COURSE/FORMATDATA', $snotifs[0]);
     $this->assertEquals('/test/MOODLE_BACKUP/COURSE/EMPTYGROUPED', $snotifs[1]);
     $this->assertEquals('/test/MOODLE_BACKUP/COURSE/SECONDGROUPED', $snotifs[2]);
     $this->assertEquals('/test/moodle2/grouped', $snotifs[3]);
     $this->assertEquals('/test/moodle2/groupednonemptywithattr', $snotifs[4]);
     $this->assertEquals('/test/moodle2/groupedemptywithattr', $snotifs[5]);
     // Now check end notifications.
     $enotifs = $pr->get_end_notifications();
     // Check we have received the correct number of notifications.
     $this->assertEquals(count($enotifs), 6);
     // Check the order of notifications (in order they appear in test6.xml).
     $this->assertEquals('/test/MOODLE_BACKUP/COURSE/FORMATDATA', $enotifs[0]);
     $this->assertEquals('/test/MOODLE_BACKUP/COURSE/EMPTYGROUPED', $enotifs[1]);
     $this->assertEquals('/test/MOODLE_BACKUP/COURSE/SECONDGROUPED', $enotifs[2]);
     $this->assertEquals('/test/moodle2/grouped', $enotifs[3]);
     $this->assertEquals('/test/moodle2/groupednonemptywithattr', $enotifs[4]);
     $this->assertEquals('/test/moodle2/groupedemptywithattr', $enotifs[5]);
     // Now verify that the start/process/end order is correct.
     $allnotifs = $pr->get_all_notifications();
     $this->assertEquals(count($allnotifs), count($snotifs) + count($enotifs) + count($chunks));
     // Check integrity of the notifications.
     $errcount = $this->helper_check_notifications_order_integrity($allnotifs);
     $this->assertEquals(0, $errcount);
 }
コード例 #3
0
ファイル: testparser.php プロジェクト: nfreear/moodle
 function test_grouped_parser_results()
 {
     global $CFG;
     // Instantiate progressive_parser
     $pp = new progressive_parser();
     // Instantiate grouped_parser_processor
     $pr = new mock_grouped_parser_processor();
     // Add interesting paths
     $pr->add_path('/activity');
     $pr->add_path('/activity/glossary', true);
     $pr->add_path('/activity/glossary/entries/entry');
     $pr->add_path('/activity/glossary/entries/entry/aliases/alias');
     $pr->add_path('/activity/glossary/entries/entry/ratings/rating');
     $pr->add_path('/activity/glossary/categories/category');
     $pr->add_path('/activity/glossary/onetest');
     $pr->add_path('/activity/glossary/othertest');
     $this->assertTrue($pr instanceof progressive_parser_processor);
     // Assign processor to parser
     $pp->set_processor($pr);
     // Set file from fixtures
     $pp->set_file($CFG->dirroot . '/backup/util/xml/parser/simpletest/fixtures/test4.xml');
     // Process the file
     $pp->process();
     // Get processor debug info
     $debug = $pr->debug_info();
     $this->assertTrue(is_array($debug));
     $this->assertTrue(array_key_exists('chunks', $debug));
     // Check the number of chunks is correct for the file
     $this->assertEqual($debug['chunks'], 2);
     // Get all the simplified chunks and perform various validations
     $chunks = $pr->get_chunks();
     // Check we have received the correct number of chunks
     $this->assertEqual(count($chunks), 2);
     // chunk[0] (/activity) tests
     $this->assertEqual(count($chunks[0]), 3);
     $this->assertEqual($chunks[0]['path'], '/activity');
     $this->assertEqual($chunks[0]['level'], '2');
     $tags = $chunks[0]['tags'];
     $this->assertEqual(count($tags), 4);
     $this->assertEqual($tags['id'], 1);
     $this->assertEqual($tags['moduleid'], 5);
     $this->assertEqual($tags['modulename'], 'glossary');
     $this->assertEqual($tags['contextid'], 26);
     $this->assertEqual($chunks[0]['level'], '2');
     // chunk[1] (grouped /activity/glossary tests)
     $this->assertEqual(count($chunks[1]), 3);
     $this->assertEqual($chunks[1]['path'], '/activity/glossary');
     $this->assertEqual($chunks[1]['level'], '3');
     $tags = $chunks[1]['tags'];
     $this->assertEqual(count($tags), 27);
     $this->assertEqual($tags['id'], 1);
     $this->assertEqual($tags['intro'], '<p>One simple glossary to test backup &amp; restore. Here it\'s the standard image:</p>' . "\n" . '<p><img src="@@PLUGINFILE@@/88_31.png" alt="pwd by moodle" width="88" height="31" /></p>');
     $this->assertEqual($tags['timemodified'], 1275639747);
     $this->assertTrue(!isset($tags['categories']));
     $this->assertTrue(isset($tags['entries']));
     $this->assertTrue(isset($tags['onetest']));
     $this->assertTrue(isset($tags['othertest']));
     // Various tests under the entries
     $entries = $chunks[1]['tags']['entries']['entry'];
     $this->assertEqual(count($entries), 2);
     // First entry
     $entry1 = $entries[0];
     $this->assertEqual(count($entry1), 17);
     $this->assertEqual($entry1['id'], 1);
     $this->assertEqual($entry1['userid'], 2);
     $this->assertEqual($entry1['concept'], 'dog');
     $this->assertEqual($entry1['definition'], '<p>Traditional enemies of cats</p>');
     $this->assertTrue(isset($entry1['aliases']));
     $this->assertTrue(isset($entry1['ratings']));
     // aliases of first entry
     $aliases = $entry1['aliases']['alias'];
     $this->assertEqual(count($aliases), 1);
     // first alias
     $alias1 = $aliases[0];
     $this->assertEqual(count($alias1), 2);
     $this->assertEqual($alias1['id'], 1);
     $this->assertEqual($alias1['alias_text'], 'dogs');
     // ratings of first entry
     $ratings = $entry1['ratings']['rating'];
     $this->assertEqual(count($ratings), 1);
     // first rating
     $rating1 = $ratings[0];
     $this->assertEqual(count($rating1), 6);
     $this->assertEqual($rating1['id'], 2);
     $this->assertEqual($rating1['value'], 6);
     $this->assertEqual($rating1['timemodified'], '1275639797');
     // Second entry
     $entry2 = $entries[1];
     $this->assertEqual(count($entry2), 17);
     $this->assertEqual($entry2['id'], 2);
     $this->assertEqual($entry2['userid'], 2);
     $this->assertEqual($entry2['concept'], 'cat');
     $this->assertEqual($entry2['definition'], '<p>traditional enemies of dogs</p>');
     $this->assertTrue(isset($entry2['aliases']));
     $this->assertTrue(isset($entry2['ratings']));
     // aliases of first entry
     $aliases = $entry2['aliases']['alias'];
     $this->assertEqual(count($aliases), 2);
     // first alias
     $alias1 = $aliases[0];
     $this->assertEqual(count($alias1), 2);
     $this->assertEqual($alias1['id'], 2);
     $this->assertEqual($alias1['alias_text'], 'cats');
     // second alias
     $alias2 = $aliases[1];
     $this->assertEqual(count($alias2), 2);
     $this->assertEqual($alias2['id'], 3);
     $this->assertEqual($alias2['alias_text'], 'felines');
     // ratings of first entry
     $ratings = $entry2['ratings']['rating'];
     $this->assertEqual(count($ratings), 1);
     // first rating
     $rating1 = $ratings[0];
     $this->assertEqual(count($rating1), 6);
     $this->assertEqual($rating1['id'], 1);
     $this->assertEqual($rating1['value'], 5);
     $this->assertEqual($rating1['scaleid'], 10);
     // Onetest test (only 1 level nested)
     $onetest = $tags['onetest'];
     $this->assertEqual(count($onetest), 2);
     $this->assertEqual(count($onetest[0]), 2);
     $this->assertEqual($onetest[0]['name'], 1);
     $this->assertEqual($onetest[0]['value'], 1);
     $this->assertEqual(count($onetest[1]), 2);
     $this->assertEqual($onetest[1]['name'], 2);
     $this->assertEqual($onetest[1]['value'], 2);
     // Other test (0 level nested, only last one is retrieved)
     $othertest = $tags['othertest'];
     $this->assertEqual(count($othertest), 1);
     $this->assertEqual(count($othertest[0]), 2);
     $this->assertEqual($othertest[0]['name'], 4);
     $this->assertEqual($othertest[0]['value'], 5);
     // Now check start notifications
     $snotifs = $pr->get_start_notifications();
     // Check we have received the correct number of notifications
     $this->assertEqual(count($snotifs), 2);
     // Check first and last notifications
     $this->assertEqual($snotifs[0], '/activity');
     $this->assertEqual($snotifs[1], '/activity/glossary');
     // Now check end notifications
     $enotifs = $pr->get_end_notifications();
     // Check we have received the correct number of notifications
     $this->assertEqual(count($snotifs), 2);
     // Check first, and last notifications
     $this->assertEqual($enotifs[0], '/activity/glossary');
     $this->assertEqual($enotifs[1], '/activity');
     // Check start and end notifications are balanced
     sort($snotifs);
     sort($enotifs);
     $this->assertEqual($snotifs, $enotifs);
 }