Merge branch 'MDL-28444' of git://github.com/timhunt/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 23 Aug 2011 20:46:17 +0000 (22:46 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 23 Aug 2011 20:46:17 +0000 (22:46 +0200)
question/type/calculated/question.php
question/type/calculated/simpletest/helper.php
question/type/calculated/simpletest/testquestion.php
question/type/calculatedmulti/question.php

index bb59e1e..3ecbc9d 100644 (file)
@@ -80,7 +80,7 @@ class qtype_calculated_question extends qtype_numerical_question
 
     public function get_variants_selection_seed() {
         if (!empty($this->synchronised) &&
-                $this->datasetloader->datasets_are_synchronised($question->category)) {
+                $this->datasetloader->datasets_are_synchronised($this->category)) {
             return 'category' . $this->category;
         } else {
             return parent::get_variants_selection_seed();
index f4a1dca..6b93bd1 100644 (file)
@@ -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;
+    }
 }
index 6df2ca5..5678e9b 100644 (file)
@@ -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());
+    }
+}
index aa96ac2..35c9155 100644 (file)
@@ -72,7 +72,7 @@ class qtype_calculatedmulti_single_question extends qtype_multichoice_single_que
 
     public function get_variants_selection_seed() {
         if (!empty($this->synchronised) &&
-                $this->datasetloader->datasets_are_synchronised($question->category)) {
+                $this->datasetloader->datasets_are_synchronised($this->category)) {
             return 'category' . $this->category;
         } else {
             return parent::get_variants_selection_seed();