ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
assMultipleChoiceTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
14{
15 protected $backupGlobals = FALSE;
16
17 protected function setUp()
18 {
19 require_once './Modules/TestQuestionPool/classes/class.assMultipleChoice.php';
20 if (defined('ILIAS_PHPUNIT_CONTEXT'))
21 {
22 include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
23 ilUnitUtil::performInitialisation();
24 }
25 else
26 {
27 chdir( dirname( __FILE__ ) );
28 chdir('../../../');
29 }
30 require_once './Services/Utilities/classes/class.ilUtil.php';
31 }
32
39/* public static function createSampleQuestion($obj_id = null)
40 {
41 $obj_id = ($obj_id) ? $obj_id : 99999999;
42 include_once './Modules/TestQuestionPool/classes/class.assMultipleChoice.php';
43
44 $mc = new assMultipleChoice('unit test multiple choice question', 'unit test multiple choice question comment', 'Helmut Schottmüller', -1, '<p><strong>unit tests</strong> are...</p>');
45 $mc->addAnswer(
46 'important',
47 0.5,
48 -0.5,
49 1
50 );
51 $mc->addAnswer(
52 'useless',
53 -0.5,
54 0.5,
55 2
56 );
57 $mc->addAnswer(
58 'stupid',
59 -0.5,
60 0.5,
61 3
62 );
63 $mc->addAnswer(
64 'cool',
65 0.5,
66 -0.5,
67 4
68 );
69 $mc->setObjId($obj_id);
70 $mc->saveToDb();
71 return $mc->getId();
72 }
73*/
79/* public function t_e_stCreation()
80 {
81 global $ilDB;
82
83 include_once './Modules/TestQuestionPool/classes/class.assMultipleChoice.php';
84 $insert_id = self::createSampleQuestion(null);
85 $this->assertGreaterThan(0, $insert_id);
86 if ($insert_id > 0)
87 {
88 $mc = new assMultipleChoice();
89 $mc->loadFromDb($insert_id);
90 $this->assertEquals($mc->getPoints(),2);
91 $this->assertEquals($mc->getTitle(),"unit test multiple choice question");
92 $this->assertEquals($mc->getComment(),"unit test multiple choice question comment");
93 $this->assertEquals($mc->getAuthor(),"Helmut Schottmüller");
94 $this->assertEquals($mc->getQuestion(),"<p><strong>unit tests</strong> are...</p>");
95 $this->assertEquals(count($mc->getAnswers()), 4);
96 $result = $mc->delete($insert_id);
97 $this->assertEquals($result,true);
98 }
99 }
100*/
102 {
103 $obj = new assMultipleChoice();
104 $this->assertEquals(false, $obj->isComplete());
105 $obj->setTitle('Tilte');
106 $obj->setAuthor('Me or another');
107 $obj->setQuestion('My great Question.');
108 $obj->addAnswer('Super simple single Choice', 1);
109
110 $this->assertEquals(true, $obj->isComplete());
111 }
112
114 {
115 $obj = new assMultipleChoice();
116 $this->assertEquals('thumb.', $obj->getThumbPrefix());
117 }
118
120 {
121 $obj = new assMultipleChoice();
122 $obj->setOutputType(0);
123 $this->assertEquals(0, $obj->getOutputType());
124 }
126 {
127 $obj = new assMultipleChoice();
128 $this->assertEquals(0, $obj->getAnswerCount());
129 $obj->addAnswer('Points for checked', 1, 0, 0);
130 $obj->addAnswer('Points for unchecked', 0, 1, 1);
131 $this->assertEquals(2, $obj->getAnswerCount());
132 $obj->deleteAnswer(0);
133 $this->assertEquals(1, $obj->getAnswerCount());
134 }
135
137 {
138 $obj = new assMultipleChoice();
139 $obj->addAnswer('1', 1, 0, 0);
140 $obj->addAnswer('1', 1, 0, 1);
141 $this->assertEquals(2, $obj->getAnswerCount());
142 $obj->flushAnswers();
143 $this->assertEquals(0, $obj->getAnswerCount());
144 }
145
147 {
148 $obj = new assMultipleChoice();
149 $this->assertEquals('assMultipleChoice', $obj->getQuestionType());
150 }
151
153 {
154 $obj = new assMultipleChoice();
155 $this->assertEquals('qpl_qst_mc', $obj->getAdditionalTableName());
156 }
157
159 {
160 $obj = new assMultipleChoice();
161 $this->assertEquals('qpl_a_mc', $obj->getAnswerTableName());
162 }
163
165 {
166 $obj = new assMultipleChoice();
167 $obj->addAnswer('Points for checked', 1, 0, 0);
168 $obj->addAnswer('Points for checked', 1, 0, 1);
169 $this->assertEquals(2, $obj->getMaximumPoints());
170 }
172 {
173 $obj = new assMultipleChoice();
174 $obj->addAnswer('Points for unchecked', 0, 1, 0);
175 $obj->addAnswer('Points for unchecked', 0, 1, 1);
176 $this->assertEquals(2, $obj->getMaximumPoints());
177 }
179 {
180 $obj = new assMultipleChoice();
181 $obj->addAnswer('Points for unchecked', 0, 1, 0);
182 $obj->addAnswer('Points for unchecked', 0, 1, 1);
183 $this->assertEquals(2, $obj->getMaximumPoints());
184 $obj->addAnswer('Points for checked', 1, 0, 2);
185 $obj->addAnswer('Points for checked', 1, 0, 3);
186 $this->assertEquals(4, $obj->getMaximumPoints());
187 $obj->addAnswer('Points for checked', 1, 1, 4);
188 $obj->addAnswer('Points for checked', 1, 1, 5);
189 $this->assertEquals(6, $obj->getMaximumPoints());
190 }
191}
Unit tests for single choice questions.
test_isComplete_shouldReturnTrue()
Create a sample question and save it to the database.
test_getMaximumPointsIfMoreForUnchecked_shouldReturnAnswerTableName()
Class for multiple choice tests.