Ejemplo n.º 1
0
 /**
  * Get an instance of the {@link \mod_quiz\structure} class for this quiz.
  * @return \mod_quiz\structure describes the questions in the quiz.
  */
 public function get_structure()
 {
     return \mod_quiz\structure::create_for_quiz($this);
 }
Ejemplo n.º 2
0
 public function test_update_question_dependency()
 {
     $quizobj = $this->create_test_quiz(array(array('TF1', 1, 'truefalse'), array('TF2', 1, 'truefalse')));
     $structure = \mod_quiz\structure::create_for_quiz($quizobj);
     // Test adding a dependency.
     $slotid = $structure->get_slot_id_for_slot(2);
     $structure->update_question_dependency($slotid, true);
     // Having called update page break, we need to reload $structure.
     $structure = \mod_quiz\structure::create_for_quiz($quizobj);
     $this->assertEquals(1, $structure->is_question_dependent_on_previous_slot(2));
     // Test removing a dependency.
     $structure->update_question_dependency($slotid, false);
     // Having called update page break, we need to reload $structure.
     $structure = \mod_quiz\structure::create_for_quiz($quizobj);
     $this->assertEquals(0, $structure->is_question_dependent_on_previous_slot(2));
 }
Ejemplo n.º 3
0
 /**
  * Test updating pagebreaks in the quiz.
  */
 public function test_update_question_dependency()
 {
     // Create a test quiz with 8 questions.
     list($quiz, $cm, $course) = $this->prepare_quiz_data();
     $this->add_eight_questions_to_the_quiz($quiz);
     $quizobj = new quiz($quiz, $cm, $course);
     $structure = \mod_quiz\structure::create_for_quiz($quizobj);
     // Store the original order of slots, so we can assert what has changed.
     $originalslotids = array();
     foreach ($structure->get_slots() as $slot) {
         $originalslotids[$slot->slot] = $slot->id;
     }
     // Test adding a dependency.
     $slotid = $structure->get_slot_id_for_slot(3);
     $structure->update_question_dependency($slotid, true);
     // Having called update page break, we need to reload $structure.
     $structure = \mod_quiz\structure::create_for_quiz($quizobj);
     $this->assertEquals(1, $structure->is_question_dependent_on_previous_slot(3));
     // Test removing a dependency.
     $structure->update_question_dependency($slotid, false);
     // Having called update page break, we need to reload $structure.
     $structure = \mod_quiz\structure::create_for_quiz($quizobj);
     $this->assertEquals(0, $structure->is_question_dependent_on_previous_slot(3));
 }
 /**
  * Test updating pagebreaks in the quiz.
  */
 public function test_update_page_break()
 {
     // Create a test quiz with 8 questions.
     list($quiz, $cm, $course) = $this->prepare_quiz_data();
     $this->add_eight_questions_to_the_quiz($quiz);
     $quizobj = new quiz($quiz, $cm, $course);
     $structure = \mod_quiz\structure::create_for_quiz($quizobj);
     // Store the original order of slots, so we can assert what has changed.
     $originalslotids = array();
     foreach ($structure->get_slots() as $slot) {
         $originalslotids[$slot->slot] = $slot->id;
     }
     // Test removing a page break.
     $slotid = $structure->get_question_in_slot(2)->slotid;
     $type = \mod_quiz\repaginate::LINK;
     $slots = $structure->update_page_break($quiz, $slotid, $type);
     // Having called update page break, we need to reload $structure.
     $structure = \mod_quiz\structure::create_for_quiz($quizobj);
     $this->assert_quiz_layout(array($originalslotids[1] => 1, $originalslotids[2] => 1, $originalslotids[3] => 1, $originalslotids[4] => 1, $originalslotids[5] => 1, $originalslotids[6] => 1, $originalslotids[7] => 2, $originalslotids[8] => 3), $structure);
     // Test adding a page break.
     $slotid = $structure->get_question_in_slot(2)->slotid;
     $type = \mod_quiz\repaginate::UNLINK;
     $slots = $structure->update_page_break($quiz, $slotid, $type);
     // Having called update page break, we need to reload $structure.
     $structure = \mod_quiz\structure::create_for_quiz($quizobj);
     $this->assert_quiz_layout(array($originalslotids[1] => 1, $originalslotids[2] => 2, $originalslotids[3] => 2, $originalslotids[4] => 2, $originalslotids[5] => 2, $originalslotids[6] => 2, $originalslotids[7] => 3, $originalslotids[8] => 4), $structure);
 }
Ejemplo n.º 5
0
 /**
  * Create a quiz, add five questions to the quiz
  * which are all on one page and return the quiz object.
  */
 private function get_quiz_object()
 {
     global $SITE;
     $this->resetAfterTest(true);
     // Make a quiz.
     $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
     $quiz = $quizgenerator->create_instance(array('course' => $SITE->id, 'questionsperpage' => 0, 'grade' => 100.0, 'sumgrades' => 2));
     $cm = get_coursemodule_from_instance('quiz', $quiz->id, $SITE->id);
     // Create five questions.
     $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
     $cat = $questiongenerator->create_question_category();
     $shortanswer = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id));
     $numerical = $questiongenerator->create_question('numerical', null, array('category' => $cat->id));
     $essay = $questiongenerator->create_question('essay', null, array('category' => $cat->id));
     $truefalse = $questiongenerator->create_question('truefalse', null, array('category' => $cat->id));
     $match = $questiongenerator->create_question('match', null, array('category' => $cat->id));
     // Add them to the quiz.
     quiz_add_quiz_question($shortanswer->id, $quiz);
     quiz_add_quiz_question($numerical->id, $quiz);
     quiz_add_quiz_question($essay->id, $quiz);
     quiz_add_quiz_question($truefalse->id, $quiz);
     quiz_add_quiz_question($match->id, $quiz);
     // Return the quiz object.
     $quizobj = new quiz($quiz, $cm, $SITE);
     return \mod_quiz\structure::create_for_quiz($quizobj);
 }