From a4c982917ea37a9673492c18cb69e68c13bbf564 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Fri, 27 May 2011 14:43:28 +0100 Subject: [PATCH] MDL-20636 truefalse qtype clean up other unit tests to use the new way of making test tf questions. --- .../simpletest/testwalkthrough.php | 8 +++--- .../simpletest/testwalkthrough.php | 2 +- .../simpletest/testwalkthrough.php | 2 +- .../simpletest/testwalkthrough.php | 2 +- .../simpletest/testmissingbehaviour.php | 8 +++--- question/engine/simpletest/helpers.php | 25 ------------------- .../engine/simpletest/testquestionattempt.php | 2 +- .../testquestionusagebyactivity.php | 8 +++--- .../truefalse/simpletest/testquestion.php | 14 +++++------ 9 files changed, 23 insertions(+), 48 deletions(-) diff --git a/question/behaviour/deferredcbm/simpletest/testwalkthrough.php b/question/behaviour/deferredcbm/simpletest/testwalkthrough.php index 43e0030ceac..6d0c5e56f0d 100644 --- a/question/behaviour/deferredcbm/simpletest/testwalkthrough.php +++ b/question/behaviour/deferredcbm/simpletest/testwalkthrough.php @@ -41,7 +41,7 @@ class qbehaviour_deferredcbm_walkthrough_test extends qbehaviour_walkthrough_tes public function test_deferred_cbm_truefalse_high_certainty() { // Create a true-false question with correct answer true. - $tf = test_question_maker::make_a_truefalse_question(); + $tf = test_question_maker::make_question('truefalse', 'true'); $this->start_attempt_at_question($tf, 'deferredcbm', 2); // Verify. @@ -116,7 +116,7 @@ class qbehaviour_deferredcbm_walkthrough_test extends qbehaviour_walkthrough_tes public function test_deferred_cbm_truefalse_low_certainty() { // Create a true-false question with correct answer true. - $tf = test_question_maker::make_a_truefalse_question(); + $tf = test_question_maker::make_question('truefalse', 'true'); $this->start_attempt_at_question($tf, 'deferredcbm', 2); // Verify. @@ -153,7 +153,7 @@ class qbehaviour_deferredcbm_walkthrough_test extends qbehaviour_walkthrough_tes public function test_deferred_cbm_truefalse_default_certainty() { // Create a true-false question with correct answer true. - $tf = test_question_maker::make_a_truefalse_question(); + $tf = test_question_maker::make_question('truefalse', 'true'); $this->start_attempt_at_question($tf, 'deferredcbm', 2); // Verify. @@ -249,7 +249,7 @@ class qbehaviour_deferredcbm_walkthrough_test extends qbehaviour_walkthrough_tes public function test_deferred_cbm_truefalse_no_certainty_feedback_when_not_answered() { // Create a true-false question with correct answer true. - $tf = test_question_maker::make_a_truefalse_question(); + $tf = test_question_maker::make_question('truefalse', 'true'); $this->start_attempt_at_question($tf, 'deferredcbm', 2); // Verify. diff --git a/question/behaviour/deferredfeedback/simpletest/testwalkthrough.php b/question/behaviour/deferredfeedback/simpletest/testwalkthrough.php index 371bbab4509..65963053180 100644 --- a/question/behaviour/deferredfeedback/simpletest/testwalkthrough.php +++ b/question/behaviour/deferredfeedback/simpletest/testwalkthrough.php @@ -41,7 +41,7 @@ class qbehaviour_deferredfeedback_walkthrough_test extends qbehaviour_walkthroug public function test_deferredfeedback_feedback_truefalse() { // Create a true-false question with correct answer true. - $tf = test_question_maker::make_a_truefalse_question(); + $tf = test_question_maker::make_question('truefalse', 'true'); $this->start_attempt_at_question($tf, 'deferredfeedback', 2); // Check the initial state. diff --git a/question/behaviour/immediatecbm/simpletest/testwalkthrough.php b/question/behaviour/immediatecbm/simpletest/testwalkthrough.php index 940d2880b68..7724a84de80 100644 --- a/question/behaviour/immediatecbm/simpletest/testwalkthrough.php +++ b/question/behaviour/immediatecbm/simpletest/testwalkthrough.php @@ -268,7 +268,7 @@ class qbehaviour_immediatecbm_walkthrough_test extends qbehaviour_walkthrough_te public function test_immediatecbm_cbm_truefalse_no_certainty_feedback_when_not_answered() { // Create a true-false question with correct answer true. - $tf = test_question_maker::make_a_truefalse_question(); + $tf = test_question_maker::make_question('truefalse', 'true'); $this->start_attempt_at_question($tf, 'deferredcbm', 2); // Verify. diff --git a/question/behaviour/manualgraded/simpletest/testwalkthrough.php b/question/behaviour/manualgraded/simpletest/testwalkthrough.php index 5f5ed67f5c2..3b7e7ef4fe8 100644 --- a/question/behaviour/manualgraded/simpletest/testwalkthrough.php +++ b/question/behaviour/manualgraded/simpletest/testwalkthrough.php @@ -108,7 +108,7 @@ class qbehaviour_manualgraded_walkthrough_test extends qbehaviour_walkthrough_te public function test_manual_graded_truefalse() { // Create a true-false question with correct answer true. - $tf = test_question_maker::make_a_truefalse_question(); + $tf = test_question_maker::make_question('truefalse', 'true'); $this->start_attempt_at_question($tf, 'manualgraded', 2); // Check the initial state. diff --git a/question/behaviour/missing/simpletest/testmissingbehaviour.php b/question/behaviour/missing/simpletest/testmissingbehaviour.php index 9068eecb77c..fb958648540 100644 --- a/question/behaviour/missing/simpletest/testmissingbehaviour.php +++ b/question/behaviour/missing/simpletest/testmissingbehaviour.php @@ -39,21 +39,21 @@ require_once(dirname(__FILE__) . '/../behaviour.php'); */ class qbehaviour_missing_test extends UnitTestCase { public function test_missing_cannot_start() { - $qa = new question_attempt(test_question_maker::make_a_truefalse_question(), 0); + $qa = new question_attempt(test_question_maker::make_question('truefalse', 'true'), 0); $behaviour = new qbehaviour_missing($qa, 'deferredfeedback'); $this->expectException(); $behaviour->init_first_step(new question_attempt_step(array()), 1); } public function test_missing_cannot_process() { - $qa = new question_attempt(test_question_maker::make_a_truefalse_question(), 0); + $qa = new question_attempt(test_question_maker::make_question('truefalse', 'true'), 0); $behaviour = new qbehaviour_missing($qa, 'deferredfeedback'); $this->expectException(); $behaviour->process_action(new question_attempt_pending_step(array())); } public function test_missing_cannot_get_min_grade() { - $qa = new question_attempt(test_question_maker::make_a_truefalse_question(), 0); + $qa = new question_attempt(test_question_maker::make_question('truefalse', 'true'), 0); $behaviour = new qbehaviour_missing($qa, 'deferredfeedback'); $this->expectException(); $behaviour->get_min_fraction(); @@ -74,7 +74,7 @@ class qbehaviour_missing_test extends UnitTestCase { 1256233790, 2, 1, 'complete', 0.50, 1256233705, 1, 'choice0', '1'), )); - $question = test_question_maker::make_a_truefalse_question(); + $question = test_question_maker::make_question('truefalse', 'true'); $question->id = -1; question_bank::start_unit_test(); diff --git a/question/engine/simpletest/helpers.php b/question/engine/simpletest/helpers.php index ee0dc030243..39fb6bf35b6 100644 --- a/question/engine/simpletest/helpers.php +++ b/question/engine/simpletest/helpers.php @@ -164,31 +164,6 @@ class test_question_maker { return $helper->$method(); } - /** - * Makes a truefalse question with correct answer true, defaultmark 1. - * @return qtype_truefalse_question - */ - public static function make_a_truefalse_question() { - question_bank::load_question_definition_classes('truefalse'); - $tf = new qtype_truefalse_question(); - self::initialise_a_question($tf); - $tf->name = 'True/false question'; - $tf->questiontext = 'The answer is true.'; - $tf->generalfeedback = 'You should have selected true.'; - $tf->penalty = 1; - $tf->qtype = question_bank::get_qtype('truefalse'); - - $tf->rightanswer = true; - $tf->truefeedback = 'This is the right answer.'; - $tf->falsefeedback = 'This is the wrong answer.'; - $tf->truefeedbackformat = FORMAT_HTML; - $tf->falsefeedbackformat = FORMAT_HTML; - $tf->trueanswerid = 13; - $tf->falseanswerid = 14; - - return $tf; - } - /** * Makes a multichoice question with choices 'A', 'B' and 'C' shuffled. 'A' * is correct, defaultmark 1. diff --git a/question/engine/simpletest/testquestionattempt.php b/question/engine/simpletest/testquestionattempt.php index c82e6bf7736..1123228c8a3 100644 --- a/question/engine/simpletest/testquestionattempt.php +++ b/question/engine/simpletest/testquestionattempt.php @@ -277,7 +277,7 @@ class question_attempt_db_test extends data_loading_method_test_base { array(8, 1, 123, 1, 1, 'deferredfeedback', -1, 1, 2.0000000, 0.0000000, 0, '', '', '', 1256233790, 6, 5, 'mangrpartial', 0.5000000, 1256233790, 1, '-maxmark', '2'), )); - $question = test_question_maker::make_a_truefalse_question(); + $question = test_question_maker::make_question('truefalse', 'true'); $question->id = -1; question_bank::start_unit_test(); diff --git a/question/engine/simpletest/testquestionusagebyactivity.php b/question/engine/simpletest/testquestionusagebyactivity.php index 53198635882..bad18547e61 100644 --- a/question/engine/simpletest/testquestionusagebyactivity.php +++ b/question/engine/simpletest/testquestionusagebyactivity.php @@ -72,7 +72,7 @@ class question_usage_by_activity_test extends UnitTestCase { $context = get_context_instance(CONTEXT_SYSTEM); $quba = question_engine::make_questions_usage_by_activity('unit_test', $context); $quba->set_preferred_behaviour('deferredfeedback'); - $tf = test_question_maker::make_a_truefalse_question(); + $tf = test_question_maker::make_question('truefalse', 'true'); $slot = $quba->add_question($tf); // Verify. @@ -88,7 +88,7 @@ class question_usage_by_activity_test extends UnitTestCase { $quba = question_engine::make_questions_usage_by_activity('unit_test', get_context_instance(CONTEXT_SYSTEM)); $quba->set_preferred_behaviour('deferredfeedback'); - $tf = test_question_maker::make_a_truefalse_question(); + $tf = test_question_maker::make_question('truefalse', 'true'); $slot = $quba->add_question($tf); // Exercise SUT and verify. @@ -100,7 +100,7 @@ class question_usage_by_activity_test extends UnitTestCase { public function test_extract_responses() { // Start a deferred feedback attempt with CBM and add the question to it. - $tf = test_question_maker::make_a_truefalse_question(); + $tf = test_question_maker::make_question('truefalse', 'true'); $quba = question_engine::make_questions_usage_by_activity('unit_test', get_context_instance(CONTEXT_SYSTEM)); $quba->set_preferred_behaviour('deferredcbm'); @@ -126,7 +126,7 @@ class question_usage_by_activity_test extends UnitTestCase { public function test_access_out_of_sequence_throws_exception() { // Start a deferred feedback attempt with CBM and add the question to it. - $tf = test_question_maker::make_a_truefalse_question(); + $tf = test_question_maker::make_question('truefalse', 'true'); $quba = question_engine::make_questions_usage_by_activity('unit_test', get_context_instance(CONTEXT_SYSTEM)); $quba->set_preferred_behaviour('deferredcbm'); diff --git a/question/type/truefalse/simpletest/testquestion.php b/question/type/truefalse/simpletest/testquestion.php index 085cfe8da1d..181749ba3c5 100644 --- a/question/type/truefalse/simpletest/testquestion.php +++ b/question/type/truefalse/simpletest/testquestion.php @@ -37,7 +37,7 @@ require_once($CFG->dirroot . '/question/engine/simpletest/helpers.php'); */ class qtype_truefalse_question_test extends UnitTestCase { public function test_is_complete_response() { - $question = test_question_maker::make_a_truefalse_question(); + $question = test_question_maker::make_question('truefalse', 'true'); $this->assertFalse($question->is_complete_response(array())); $this->assertTrue($question->is_complete_response(array('answer' => 0))); @@ -45,7 +45,7 @@ class qtype_truefalse_question_test extends UnitTestCase { } public function test_is_gradable_response() { - $question = test_question_maker::make_a_truefalse_question(); + $question = test_question_maker::make_question('truefalse', 'true'); $this->assertFalse($question->is_gradable_response(array())); $this->assertTrue($question->is_gradable_response(array('answer' => 0))); @@ -53,7 +53,7 @@ class qtype_truefalse_question_test extends UnitTestCase { } public function test_grading() { - $question = test_question_maker::make_a_truefalse_question(); + $question = test_question_maker::make_question('truefalse', 'true'); $this->assertEqual(array(0, question_state::$gradedwrong), $question->grade_response(array('answer' => 0))); @@ -62,7 +62,7 @@ class qtype_truefalse_question_test extends UnitTestCase { } public function test_get_correct_response() { - $question = test_question_maker::make_a_truefalse_question(); + $question = test_question_maker::make_question('truefalse', 'true'); // true $this->assertIdentical(array('answer' => 1), @@ -75,13 +75,13 @@ class qtype_truefalse_question_test extends UnitTestCase { } public function test_get_question_summary() { - $tf = test_question_maker::make_a_truefalse_question(); + $tf = test_question_maker::make_question('truefalse', 'true'); $qsummary = $tf->get_question_summary(); $this->assertEqual('The answer is true.', $qsummary); } public function test_summarise_response() { - $tf = test_question_maker::make_a_truefalse_question(); + $tf = test_question_maker::make_question('truefalse', 'true'); $this->assertEqual(get_string('false', 'qtype_truefalse'), $tf->summarise_response(array('answer' => '0'))); @@ -91,7 +91,7 @@ class qtype_truefalse_question_test extends UnitTestCase { } public function test_classify_response() { - $tf = test_question_maker::make_a_truefalse_question(); + $tf = test_question_maker::make_question('truefalse', 'true'); $tf->start_attempt(new question_attempt_step(), 1); $this->assertEqual(array(