ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
assLongMenuTest.php
Go to the documentation of this file.
1<?php
2
27{
28 protected $backupGlobals = false;
29
30
31 protected static function getMethod($name): ReflectionMethod
32 {
33 $class = new ReflectionClass(assLongMenu::class);
34 $method = $class->getMethod($name);
35 return $method;
36 }
37
38 protected function setUp(): void
39 {
40 chdir(__DIR__ . '/../../../../');
41
42 parent::setUp();
43
44 $ilCtrl_mock = $this->createMock('ilCtrl');
45 $ilCtrl_mock->expects($this->any())->method('saveParameter');
46 $ilCtrl_mock->expects($this->any())->method('saveParameterByClass');
47 $this->setGlobalVariable('ilCtrl', $ilCtrl_mock);
48
49 $lng_mock = $this->createMock('ilLanguage', ['txt'], [], '', false);
50 $this->setGlobalVariable('lng', $lng_mock);
51
52 $this->setGlobalVariable('ilias', $this->getIliasMock());
53 $this->setGlobalVariable('ilDB', $this->getDatabaseMock());
54 }
55
57 {
58 $instance = new assLongMenu();
59 $this->assertInstanceOf(assLongMenu::class, $instance);
60 }
61
63 {
64 $instance = new assLongMenu();
65 $this->assertEquals('qpl_qst_lome', $instance->getAdditionalTableName());
66 }
67
69 {
70 $instance = new assLongMenu();
71 $this->assertEquals('assLongMenu', $instance->getQuestionType());
72 }
73
75 {
76 $instance = new assLongMenu();
77 $this->assertEquals('qpl_a_lome', $instance->getAnswerTableName());
78 }
79
81 {
82 $method = self::getMethod('correctAnswerDoesNotExistInAnswerOptions');
83 $obj = new assLongMenu();
84 $value = $method->invokeArgs($obj, [[[5],1,1], [1,2,3,4]]);
85 $this->assertEquals(true, $value);
86 }
87
89 {
90 $method = self::getMethod('correctAnswerDoesNotExistInAnswerOptions');
91 $obj = new assLongMenu();
92 $value = $method->invokeArgs($obj, [[[1],1,1], [1,2,3,4]]);
93 $this->assertEquals(false, $value);
94 }
95
96 public function test_getMaximumPoints_shouldBeFour(): void
97 {
98 $obj = new assLongMenu();
99 $obj->setCorrectAnswers([0 => [0 => [0 => 'answer'], 1 => '2', 2 => '1'], 1 => [0 => [0 => 'answer'], 1 => '2', 2 => '1']]);
100 $value = $obj->getMaximumPoints();
101 $this->assertEquals(4, $value);
102 }
103
105 {
106 $obj = new assLongMenu();
107 $obj->setCorrectAnswers([0 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1'], 1 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1']]);
108 $value = $obj->getMaximumPoints();
109 $this->assertEquals(4.5, $value);
110 }
111
112 public function test_isComplete_shouldBeFalse(): void
113 {
114 $obj = new assLongMenu();
115 $obj->setCorrectAnswers([0 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1'], 1 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1']]);
116 $obj->setAnswers([[1,2,3,4]]);
117 $this->assertEquals($obj->isComplete(), false);
118 }
119
120 /* Removed by @kergomard 17 NOV 2022, we should introduce this again
121 public function test_isComplete_shouldBeTrue(): void
122 {
123 $obj = new assLongMenu();
124 $obj->setCorrectAnswers([0 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1'], 1 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1']]);
125 $obj->setAnswers([[1,2,3,4]]);
126 $obj->setAuthor("Tester");
127 $obj->setPoints(4.5);
128 $obj->setTitle('LongMenu Title');
129 $obj->setLongMenuTextValue('LongMenu Question');
130 $this->assertEquals($obj->isComplete(), true);
131 } */
132
134 {
135 $obj = new assLongMenu();
136 $this->assertEquals($obj->checkQuestionCustomPart(), false);
137 }
138
140 {
141 $obj = new assLongMenu();
142 $obj->setAnswers([[1,2,3,4]]);
143 $this->assertEquals($obj->checkQuestionCustomPart(), false);
144 }
145
147 {
148 $obj = new assLongMenu();
149 $obj->setCorrectAnswers([0 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1'], 1 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1']]);
150 $this->assertEquals($obj->checkQuestionCustomPart(), false);
151 }
153 {
154 $obj = new assLongMenu();
155 $obj->setCorrectAnswers([0 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1'], 1 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1']]);
156 $obj->setAnswers([['answer']]);
157 $this->assertEquals($obj->checkQuestionCustomPart(), false);
158 }
160 {
161 $obj = new assLongMenu();
162 $obj->setCorrectAnswers([0 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1']]);
163 $obj->setAnswers([[1]]);
164 $this->assertEquals($obj->checkQuestionCustomPart(), false);
165 }
166
168 {
169 $obj = new assLongMenu();
170 $obj->setCorrectAnswers([0 => [0 => [], 1 => '2.25', 2 => '1']]);
171 $obj->setAnswers([['answer']]);
172 $this->assertEquals($obj->checkQuestionCustomPart(), false);
173 }
174
176 {
177 $obj = new assLongMenu();
178 $obj->setCorrectAnswers([0 => [0 => []]]);
179 $obj->setAnswers([['answer']]);
180 $this->assertEquals($obj->checkQuestionCustomPart(), false);
181 }
182
184 {
185 $obj = new assLongMenu();
186 $obj->setCorrectAnswers([0 => [0 => ['answer'], 1 => 0, 2 => '1']]);
187 $obj->setAnswers([['answer']]);
188 $this->assertEquals($obj->checkQuestionCustomPart(), false);
189 }
190
192 {
193 $obj = new assLongMenu();
194 $obj->setCorrectAnswers([0 => [0 => ['answer'], 1 => 1, 2 => '1']]);
195 $obj->setAnswers([['answer']]);
196 $this->assertEquals($obj->checkQuestionCustomPart(), true);
197 }
198
200 {
201 $obj = new assLongMenu();
202 $obj->setAnswerType([]);
203 $this->assertEquals([], $obj->getAnswerType());
204 }
205
206 /* Removed by @kergomard 17 NOV 2022, we should introduce this again
207 public function test_setLongMenuTextValue_shouldReturnGetLongMenuTextValue(): void
208 {
209 $obj = new assLongMenu();
210 $this->assertEquals('', $obj->getLongMenuTextValue());
211 $obj->setLongMenuTextValue('dummy text');
212 $this->assertEquals('dummy text', $obj->getLongMenuTextValue());
213 } */
214
216 {
217 $obj = new assLongMenu();
218 $this->assertEquals(false, $obj->isShuffleAnswersEnabled());
219 $this->assertNotEquals(true, $obj->isShuffleAnswersEnabled());
220 }
221}
Class assBaseTestCase.
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_checkQuestionCustomPart_shouldBeFalseBecauseOnlyCorrectAnswers()
test_instantiateObject_shouldReturnInstance()
test_correctAnswerDoesNotExistInAnswerOptions_shouldReturnTrue()
test_checkQuestionCustomPart_shouldBeFalseBecauseNoCustomPart()
test_checkQuestionCustomPart_shouldBeFalseBecauseCorrectAnswerPointsAreZero()
test_getMaximumPoints_shouldBeFour()
test_checkQuestionCustomPart_shouldBeFalseBecauseOnlyAnswers()
test_checkQuestionCustomPart_shouldBeTrue()
test_checkQuestionCustomPart_shouldBeFalseBecauseCorrectAnswerHasNoPoints()
test_getQuestionType_shouldReturnString()
test_correctAnswerDoesNotExistInAnswerOptions_shouldReturnFalse()
test_checkQuestionCustomPart_shouldBeFalseBecauseCorrectAnswerDoesNotExistsInAnswers()
setGlobalVariable(string $name, mixed $value)