Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/question/type/multianswer/simpletest/testquestion.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 
00028 require_once($CFG->dirroot . '/question/engine/simpletest/helpers.php');
00029 
00030 
00037 class qtype_multianswer_question_test extends UnitTestCase {
00038     public function test_get_expected_data() {
00039         $question = test_question_maker::make_question('multianswer');
00040         $this->assertEqual(array('sub1_answer' => PARAM_RAW_TRIMMED,
00041                 'sub2_answer' => PARAM_RAW), $question->get_expected_data());
00042     }
00043 
00044     public function test_is_complete_response() {
00045         $question = test_question_maker::make_question('multianswer');
00046 
00047         $this->assertFalse($question->is_complete_response(array()));
00048         $this->assertTrue($question->is_complete_response(array('sub1_answer' => 'Owl',
00049                 'sub2_answer' => '2')));
00050         $this->assertTrue($question->is_complete_response(array('sub1_answer' => '0',
00051                 'sub2_answer' => 0)));
00052         $this->assertFalse($question->is_complete_response(array('sub1_answer' => 'Owl')));
00053     }
00054 
00055     public function test_is_gradable_response() {
00056         $question = test_question_maker::make_question('multianswer');
00057 
00058         $this->assertFalse($question->is_gradable_response(array()));
00059         $this->assertTrue($question->is_gradable_response(array('sub1_answer' => 'Owl',
00060                 'sub2_answer' => '2')));
00061         $this->assertTrue($question->is_gradable_response(array('sub1_answer' => '0',
00062                 'sub2_answer' => 0)));
00063         $this->assertTrue($question->is_gradable_response(array('sub1_answer' => 'Owl')));
00064     }
00065 
00066     public function test_grading() {
00067         $question = test_question_maker::make_question('multianswer');
00068         $question->start_attempt(new question_attempt_step(), 1);
00069 
00070         $rightchoice = $question->subquestions[2]->get_correct_response();
00071 
00072         $this->assertEqual(array(1, question_state::$gradedright), $question->grade_response(
00073                 array('sub1_answer' => 'Owl', 'sub2_answer' => reset($rightchoice))));
00074         $this->assertEqual(array(0.5, question_state::$gradedpartial), $question->grade_response(
00075                 array('sub1_answer' => 'Owl')));
00076         $this->assertEqual(array(0.5, question_state::$gradedpartial), $question->grade_response(
00077                 array('sub1_answer' => 'Goat', 'sub2_answer' => reset($rightchoice))));
00078         $this->assertEqual(array(0, question_state::$gradedwrong), $question->grade_response(
00079                 array('sub1_answer' => 'Dog')));
00080     }
00081 
00082     public function test_get_correct_response() {
00083         $question = test_question_maker::make_question('multianswer');
00084         $question->start_attempt(new question_attempt_step(), 1);
00085 
00086         $rightchoice = $question->subquestions[2]->get_correct_response();
00087 
00088         $this->assertEqual(array('sub1_answer' => 'Owl', 'sub2_answer' => reset($rightchoice)),
00089                 $question->get_correct_response());
00090     }
00091 
00092     public function test_get_question_summary() {
00093         $question = test_question_maker::make_question('multianswer');
00094 
00095         // Bit of a hack to make testing easier.
00096         $question->subquestions[2]->shuffleanswers = false;
00097 
00098         $question->start_attempt(new question_attempt_step(), 1);
00099 
00100         $qsummary = $question->get_question_summary();
00101         $this->assertEqual('Complete this opening line of verse: "The _____ and the ' .
00102                 '{Bow-wow; Wiggly worm; Pussy-cat} went to sea".', $qsummary);
00103     }
00104 
00105     public function test_summarise_response() {
00106         $question = test_question_maker::make_question('multianswer');
00107         $question->start_attempt(new question_attempt_step(), 1);
00108 
00109         $rightchoice = $question->subquestions[2]->get_correct_response();
00110 
00111         $this->assertEqual(get_string('subqresponse', 'qtype_multianswer',
00112                 array('i' => 1, 'response' => 'Owl')) . '; ' .
00113                 get_string('subqresponse', 'qtype_multianswer',
00114                 array('i' => 2, 'response' => 'Pussy-cat')), $question->summarise_response(
00115                 array('sub1_answer' => 'Owl', 'sub2_answer' => reset($rightchoice))));
00116     }
00117 }
 All Data Structures Namespaces Files Functions Variables Enumerations