Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/question/type/match/simpletest/testquestiontype.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 
00027 defined('MOODLE_INTERNAL') || die();
00028 
00029 require_once($CFG->dirroot . '/question/engine/simpletest/helpers.php');
00030 require_once($CFG->dirroot . '/question/type/match/questiontype.php');
00031 
00032 
00039 class qtype_match_test extends UnitTestCase {
00041     protected $qtype;
00042 
00043     public function setUp() {
00044         $this->qtype = new qtype_match();
00045     }
00046 
00047     public function tearDown() {
00048         $this->qtype = null;
00049     }
00050 
00051     protected function get_test_question_data() {
00052         global $USER;
00053         $q = new stdClass();
00054         $q->id = 0;
00055         $q->name = 'Matching question';
00056         $q->category = 0;
00057         $q->contextid = 0;
00058         $q->parent = 0;
00059         $q->questiontext = 'Classify the animals.';
00060         $q->questiontextformat = FORMAT_HTML;
00061         $q->generalfeedback = 'General feedback.';
00062         $q->generalfeedbackformat = FORMAT_HTML;
00063         $q->defaultmark = 1;
00064         $q->penalty = 0.3333333;
00065         $q->length = 1;
00066         $q->stamp = make_unique_id_code();
00067         $q->version = make_unique_id_code();
00068         $q->hidden = 0;
00069         $q->timecreated = time();
00070         $q->timemodified = time();
00071         $q->createdby = $USER->id;
00072         $q->modifiedby = $USER->id;
00073 
00074         $q->options->shuffleanswers = false;
00075         test_question_maker::set_standard_combined_feedback_fields($q->options);
00076 
00077         $q->options->subquestions = array(
00078             14 => (object) array(
00079                 'id' => 14,
00080                 'questiontext' => 'frog',
00081                 'questiontextformat' => FORMAT_HTML,
00082                 'answertext' => 'amphibian'),
00083             15 => (object) array(
00084                 'id' => 15,
00085                 'questiontext' => 'cat',
00086                 'questiontextformat' => FORMAT_HTML,
00087                 'answertext' => 'mammal'),
00088             16 => (object) array(
00089                 'id' => 16,
00090                 'questiontext' => 'newt',
00091                 'questiontextformat' => FORMAT_HTML,
00092                 'answertext' => 'amphibian'),
00093             17 => (object) array(
00094                 'id' => 17,
00095                 'questiontext' => '',
00096                 'questiontextformat' => FORMAT_HTML,
00097                 'answertext' => 'insect'),
00098         );
00099 
00100         return $q;
00101     }
00102 
00103     public function test_name() {
00104         $this->assertEqual($this->qtype->name(), 'match');
00105     }
00106 
00107     public function test_can_analyse_responses() {
00108         $this->assertTrue($this->qtype->can_analyse_responses());
00109     }
00110 
00111     public function test_get_random_guess_score() {
00112         $q = $this->get_test_question_data();
00113         $this->assertWithinMargin(0.3333333, $this->qtype->get_random_guess_score($q), 0.0000001);
00114     }
00115 
00116     public function test_get_possible_responses() {
00117         $q = $this->get_test_question_data();
00118 
00119         $this->assertEqual(array(
00120             14 => array(
00121                 14 => new question_possible_response('frog: amphibian', 1/3),
00122                 15 => new question_possible_response('frog: mammal', 0),
00123                 17 => new question_possible_response('frog: insect', 0),
00124                 null => question_possible_response::no_response()),
00125             15 => array(
00126                 14 => new question_possible_response('cat: amphibian', 0),
00127                 15 => new question_possible_response('cat: mammal', 1/3),
00128                 17 => new question_possible_response('cat: insect', 0),
00129                 null => question_possible_response::no_response()),
00130             16 => array(
00131                 14 => new question_possible_response('newt: amphibian', 1/3),
00132                 15 => new question_possible_response('newt: mammal', 0),
00133                 17 => new question_possible_response('newt: insect', 0),
00134                 null => question_possible_response::no_response()),
00135         ), $this->qtype->get_possible_responses($q));
00136     }
00137 }
 All Data Structures Namespaces Files Functions Variables Enumerations