diff --git a/question/type/calculated/simpletest/helper.php b/question/type/calculated/simpletest/helper.php index f4a1dca42de..6b93bd17452 100644 --- a/question/type/calculated/simpletest/helper.php +++ b/question/type/calculated/simpletest/helper.php @@ -68,6 +68,7 @@ class qtype_calculated_test_helper extends question_test_helper { $q->unitgradingtype = 0; $q->unitpenalty = 0; $q->ap = new qtype_numerical_answer_processor(array()); + $q->synchronised = false; $q->datasetloader = new qtype_calculated_test_dataset_loader(0, array( array('a' => 1, 'b' => 5), @@ -88,6 +89,7 @@ class qtype_calculated_test_helper extends question_test_helper { */ class qtype_calculated_test_dataset_loader extends qtype_calculated_dataset_loader{ protected $valuesets; + protected $aresynchronised = array(); public function __construct($questionid, array $valuesets) { parent::__construct($questionid); @@ -101,4 +103,17 @@ class qtype_calculated_test_dataset_loader extends qtype_calculated_dataset_load public function load_values($itemnumber) { return $this->valuesets[$itemnumber - 1]; } + + public function datasets_are_synchronised($category) { + return !empty($this->aresynchronised[$category]); + } + + /** + * Allows the test to mock the return value of {@link datasets_are_synchronised()}. + * @param int $category + * @param bool $aresychronised + */ + public function set_are_synchronised($category, $aresychronised) { + $this->aresynchronised[$category] = $aresychronised; + } } diff --git a/question/type/calculated/simpletest/testquestion.php b/question/type/calculated/simpletest/testquestion.php index 6df2ca5b016..5678e9bc241 100644 --- a/question/type/calculated/simpletest/testquestion.php +++ b/question/type/calculated/simpletest/testquestion.php @@ -108,4 +108,23 @@ class qtype_calculated_question_test extends UnitTestCase { question_classified_response::no_response()), $question->classify_response(array('answer' => ''))); } -} \ No newline at end of file + + public function test_get_variants_selection_seed_q_not_synchronised() { + $question = test_question_maker::make_question('calculated'); + $this->assertEqual($question->stamp, $question->get_variants_selection_seed()); + } + + public function test_get_variants_selection_seed_q_synchronised_datasets_not() { + $question = test_question_maker::make_question('calculated'); + $question->synchronised = true; + $this->assertEqual($question->stamp, $question->get_variants_selection_seed()); + } + + public function test_get_variants_selection_seed_q_synchronised() { + $question = test_question_maker::make_question('calculated'); + $question->synchronised = true; + $question->datasetloader->set_are_synchronised($question->category, true); + $this->assertEqual('category' . $question->category, + $question->get_variants_selection_seed()); + } +}