Skip to content

Commit

Permalink
Merge branch 'MDL-28444' of git://github.com/timhunt/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Aug 23, 2011
2 parents 553d343 + e8b8073 commit 53ef01d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion question/type/calculated/question.php
Expand Up @@ -80,7 +80,7 @@ public function get_num_variants() {

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();
Expand Down
15 changes: 15 additions & 0 deletions question/type/calculated/simpletest/helper.php
Expand Up @@ -68,6 +68,7 @@ public function make_calculated_question_sum() {
$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),
Expand All @@ -88,6 +89,7 @@ public function make_calculated_question_sum() {
*/
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);
Expand All @@ -101,4 +103,17 @@ public function get_number_of_items() {
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;
}
}
21 changes: 20 additions & 1 deletion question/type/calculated/simpletest/testquestion.php
Expand Up @@ -108,4 +108,23 @@ public function test_classify_response() {
question_classified_response::no_response()),
$question->classify_response(array('answer' => '')));
}
}

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());
}
}
2 changes: 1 addition & 1 deletion question/type/calculatedmulti/question.php
Expand Up @@ -72,7 +72,7 @@ public function get_num_variants() {

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();
Expand Down

0 comments on commit 53ef01d

Please sign in to comment.