MDL-28444 unit test to verify the fix.

This commit is contained in:
Tim Hunt 2011-08-20 13:14:07 +01:00
parent 409199d660
commit e8b8073d3c
2 changed files with 35 additions and 1 deletions

View 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;
}
}

View file

@ -108,4 +108,23 @@ class qtype_calculated_question_test extends UnitTestCase {
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());
}
}