ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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  $method->setAccessible(true);
36  return $method;
37  }
38 
39  protected function setUp(): void
40  {
41  chdir(__DIR__ . '/../../../../');
42 
43  parent::setUp();
44 
45  $ilCtrl_mock = $this->createMock('ilCtrl');
46  $ilCtrl_mock->expects($this->any())->method('saveParameter');
47  $ilCtrl_mock->expects($this->any())->method('saveParameterByClass');
48  $this->setGlobalVariable('ilCtrl', $ilCtrl_mock);
49 
50  $lng_mock = $this->createMock('ilLanguage', ['txt'], [], '', false);
51  $this->setGlobalVariable('lng', $lng_mock);
52 
53  $this->setGlobalVariable('ilias', $this->getIliasMock());
54  $this->setGlobalVariable('ilDB', $this->getDatabaseMock());
55  }
56 
58  {
59  $instance = new assLongMenu();
60  $this->assertInstanceOf(assLongMenu::class, $instance);
61  }
62 
64  {
65  $instance = new assLongMenu();
66  $this->assertEquals('qpl_qst_lome', $instance->getAdditionalTableName());
67  }
68 
70  {
71  $instance = new assLongMenu();
72  $this->assertEquals('assLongMenu', $instance->getQuestionType());
73  }
74 
76  {
77  $instance = new assLongMenu();
78  $this->assertEquals('qpl_a_lome', $instance->getAnswerTableName());
79  }
80 
82  {
83  $method = self::getMethod('correctAnswerDoesNotExistInAnswerOptions');
84  $obj = new assLongMenu();
85  $value = $method->invokeArgs($obj, [[[5],1,1], [1,2,3,4]]);
86  $this->assertEquals(true, $value);
87  }
88 
90  {
91  $method = self::getMethod('correctAnswerDoesNotExistInAnswerOptions');
92  $obj = new assLongMenu();
93  $value = $method->invokeArgs($obj, [[[1],1,1], [1,2,3,4]]);
94  $this->assertEquals(false, $value);
95  }
96 
97  public function test_getMaximumPoints_shouldBeFour(): void
98  {
99  $obj = new assLongMenu();
100  $obj->setCorrectAnswers([0 => [0 => [0 => 'answer'], 1 => '2', 2 => '1'], 1 => [0 => [0 => 'answer'], 1 => '2', 2 => '1']]);
101  $value = $obj->getMaximumPoints();
102  $this->assertEquals(4, $value);
103  }
104 
106  {
107  $obj = new assLongMenu();
108  $obj->setCorrectAnswers([0 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1'], 1 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1']]);
109  $value = $obj->getMaximumPoints();
110  $this->assertEquals(4.5, $value);
111  }
112 
113  public function test_isComplete_shouldBeFalse(): void
114  {
115  $obj = new assLongMenu();
116  $obj->setCorrectAnswers([0 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1'], 1 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1']]);
117  $obj->setAnswers([[1,2,3,4]]);
118  $this->assertEquals($obj->isComplete(), false);
119  }
120 
121  /* Removed by @kergomard 17 NOV 2022, we should introduce this again
122  public function test_isComplete_shouldBeTrue(): void
123  {
124  $obj = new assLongMenu();
125  $obj->setCorrectAnswers([0 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1'], 1 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1']]);
126  $obj->setAnswers([[1,2,3,4]]);
127  $obj->setAuthor("Tester");
128  $obj->setPoints(4.5);
129  $obj->setTitle('LongMenu Title');
130  $obj->setLongMenuTextValue('LongMenu Question');
131  $this->assertEquals($obj->isComplete(), true);
132  } */
133 
135  {
136  $obj = new assLongMenu();
137  $this->assertEquals($obj->checkQuestionCustomPart(), false);
138  }
139 
141  {
142  $obj = new assLongMenu();
143  $obj->setAnswers([[1,2,3,4]]);
144  $this->assertEquals($obj->checkQuestionCustomPart(), false);
145  }
146 
148  {
149  $obj = new assLongMenu();
150  $obj->setCorrectAnswers([0 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1'], 1 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1']]);
151  $this->assertEquals($obj->checkQuestionCustomPart(), false);
152  }
154  {
155  $obj = new assLongMenu();
156  $obj->setCorrectAnswers([0 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1'], 1 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1']]);
157  $obj->setAnswers([['answer']]);
158  $this->assertEquals($obj->checkQuestionCustomPart(), false);
159  }
161  {
162  $obj = new assLongMenu();
163  $obj->setCorrectAnswers([0 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1']]);
164  $obj->setAnswers([[1]]);
165  $this->assertEquals($obj->checkQuestionCustomPart(), false);
166  }
167 
169  {
170  $obj = new assLongMenu();
171  $obj->setCorrectAnswers([0 => [0 => [], 1 => '2.25', 2 => '1']]);
172  $obj->setAnswers([['answer']]);
173  $this->assertEquals($obj->checkQuestionCustomPart(), false);
174  }
175 
177  {
178  $obj = new assLongMenu();
179  $obj->setCorrectAnswers([0 => [0 => []]]);
180  $obj->setAnswers([['answer']]);
181  $this->assertEquals($obj->checkQuestionCustomPart(), false);
182  }
183 
185  {
186  $obj = new assLongMenu();
187  $obj->setCorrectAnswers([0 => [0 => ['answer'], 1 => 0, 2 => '1']]);
188  $obj->setAnswers([['answer']]);
189  $this->assertEquals($obj->checkQuestionCustomPart(), false);
190  }
191 
193  {
194  $obj = new assLongMenu();
195  $obj->setCorrectAnswers([0 => [0 => ['answer'], 1 => 1, 2 => '1']]);
196  $obj->setAnswers([['answer']]);
197  $this->assertEquals($obj->checkQuestionCustomPart(), true);
198  }
199 
201  {
202  $obj = new assLongMenu();
203  $obj->setAnswerType([]);
204  $this->assertEquals([], $obj->getAnswerType());
205  }
206 
207  /* Removed by @kergomard 17 NOV 2022, we should introduce this again
208  public function test_setLongMenuTextValue_shouldReturnGetLongMenuTextValue(): void
209  {
210  $obj = new assLongMenu();
211  $this->assertEquals('', $obj->getLongMenuTextValue());
212  $obj->setLongMenuTextValue('dummy text');
213  $this->assertEquals('dummy text', $obj->getLongMenuTextValue());
214  } */
215 
217  {
218  $obj = new assLongMenu();
219  $this->assertEquals(false, $obj->isShuffleAnswersEnabled());
220  $this->assertNotEquals(true, $obj->isShuffleAnswersEnabled());
221  }
222 }
test_checkQuestionCustomPart_shouldBeFalseBecauseCorrectAnswerHasNoPoints()
test_getAdditionalTableName_shouldReturnString()
test_checkQuestionCustomPart_shouldBeFalseBecauseCorrectAnswerPointsAreZero()
Class assBaseTestCase.
test_checkQuestionCustomPart_shouldBeTrue()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
test_setAnswerType_shouldReturnGetAnswerType()
test_getMaximumPoints_shouldBeFourPointFive()
test_correctAnswerDoesNotExistInAnswerOptions_shouldReturnFalse()
static getMethod($name)
test_correctAnswerDoesNotExistInAnswerOptions_shouldReturnTrue()
test_checkQuestionCustomPart_shouldBeFalseBecauseNoCustomPart()
test_checkQuestionCustomPart_shouldBeFalseBecauseOnlyCorrectAnswers()
test_instantiateObject_shouldReturnInstance()
test_getQuestionType_shouldReturnString()
test_getMaximumPoints_shouldBeFour()
test_isShuffleAnswersEnabled_shouldReturnFalse()
test_checkQuestionCustomPart_shouldBeFalseBecauseOnlyAnswers()
test_checkQuestionCustomPart_shouldBeFalseBecauseToManyCorrectAnswers()
setGlobalVariable(string $name, mixed $value)
test_checkQuestionCustomPart_shouldBeFalseBecauseCorrectAnswerHasNoAnswers()
test_getAnswerTableName_shouldReturnString()
test_checkQuestionCustomPart_shouldBeFalseBecauseCorrectAnswerDoesNotExistsInAnswers()