d69b9eea8be1e59ac71d1244382430511ae2ba98
[moodle.git] / question / type / match / tests / helper.php
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
17 /**
18  * Test helpers for the match question type.
19  *
20  * @package    qtype_match
21  * @copyright  2013 The Open University
22  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23  */
26 defined('MOODLE_INTERNAL') || die();
28 global $CFG;
29 require_once($CFG->dirroot . '/question/type/match/question.php');
32 /**
33  * Test helper class for the match question type.
34  *
35  * @copyright  2013 The Open University
36  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37  */
38 class qtype_match_test_helper extends question_test_helper {
39     public function get_test_questions() {
40         return array('foursubq');
41     }
44     /**
45      * Makes a match question about completing two blanks in some text.
46      * @return object the question definition data, as it might be returned from
47      * get_question_options.
48      */
49     public function get_match_question_data_foursubq() {
50         global $USER;
51         $q = new stdClass();
52         test_question_maker::initialise_question_data($q);
53         $q->name = 'Matching question';
54         $q->qtype = 'match';
55         $q->parent = 0;
56         $q->questiontext = 'Classify the animals.';
57         $q->questiontextformat = FORMAT_HTML;
58         $q->generalfeedback = 'General feedback.';
59         $q->generalfeedbackformat = FORMAT_HTML;
60         $q->defaultmark = 1;
61         $q->penalty = 0.3333333;
62         $q->length = 1;
63         $q->hidden = 0;
64         $q->createdby = $USER->id;
65         $q->modifiedby = $USER->id;
67         $q->options = new stdClass();
68         $q->options->shuffleanswers = 0;
69         test_question_maker::set_standard_combined_feedback_fields($q->options);
71         $q->options->subquestions = array(
72             14 => (object) array(
73                 'id' => 14,
74                 'questiontext' => 'frog',
75                 'questiontextformat' => FORMAT_HTML,
76                 'answertext' => 'amphibian'),
77             15 => (object) array(
78                 'id' => 15,
79                 'questiontext' => 'cat',
80                 'questiontextformat' => FORMAT_HTML,
81                 'answertext' => 'mammal'),
82             16 => (object) array(
83                 'id' => 16,
84                 'questiontext' => 'newt',
85                 'questiontextformat' => FORMAT_HTML,
86                 'answertext' => 'amphibian'),
87             17 => (object) array(
88                 'id' => 17,
89                 'questiontext' => '',
90                 'questiontextformat' => FORMAT_HTML,
91                 'answertext' => 'insect'),
92         );
94         return $q;
95     }
97     /**
98      * Makes a match question about completing two blanks in some text.
99      * @return object the question definition data, as it might be returned from
100      *      the question editing form.
101      */
102     public function get_match_question_form_data_foursubq() {
103         $q = new stdClass();
104         $q->name = 'Matching question';
105         $q->questiontext = array('text' => 'Classify the animals.', 'format' => FORMAT_HTML);
106         $q->generalfeedback = array('text' => 'General feedback.', 'format' => FORMAT_HTML);
107         $q->defaultmark = 1;
108         $q->penalty = 0.3333333;
110         $q->shuffleanswers = 0;
111         test_question_maker::set_standard_combined_feedback_form_data($q);
113         $q->subquestions = array(
114             0 => array('text' => 'frog', 'format' => FORMAT_HTML),
115             1 => array('text' => 'cat', 'format' => FORMAT_HTML),
116             2 => array('text' => 'newt', 'format' => FORMAT_HTML),
117             3 => array('text' => '', 'format' => FORMAT_HTML));
119         $q->subanswers = array(
120             0 => 'amphibian',
121             1 => 'mammal',
122             2 => 'amphibian',
123             3 => 'insect'
124         );
126         $q->noanswers = 4;
128         return $q;
129     }