ILIAS  release_8 Revision v8.24
assLongMenuTest.php
Go to the documentation of this file.
1<?php
26{
27 protected $backupGlobals = false;
28
29
30 protected static function getMethod($name): ReflectionMethod
31 {
32 $class = new ReflectionClass('assLongMenu');
33 $method = $class->getMethod($name);
34 $method->setAccessible(true);
35 return $method;
36 }
37
38 protected function setUp(): void
39 {
40 chdir(dirname(__FILE__));
41 chdir('../../../');
42
43 parent::setUp();
44
45 require_once './Services/UICore/classes/class.ilCtrl.php';
46 $ilCtrl_mock = $this->createMock('ilCtrl');
47 $ilCtrl_mock->expects($this->any())->method('saveParameter');
48 $ilCtrl_mock->expects($this->any())->method('saveParameterByClass');
49 $this->setGlobalVariable('ilCtrl', $ilCtrl_mock);
50
51 require_once './Services/Language/classes/class.ilLanguage.php';
52 $lng_mock = $this->createMock('ilLanguage', array('txt'), array(), '', false);
53 //$lng_mock->expects( $this->once() )->method( 'txt' )->will( $this->returnValue('Test') );
54 $this->setGlobalVariable('lng', $lng_mock);
55
56 $this->setGlobalVariable('ilias', $this->getIliasMock());
57 $this->setGlobalVariable('tpl', $this->getGlobalTemplateMock());
58 $this->setGlobalVariable('ilDB', $this->getDatabaseMock());
59 }
60
62 {
63 $instance = new assLongMenu();
64 $this->assertInstanceOf('assLongMenu', $instance);
65 }
66
68 {
69 $instance = new assLongMenu();
70 $this->assertEquals('qpl_qst_lome', $instance->getAdditionalTableName());
71 }
72
74 {
75 $instance = new assLongMenu();
76 $this->assertEquals('assLongMenu', $instance->getQuestionType());
77 }
78
80 {
81 $instance = new assLongMenu();
82 $this->assertEquals('qpl_a_lome', $instance->getAnswerTableName());
83 }
84
86 {
87 $method = self::getMethod('correctAnswerDoesNotExistInAnswerOptions');
88 $obj = new assLongMenu();
89 $value = $method->invokeArgs($obj, array(array(array(5),1,1), array(1,2,3,4)));
90 $this->assertEquals(true, $value);
91 }
92
94 {
95 $method = self::getMethod('correctAnswerDoesNotExistInAnswerOptions');
96 $obj = new assLongMenu();
97 $value = $method->invokeArgs($obj, array(array(array(1),1,1), array(1,2,3,4)));
98 $this->assertEquals(false, $value);
99 }
100
102 {
103 $obj = new assLongMenu();
104 $obj->setCorrectAnswers(array( 0 => array( 0 => array(0 => 'answer'),1 => '2', 2 => '1'),
105 1 => array( 0 => array(0 => 'answer'),1 => '2', 2 => '1')));
106 $value = $obj->getMaximumPoints();
107 $this->assertEquals(4, $value);
108 }
109
111 {
112 $obj = new assLongMenu();
113 $obj->setCorrectAnswers(array( 0 => array( 0 => array(0 => 'answer'),1 => '2.25', 2 => '1'),
114 1 => array( 0 => array(0 => 'answer'),1 => '2.25', 2 => '1')));
115 $value = $obj->getMaximumPoints();
116 $this->assertEquals(4.5, $value);
117 }
118
119 public function test_isComplete_shouldBeFalse(): void
120 {
121 $obj = new assLongMenu();
122 $obj->setCorrectAnswers(array( 0 => array( 0 => array(0 => 'answer'),1 => '2.25', 2 => '1'),
123 1 => array( 0 => array(0 => 'answer'),1 => '2.25', 2 => '1')));
124 $obj->setAnswers(array(array(1,2,3,4)));
125 $this->assertEquals($obj->isComplete(), false);
126 }
127
128 /* Removed by @kergomard 17 NOV 2022, we should introduce this again
129 public function test_isComplete_shouldBeTrue(): void
130 {
131 $obj = new assLongMenu();
132 $obj->setCorrectAnswers(array( 0 => array( 0 => array(0 => 'answer'),1 => '2.25', 2 => '1'),
133 1 => array( 0 => array(0 => 'answer'),1 => '2.25', 2 => '1')));
134 $obj->setAnswers(array(array(1,2,3,4)));
135 $obj->setAuthor("Tester");
136 $obj->setPoints(4.5);
137 $obj->setTitle('LongMenu Title');
138 $obj->setLongMenuTextValue('LongMenu Question');
139 $this->assertEquals($obj->isComplete(), true);
140 } */
141
143 {
144 $obj = new assLongMenu();
145 $this->assertEquals($obj->checkQuestionCustomPart(), false);
146 }
147
149 {
150 $obj = new assLongMenu();
151 $obj->setAnswers(array(array(1,2,3,4)));
152 $this->assertEquals($obj->checkQuestionCustomPart(), false);
153 }
154
156 {
157 $obj = new assLongMenu();
158 $obj->setCorrectAnswers(array( 0 => array( 0 => array(0 => 'answer'),1 => '2.25', 2 => '1'),
159 1 => array( 0 => array(0 => 'answer'),1 => '2.25', 2 => '1')));
160 $this->assertEquals($obj->checkQuestionCustomPart(), false);
161 }
163 {
164 $obj = new assLongMenu();
165 $obj->setCorrectAnswers(array( 0 => array( 0 => array(0 => 'answer'),1 => '2.25', 2 => '1'),
166 1 => array( 0 => array(0 => 'answer'),1 => '2.25', 2 => '1')));
167 $obj->setAnswers(array(array('answer')));
168 $this->assertEquals($obj->checkQuestionCustomPart(), false);
169 }
171 {
172 $obj = new assLongMenu();
173 $obj->setCorrectAnswers(array( 0 => array( 0 => array(0 => 'answer'),1 => '2.25', 2 => '1')));
174 $obj->setAnswers(array(array(1)));
175 $this->assertEquals($obj->checkQuestionCustomPart(), false);
176 }
177
179 {
180 $obj = new assLongMenu();
181 $obj->setCorrectAnswers(array( 0 => array( 0 => array(),1 => '2.25', 2 => '1')));
182 $obj->setAnswers(array(array('answer')));
183 $this->assertEquals($obj->checkQuestionCustomPart(), false);
184 }
185
187 {
188 $obj = new assLongMenu();
189 $obj->setCorrectAnswers(array( 0 => array( 0 => array())));
190 $obj->setAnswers(array(array('answer')));
191 $this->assertEquals($obj->checkQuestionCustomPart(), false);
192 }
193
195 {
196 $obj = new assLongMenu();
197 $obj->setCorrectAnswers(array( 0 => array( 0 => array('answer'),1 => 0, 2 => '1')));
198 $obj->setAnswers(array(array('answer')));
199 $this->assertEquals($obj->checkQuestionCustomPart(), false);
200 }
201
203 {
204 $obj = new assLongMenu();
205 $obj->setCorrectAnswers(array( 0 => array( 0 => array('answer'),1 => 1, 2 => '1')));
206 $obj->setAnswers(array(array('answer')));
207 $this->assertEquals($obj->checkQuestionCustomPart(), true);
208 }
209
211 {
212 $obj = new assLongMenu();
213 $array = array( 0 => 'squirrel', 1 => 'icebear');
214 $_POST['answer'] = $array;
215 $this->assertEquals($obj->getSolutionSubmit(), $array);
216 }
217
219 {
220 $obj = new assLongMenu();
221 $obj->setAnswerType(0);
222 $this->assertEquals(0, $obj->getAnswerType());
223 }
224
225 /* Removed by @kergomard 17 NOV 2022, we should introduce this again
226 public function test_setLongMenuTextValue_shouldReturnGetLongMenuTextValue(): void
227 {
228 $obj = new assLongMenu();
229 $this->assertEquals('', $obj->getLongMenuTextValue());
230 $obj->setLongMenuTextValue('dummy text');
231 $this->assertEquals('dummy text', $obj->getLongMenuTextValue());
232 } */
233
235 {
236 $obj = new assLongMenu();
237 $obj->setJsonStructure(json_encode(array(1 => 'bla')));
238 $this->assertEquals('{"1":"bla"}', $obj->getJsonStructure());
239 }
240
242 {
243 $obj = new assLongMenu();
244 $this->assertEquals(false, $obj->isShuffleAnswersEnabled());
245 $this->assertNotEquals(true, $obj->isShuffleAnswersEnabled());
246 }
247}
Class assBaseTestCase.
setGlobalVariable(string $name, $value)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
test_getAdditionalTableName_shouldReturnString()
test_getMaximumPoints_shouldBeFourPointFive()
test_getAnswerTableName_shouldReturnString()
static getMethod($name)
test_isShuffleAnswersEnabled_shouldReturnFalse()
test_checkQuestionCustomPart_shouldBeFalseBecauseToManyCorrectAnswers()
test_checkQuestionCustomPart_shouldBeFalseBecauseCorrectAnswerHasNoAnswers()
test_setAnswerType_shouldReturnGetAnswerType()
test_getSolutionSubmit_shouldReturnSolution()
test_checkQuestionCustomPart_shouldBeFalseBecauseOnlyCorrectAnswers()
test_instantiateObject_shouldReturnInstance()
test_correctAnswerDoesNotExistInAnswerOptions_shouldReturnTrue()
test_checkQuestionCustomPart_shouldBeFalseBecauseNoCustomPart()
test_checkQuestionCustomPart_shouldBeFalseBecauseCorrectAnswerPointsAreZero()
test_checkQuestionCustomPart_shouldBeFalseBecauseOnlyAnswers()
test_checkQuestionCustomPart_shouldBeTrue()
test_checkQuestionCustomPart_shouldBeFalseBecauseCorrectAnswerHasNoPoints()
test_getQuestionType_shouldReturnString()
test_correctAnswerDoesNotExistInAnswerOptions_shouldReturnFalse()
test_setJsonStructure_shouldReturnGetJsonStructure()
test_checkQuestionCustomPart_shouldBeFalseBecauseCorrectAnswerDoesNotExistsInAnswers()
if($format !==null) $name
Definition: metadata.php:247