mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 00:42:54 +02:00
MDL-47963 quiz editing: fix failing unit tests
The unit tests were initialising the structure class in a different way from real use. That was clearly silly, so I got rid of create_for, leaving just the real create_for_quiz.
This commit is contained in:
parent
1de9b5072a
commit
58413f613e
@ -70,25 +70,15 @@ class structure {
|
||||
return new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of this class representing the structure of a given quiz.
|
||||
* @param \stdClass $quiz the quiz settings.
|
||||
* @return structure
|
||||
*/
|
||||
public static function create_for($quiz) {
|
||||
$structure = self::create();
|
||||
$structure->populate_structure($quiz);
|
||||
return $structure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of this class representing the structure of a given quiz.
|
||||
* @param \quiz $quizobj the quiz.
|
||||
* @return structure
|
||||
*/
|
||||
public static function create_for_quiz($quizobj) {
|
||||
$structure = self::create_for($quizobj->get_quiz());
|
||||
$structure = self::create();
|
||||
$structure->quizobj = $quizobj;
|
||||
$structure->populate_structure($quizobj->get_quiz());
|
||||
return $structure;
|
||||
}
|
||||
|
||||
|
@ -90,6 +90,7 @@ class mod_quiz_repaginate_test extends advanced_testcase {
|
||||
|
||||
$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');
|
||||
@ -109,7 +110,8 @@ class mod_quiz_repaginate_test extends advanced_testcase {
|
||||
quiz_add_quiz_question($match->id, $quiz);
|
||||
|
||||
// Return the quiz object.
|
||||
return \mod_quiz\structure::create_for($quiz);
|
||||
$quizobj = new quiz($quiz, $cm, $SITE);
|
||||
return \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -282,6 +282,7 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
// Setup a quiz with 1 standard and 1 random question.
|
||||
$quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
|
||||
$quiz = $quizgenerator->create_instance(array('course' => $SITE->id, 'questionsperpage' => 3, 'grade' => 100.0));
|
||||
$cm = get_coursemodule_from_instance('quiz', $quiz->id, $SITE->id);
|
||||
|
||||
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
||||
$cat = $questiongenerator->create_question_category();
|
||||
@ -293,7 +294,8 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
// Get the random question.
|
||||
$randomq = $DB->get_record('question', array('qtype' => 'random'));
|
||||
|
||||
$structure = \mod_quiz\structure::create_for($quiz);
|
||||
$quizobj = new quiz($quiz, $cm, $SITE);
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
|
||||
// Check that the setup looks right.
|
||||
$this->assertEquals(2, $structure->get_question_count());
|
||||
@ -303,7 +305,7 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
// Remove the standard question.
|
||||
$structure->remove_slot($quiz, 1);
|
||||
|
||||
$alteredstructure = \mod_quiz\structure::create_for($quiz);
|
||||
$alteredstructure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
|
||||
// Check the new ordering, and that the slot number was updated.
|
||||
$this->assertEquals(1, $alteredstructure->get_question_count());
|
||||
@ -314,7 +316,7 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
|
||||
// Remove the random question.
|
||||
$structure->remove_slot($quiz, 1);
|
||||
$alteredstructure = \mod_quiz\structure::create_for($quiz);
|
||||
$alteredstructure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
|
||||
// Check that new ordering.
|
||||
$this->assertEquals(0, $alteredstructure->get_question_count());
|
||||
|
Loading…
x
Reference in New Issue
Block a user