/** * Verify that the given layout matches that expected. * @param array $expectedlayout as for $layout in {@link create_test_quiz()}. * @param \mod_quiz\structure $structure the structure to test. */ protected function assert_quiz_layout($expectedlayout, \mod_quiz\structure $structure) { $sections = $structure->get_sections(); $slot = 1; foreach ($expectedlayout as $item) { if (is_string($item)) { list($heading, $shuffle) = $this->parse_section_name($item); $section = array_shift($sections); if ($slot > 1 && $section->heading == '' && $section->firstslot == 1) { // The array $expectedlayout did not contain default first quiz section, so skip over it. $section = array_shift($sections); } $this->assertEquals($slot, $section->firstslot); $this->assertEquals($heading, $section->heading); $this->assertEquals($shuffle, $section->shufflequestions); } else { list($name, $page, $qtype) = $item; $question = $structure->get_question_in_slot($slot); $this->assertEquals($name, $question->name); $this->assertEquals($slot, $question->slot, 'Slot number wrong for question ' . $name); $this->assertEquals($qtype, $question->qtype, 'Question type wrong for question ' . $name); $this->assertEquals($page, $question->page, 'Page number wrong for question ' . $name); $slot += 1; } } if ($slot - 1 != count($structure->get_slots())) { $this->fail('The quiz contains more slots than expected.'); } if (!empty($sections)) { $section = array_shift($sections); if ($section->heading != '' || $section->firstslot != 1) { $this->fail('Unexpected section (' . $section->heading . ') found in the quiz.'); } } }