17 if (defined(
'ILIAS_PHPUNIT_CONTEXT'))
19 include_once(
"./Services/PHPUnit/classes/class.ilUnitUtil.php");
20 ilUnitUtil::performInitialisation();
24 chdir( dirname( __FILE__ ) );
32 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
37 $this->assertInstanceOf(
'assClozeGap', $instance);
43 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
48 $instance->setType($expected);
49 $actual = $instance->getType();
52 $this->assertEquals($expected, $actual);
58 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
64 $actual = $instance->getType();
67 $this->assertEquals($expected, $actual);
73 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
78 $instance->setShuffle($expected);
79 $actual = $instance->getShuffle();
82 $this->assertEquals($expected, $actual);
88 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
92 $the_unexpected = array(
'Killing',
'Kunkel',
'Luetzenkirchen',
93 'Meyer',
'Jansen',
'Heyser',
'Becker');
94 $actual = $instance->arrayShuffle($the_unexpected);
97 $this->assertNotEquals($the_unexpected, $actual);
103 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
105 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
109 $instance->addItem($expected);
110 $actual = $instance->getItem(0);
113 $this->assertEquals($expected, $actual);
119 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
121 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
126 $instance->addItem($answer);
127 $instance->addItem($expected);
128 $actual = $instance->getItem(0);
131 $this->assertEquals($expected, $actual);
137 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
139 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
143 $instance->addItem($answer1);
144 $instance->addItem($answer2);
149 $actual = $instance->getItem(2);
152 $this->assertEquals($expected, $actual);
158 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
161 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
168 $instance->addItem($answer);
169 $instance->addItem($answer2);
170 $instance->addItem($answer3);
171 $instance->addItem($expected);
172 $actual = $instance->getItem(0);
175 $this->assertEquals($expected, $actual);
181 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
183 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
188 $instance->setShuffle(
false);
189 $expected = array($item1, $item2, $item3, $item4);
192 $instance->addItem($item1);
193 $instance->addItem($item2);
194 $instance->addItem($item3);
195 $instance->addItem($item4);
196 $actual = $instance->getItems();
199 $this->assertEquals($expected, $actual);
205 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
207 $instance->setShuffle(
true);
208 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
213 $expected = array($item1, $item2, $item3, $item4);
216 $instance->addItem($item1);
217 $instance->addItem($item2);
218 $instance->addItem($item3);
219 $instance->addItem($item4);
220 $actual = $instance->getItems();
223 $this->assertTrue(is_array($actual));
224 $this->assertTrue(in_array($item1, $actual));
225 $this->assertTrue(in_array($item2, $actual));
226 $this->assertTrue(in_array($item3, $actual));
227 $this->assertTrue(in_array($item4, $actual));
228 $this->assertNotEquals($expected, $actual);
234 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
236 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
241 $expected = array($item1, $item2, $item3, $item4);
244 $instance->addItem($item1);
245 $instance->addItem($item2);
246 $instance->addItem($item3);
247 $instance->addItem($item4);
248 $actual = $instance->getItemsRaw();
251 $this->assertEquals($expected, $actual);
257 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
259 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
267 $instance->addItem($item1);
268 $instance->addItem($item2);
269 $instance->addItem($item3);
270 $instance->addItem($item4);
271 $actual = $instance->getItemCount();
274 $this->assertEquals($expected, $actual);
277 public function test_setItemPoints_shouldSetItemPoints()
280 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
282 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
284 $instance->addItem($item1);
288 $instance->setItemPoints(0, $expected);
290 $item_retrieved = $instance->getItem(0);
291 $actual = $item_retrieved->getPoints();
294 $this->assertEquals($expected, $actual);
300 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
302 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
306 $instance->addItem($item1);
307 $instance->addItem($item2);
309 $expected = array(
'1' => $item2);
312 $instance->deleteItem(0);
314 $actual = $instance->getItemsRaw();
317 $this->assertEquals($expected, $actual);
323 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
325 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
331 $instance->addItem($item1);
332 $instance->addItem($item2);
333 $instance->addItem($item3);
334 $instance->addItem($item4);
339 $instance->clearItems();
340 $actual = $instance->getItemCount();
343 $this->assertEquals($expected, $actual);
349 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
351 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
354 $instance->addItem($item1);
359 $instance->setItemLowerBound(0, $expected);
360 $item_retrieved = $instance->getItem(0);
361 $actual = $item_retrieved->getLowerBound();
364 $this->assertEquals($expected, $actual);
370 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
372 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
375 $instance->addItem($item1);
380 $instance->setItemLowerBound(0, $expected);
381 $item_retrieved = $instance->getItem(0);
382 $actual = $item_retrieved->getLowerBound();
385 $this->assertNotEquals($expected, $actual);
386 $this->assertEquals($item_retrieved->getAnswerText(), $actual);
392 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
394 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
397 $instance->addItem($item1);
402 $instance->setItemUpperBound(0, $expected);
403 $item_retrieved = $instance->getItem(0);
404 $actual = $item_retrieved->getUpperBound();
407 $this->assertEquals($expected, $actual);
413 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
415 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
418 $instance->addItem($item1);
423 $instance->setItemUpperBound(0, $expected);
424 $item_retrieved = $instance->getItem(0);
425 $actual = $item_retrieved->getUpperBound();
428 $this->assertNotEquals($expected, $actual);
429 $this->assertEquals($item_retrieved->getAnswerText(), $actual);
435 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
437 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
443 $instance->addItem($item1);
444 $instance->addItem($item2);
445 $instance->addItem($item3);
446 $instance->addItem($item4);
448 $expected = strlen($item4->getAnswertext());
451 $actual = $instance->getMaxWidth();
454 $this->assertEquals($expected, $actual);
460 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
462 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
468 $instance->addItem($item1);
469 $instance->addItem($item2);
470 $instance->addItem($item3);
471 $instance->addItem($item4);
473 $expected = array( 0 => 3 );
476 $actual = $instance->getBestSolutionIndexes();
479 $this->assertEquals($expected, $actual);
485 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
487 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
494 require_once
'./Services/Language/classes/class.ilLanguage.php';
495 $lng_mock = $this->getMock(
'ilLanguage', array(
'txt'), array(),
'',
false);
496 $lng_mock->expects( $this->any() )->method(
'txt' )->will( $this->returnValue(
'Test') );
500 $instance->addItem($item1);
501 $instance->addItem($item2);
502 $instance->addItem($item3);
503 $instance->addItem($item4);
505 $expected =
'Esther';
508 $actual = $instance->getBestSolutionOutput();
511 $this->assertEquals($expected, $actual);
517 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
519 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
526 require_once
'./Services/Language/classes/class.ilLanguage.php';
527 $lng_mock = $this->getMock(
'ilLanguage', array(
'txt'), array(),
'',
false);
528 $lng_mock->expects( $this->any() )->method(
'txt' )->will( $this->returnValue(
'or') );
532 $instance->addItem($item1);
533 $instance->addItem($item2);
534 $instance->addItem($item3);
535 $instance->addItem($item4);
537 $expected1 =
'Karl or Esther';
538 $expected2 =
'Esther or Karl';
541 $actual = $instance->getBestSolutionOutput();
544 $this->assertTrue( ($actual == $expected1) || ($actual == $expected2) );
550 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
552 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
559 require_once
'./Services/Language/classes/class.ilLanguage.php';
560 $lng_mock = $this->getMock(
'ilLanguage', array(
'txt'), array(),
'',
false);
561 $lng_mock->expects( $this->any() )->method(
'txt' )->will( $this->returnValue(
'Test') );
565 $instance->addItem($item1);
566 $instance->addItem($item2);
567 $instance->addItem($item3);
568 $instance->addItem($item4);
573 $actual = $instance->getBestSolutionOutput();
576 $this->assertEquals($expected, $actual);
582 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGap.php';
584 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
591 require_once
'./Services/Language/classes/class.ilLanguage.php';
592 $lng_mock = $this->getMock(
'ilLanguage', array(
'txt'), array(),
'',
false);
593 $lng_mock->expects( $this->any() )->method(
'txt' )->will( $this->returnValue(
'Test') );
597 $instance->addItem($item1);
598 $instance->addItem($item2);
599 $instance->addItem($item3);
600 $instance->addItem($item4);
605 $actual = $instance->getBestSolutionOutput();
608 $this->assertEquals($expected, $actual);