ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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  //$lng_mock->expects( $this->once() )->method( 'txt' )->will( $this->returnValue('Test') );
52  $this->setGlobalVariable('lng', $lng_mock);
53 
54  $this->setGlobalVariable('ilias', $this->getIliasMock());
55  $this->setGlobalVariable('ilDB', $this->getDatabaseMock());
56  }
57 
59  {
60  $instance = new assLongMenu();
61  $this->assertInstanceOf(assLongMenu::class, $instance);
62  }
63 
65  {
66  $instance = new assLongMenu();
67  $this->assertEquals('qpl_qst_lome', $instance->getAdditionalTableName());
68  }
69 
71  {
72  $instance = new assLongMenu();
73  $this->assertEquals('assLongMenu', $instance->getQuestionType());
74  }
75 
77  {
78  $instance = new assLongMenu();
79  $this->assertEquals('qpl_a_lome', $instance->getAnswerTableName());
80  }
81 
83  {
84  $method = self::getMethod('correctAnswerDoesNotExistInAnswerOptions');
85  $obj = new assLongMenu();
86  $value = $method->invokeArgs($obj, [[[5],1,1], [1,2,3,4]]);
87  $this->assertEquals(true, $value);
88  }
89 
91  {
92  $method = self::getMethod('correctAnswerDoesNotExistInAnswerOptions');
93  $obj = new assLongMenu();
94  $value = $method->invokeArgs($obj, [[[1],1,1], [1,2,3,4]]);
95  $this->assertEquals(false, $value);
96  }
97 
98  public function test_getMaximumPoints_shouldBeFour(): void
99  {
100  $obj = new assLongMenu();
101  $obj->setCorrectAnswers([0 => [0 => [0 => 'answer'], 1 => '2', 2 => '1'], 1 => [0 => [0 => 'answer'], 1 => '2', 2 => '1']]);
102  $value = $obj->getMaximumPoints();
103  $this->assertEquals(4, $value);
104  }
105 
107  {
108  $obj = new assLongMenu();
109  $obj->setCorrectAnswers([0 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1'], 1 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1']]);
110  $value = $obj->getMaximumPoints();
111  $this->assertEquals(4.5, $value);
112  }
113 
114  public function test_isComplete_shouldBeFalse(): void
115  {
116  $obj = new assLongMenu();
117  $obj->setCorrectAnswers([0 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1'], 1 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1']]);
118  $obj->setAnswers([[1,2,3,4]]);
119  $this->assertEquals($obj->isComplete(), false);
120  }
121 
122  /* Removed by @kergomard 17 NOV 2022, we should introduce this again
123  public function test_isComplete_shouldBeTrue(): void
124  {
125  $obj = new assLongMenu();
126  $obj->setCorrectAnswers([0 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1'], 1 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1']]);
127  $obj->setAnswers([[1,2,3,4]]);
128  $obj->setAuthor("Tester");
129  $obj->setPoints(4.5);
130  $obj->setTitle('LongMenu Title');
131  $obj->setLongMenuTextValue('LongMenu Question');
132  $this->assertEquals($obj->isComplete(), true);
133  } */
134 
136  {
137  $obj = new assLongMenu();
138  $this->assertEquals($obj->checkQuestionCustomPart(), false);
139  }
140 
142  {
143  $obj = new assLongMenu();
144  $obj->setAnswers([[1,2,3,4]]);
145  $this->assertEquals($obj->checkQuestionCustomPart(), false);
146  }
147 
149  {
150  $obj = new assLongMenu();
151  $obj->setCorrectAnswers([0 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1'], 1 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1']]);
152  $this->assertEquals($obj->checkQuestionCustomPart(), false);
153  }
155  {
156  $obj = new assLongMenu();
157  $obj->setCorrectAnswers([0 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1'], 1 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1']]);
158  $obj->setAnswers([['answer']]);
159  $this->assertEquals($obj->checkQuestionCustomPart(), false);
160  }
162  {
163  $obj = new assLongMenu();
164  $obj->setCorrectAnswers([0 => [0 => [0 => 'answer'], 1 => '2.25', 2 => '1']]);
165  $obj->setAnswers([[1]]);
166  $this->assertEquals($obj->checkQuestionCustomPart(), false);
167  }
168 
170  {
171  $obj = new assLongMenu();
172  $obj->setCorrectAnswers([0 => [0 => [], 1 => '2.25', 2 => '1']]);
173  $obj->setAnswers([['answer']]);
174  $this->assertEquals($obj->checkQuestionCustomPart(), false);
175  }
176 
178  {
179  $obj = new assLongMenu();
180  $obj->setCorrectAnswers([0 => [0 => []]]);
181  $obj->setAnswers([['answer']]);
182  $this->assertEquals($obj->checkQuestionCustomPart(), false);
183  }
184 
186  {
187  $obj = new assLongMenu();
188  $obj->setCorrectAnswers([0 => [0 => ['answer'], 1 => 0, 2 => '1']]);
189  $obj->setAnswers([['answer']]);
190  $this->assertEquals($obj->checkQuestionCustomPart(), false);
191  }
192 
194  {
195  $obj = new assLongMenu();
196  $obj->setCorrectAnswers([0 => [0 => ['answer'], 1 => 1, 2 => '1']]);
197  $obj->setAnswers([['answer']]);
198  $this->assertEquals($obj->checkQuestionCustomPart(), true);
199  }
200 
202  {
203  $obj = new assLongMenu();
204  $obj->setAnswerType([]);
205  $this->assertEquals([], $obj->getAnswerType());
206  }
207 
208  /* Removed by @kergomard 17 NOV 2022, we should introduce this again
209  public function test_setLongMenuTextValue_shouldReturnGetLongMenuTextValue(): void
210  {
211  $obj = new assLongMenu();
212  $this->assertEquals('', $obj->getLongMenuTextValue());
213  $obj->setLongMenuTextValue('dummy text');
214  $this->assertEquals('dummy text', $obj->getLongMenuTextValue());
215  } */
216 
218  {
219  $obj = new assLongMenu();
220  $this->assertEquals(false, $obj->isShuffleAnswersEnabled());
221  $this->assertNotEquals(true, $obj->isShuffleAnswersEnabled());
222  }
223 }
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()
test_checkQuestionCustomPart_shouldBeFalseBecauseCorrectAnswerHasNoAnswers()
test_getAnswerTableName_shouldReturnString()
test_checkQuestionCustomPart_shouldBeFalseBecauseCorrectAnswerDoesNotExistsInAnswers()