ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
assClozeGapTest.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 {
13  protected $backupGlobals = FALSE;
14 
15  protected function setUp()
16  {
17  if (defined('ILIAS_PHPUNIT_CONTEXT'))
18  {
19  include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
20  ilUnitUtil::performInitialisation();
21  }
22  else
23  {
24  chdir( dirname( __FILE__ ) );
25  chdir('../../../');
26  }
27  require_once './Services/Utilities/classes/class.ilUtil.php';
28  require_once './Services/Randomization/classes/class.ilArrayElementShuffler.php';
29  $util_mock = $this->getMock('ilUtil', array('stripSlashes'), array(), '', false);
30  $util_mock->expects( $this->any() )->method( 'stripSlashes' )->will( $this->returnArgument(0) );
31  global $ilUtils;
32  $ilUtils = $util_mock;
33  }
34 
36  {
37  // Arrange
38  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
39 
40  // Act
41  $instance = new assClozeGap(0); // 0 - text gap
42 
43  $this->assertInstanceOf('assClozeGap', $instance);
44  }
45 
47  {
48  // Arrange
49  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
50  $instance = new assClozeGap(0); // 0 - text gap
51  $expected = 1; // 1 - select gap
52 
53  // Act
54  $instance->setType($expected);
55  $actual = $instance->getType();
56 
57  // Assert
58  $this->assertEquals($expected, $actual);
59  }
60 
62  {
63  // Arrange
64  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
65  $instance = new assClozeGap(0); // 0 - text gap
66  $expected = 0; // 0 - text gap
67 
68  // Act
69  $instance->setType();
70  $actual = $instance->getType();
71 
72  // Assert
73  $this->assertEquals($expected, $actual);
74  }
75 
77  {
78  // Arrange
79  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
80  $instance = new assClozeGap(0); // 0 - text gap
81  $expected = true;
82 
83  // Act
84  $instance->setShuffle($expected);
85  $actual = $instance->getShuffle();
86 
87  // Assert
88  $this->assertEquals($expected, $actual);
89  }
90 
92  {
93  // Arrange
94  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
95 
96  $instance = new assClozeGap(0); // 0 - text gap
97 
98  // Act
99  $the_unexpected = array('Killing', 'Kunkel', 'Luetzenkirchen',
100  'Meyer', 'Jansen', 'Heyser', 'Becker');
101  $instance->items = $the_unexpected;
102  $instance->setShuffle(true);
103 
104  $actual = $instance->getItems(new ilArrayElementShuffler);
105 
106  // Assert
107  $this->assertNotEquals($the_unexpected, $actual);
108  }
109 
111  {
112  // Arrange
113  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
114  $instance = new assClozeGap(0); // 0 - text gap
115  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
116  $expected = new assAnswerCloze('Esther', 1.0, 0);
117 
118  // Act
119  $instance->addItem($expected);
120  $actual = $instance->getItem(0);
121 
122  // Assert
123  $this->assertEquals($expected, $actual);
124  }
125 
127  {
128  // Arrange
129  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
130  $instance = new assClozeGap(0); // 0 - text gap
131  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
132  $answer = new assAnswerCloze('Bert', 1.0, 0);
133  $expected = new assAnswerCloze('Esther', 1.0, 0);
134 
135  // Act
136  $instance->addItem($answer);
137  $instance->addItem($expected);
138  $actual = $instance->getItem(0);
139 
140  // Assert
141  $this->assertEquals($expected, $actual);
142  }
143 
145  {
146  // Arrange
147  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
148  $instance = new assClozeGap(0); // 0 - text gap
149  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
150  $answer1 = new assAnswerCloze('Bert', 1.0, 0);
151  $answer2 = new assAnswerCloze('Esther', 1.0, 1);
152 
153  $instance->addItem($answer1);
154  $instance->addItem($answer2);
155 
156  $expected = null;
157 
158  // Act
159  $actual = $instance->getItem(2);
160 
161  // Assert
162  $this->assertEquals($expected, $actual);
163  }
164 
166  {
167  // Arrange
168  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
169  $instance = new assClozeGap(0); // 0 - text gap
170 
171  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
172  $answer = new assAnswerCloze('Bert', 1.0, 1);
173  $answer2 = new assAnswerCloze('Fred', 1.0, 2);
174  $answer3 = new assAnswerCloze('Karl', 1.0, 3);
175  $expected = new assAnswerCloze('Esther', 1.0, 0);
176 
177  // Act
178  $instance->addItem($answer);
179  $instance->addItem($answer2);
180  $instance->addItem($answer3);
181  $instance->addItem($expected);
182  $actual = $instance->getItem(0);
183 
184  // Assert
185  $this->assertEquals($expected, $actual);
186  }
187 
189  {
190  // Arrange
191  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
192  $instance = new assClozeGap(0); // 0 - text gap
193  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
194  $item1 = new assAnswerCloze('Bert', 1.0, 0);
195  $item2 = new assAnswerCloze('Fred', 1.0, 1);
196  $item3 = new assAnswerCloze('Karl', 1.0, 2);
197  $item4 = new assAnswerCloze('Esther', 1.0, 3);
198  $instance->setShuffle(false);
199  $expected = array($item1, $item2, $item3, $item4);
200  // Act
201  $instance->addItem($item1);
202  $instance->addItem($item2);
203  $instance->addItem($item3);
204  $instance->addItem($item4);
205  $actual = $instance->getItems(new ilArrayElementShuffler);
206 
207  // Assert
208  $this->assertEquals($expected, $actual);
209  }
210 
212  {
213  // Arrange
214  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
215  $instance = new assClozeGap(0); // 0 - text gap
216  $instance->setShuffle(true);
217  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
218  $item1 = new assAnswerCloze('Bert', 1.0, 0);
219  $item2 = new assAnswerCloze('Fred', 1.0, 1);
220  $item3 = new assAnswerCloze('Karl', 1.0, 2);
221  $item4 = new assAnswerCloze('Esther', 1.0, 3);
222  $item5 = new assAnswerCloze('Herbert', 1.0, 4);
223  $item6 = new assAnswerCloze('Karina', 1.0, 5);
224  $item7 = new assAnswerCloze('Helmut', 1.0, 6);
225  $item8 = new assAnswerCloze('Kerstin', 1.0, 7);
226  $expected = array($item1, $item2, $item3, $item4, $item5, $item6, $item7, $item8);
227 
228  // Act
229  $instance->addItem($item1);
230  $instance->addItem($item2);
231  $instance->addItem($item3);
232  $instance->addItem($item4);
233  $instance->addItem($item5);
234  $instance->addItem($item6);
235  $instance->addItem($item7);
236  $instance->addItem($item8);
237  $actual = $instance->getItems(new ilArrayElementShuffler);
238 
239  // Assert
240  $this->assertTrue(is_array($actual));
241  $this->assertTrue(in_array($item1, $actual));
242  $this->assertTrue(in_array($item2, $actual));
243  $this->assertTrue(in_array($item3, $actual));
244  $this->assertTrue(in_array($item4, $actual));
245  $this->assertTrue(in_array($item5, $actual));
246  $this->assertTrue(in_array($item6, $actual));
247  $this->assertTrue(in_array($item7, $actual));
248  $this->assertTrue(in_array($item8, $actual));
249  $this->assertNotEquals($expected, $actual);
250  }
251 
253  {
254  // Arrange
255  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
256  $instance = new assClozeGap(0); // 0 - text gap
257  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
258  $item1 = new assAnswerCloze('Bert', 1.0, 0);
259  $item2 = new assAnswerCloze('Fred', 1.0, 1);
260  $item3 = new assAnswerCloze('Karl', 1.0, 2);
261  $item4 = new assAnswerCloze('Esther', 1.0, 3);
262  $expected = array($item1, $item2, $item3, $item4);
263 
264  // Act
265  $instance->addItem($item1);
266  $instance->addItem($item2);
267  $instance->addItem($item3);
268  $instance->addItem($item4);
269  $actual = $instance->getItemsRaw();
270 
271  // Assert
272  $this->assertEquals($expected, $actual);
273  }
274 
276  {
277  // Arrange
278  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
279  $instance = new assClozeGap(0); // 0 - text gap
280  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
281  $item1 = new assAnswerCloze('Bert', 1.0, 0);
282  $item2 = new assAnswerCloze('Fred', 1.0, 2);
283  $item3 = new assAnswerCloze('Karl', 1.0, 1);
284  $item4 = new assAnswerCloze('Esther', 1.0, 3);
285  $expected = 4;
286 
287  // Act
288  $instance->addItem($item1);
289  $instance->addItem($item2);
290  $instance->addItem($item3);
291  $instance->addItem($item4);
292  $actual = $instance->getItemCount();
293 
294  // Assert
295  $this->assertEquals($expected, $actual);
296  }
297 
298  public function test_setItemPoints_shouldSetItemPoints()
299  {
300  // Arrange
301  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
302  $instance = new assClozeGap(0); // 0 - text gap
303  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
304  $item1 = new assAnswerCloze('Esther', 1.0, 0);
305  $instance->addItem($item1);
306  $expected = 4;
307 
308  // Act
309  $instance->setItemPoints(0, $expected);
311  $item_retrieved = $instance->getItem(0);
312  $actual = $item_retrieved->getPoints();
313 
314  // Assert
315  $this->assertEquals($expected, $actual);
316  }
317 
319  {
320  // Arrange
321  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
322  $instance = new assClozeGap(0); // 0 - text gap
323  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
324  $item1 = new assAnswerCloze('Bert', 1.0, 0);
325  $item2 = new assAnswerCloze('Fred', 1.0, 1);
326 
327  $instance->addItem($item1);
328  $instance->addItem($item2);
329 
330  $expected = array('1' => $item2);
331 
332  // Act
333  $instance->deleteItem(0);
334 
335  $actual = $instance->getItemsRaw();
336 
337  // Assert
338  $this->assertEquals($expected, $actual);
339  }
340 
342  {
343  // Arrange
344  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
345  $instance = new assClozeGap(0); // 0 - text gap
346  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
347  $item1 = new assAnswerCloze('Bert', 1.0, 0);
348  $item2 = new assAnswerCloze('Fred', 1.0, 2);
349  $item3 = new assAnswerCloze('Karl', 1.0, 1);
350  $item4 = new assAnswerCloze('Esther', 1.0, 3);
351 
352  $instance->addItem($item1);
353  $instance->addItem($item2);
354  $instance->addItem($item3);
355  $instance->addItem($item4);
356 
357  $expected = 0;
358 
359  // Act
360  $instance->clearItems();
361  $actual = $instance->getItemCount();
362 
363  // Assert
364  $this->assertEquals($expected, $actual);
365  }
366 
368  {
369  // Arrange
370  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
371  $instance = new assClozeGap(0); // 0 - text gap
372  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
373  $item1 = new assAnswerCloze(20, 1.0, 0);
374 
375  $instance->addItem($item1);
376 
377  $expected = 10;
378 
379  // Act
380  $instance->setItemLowerBound(0, $expected);
381  $item_retrieved = $instance->getItem(0);
382  $actual = $item_retrieved->getLowerBound();
383 
384  // Assert
385  $this->assertEquals($expected, $actual);
386  }
387 
389  {
390  // Arrange
391  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
392  $instance = new assClozeGap(0); // 0 - text gap
393  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
394  $item1 = new assAnswerCloze(20, 1.0, 0);
395 
396  $instance->addItem($item1);
397 
398  $expected = 40;
399 
400  // Act
401  $instance->setItemLowerBound(0, $expected);
402  $item_retrieved = $instance->getItem(0);
403  $actual = $item_retrieved->getLowerBound();
404 
405  // Assert
406  $this->assertNotEquals($expected, $actual);
407  $this->assertEquals($item_retrieved->getAnswerText(), $actual);
408  }
409 
411  {
412  // Arrange
413  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
414  $instance = new assClozeGap(0); // 0 - text gap
415  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
416  $item1 = new assAnswerCloze(5, 1.0, 0);
417 
418  $instance->addItem($item1);
419 
420  $expected = 10;
421 
422  // Act
423  $instance->setItemUpperBound(0, $expected);
424  $item_retrieved = $instance->getItem(0);
425  $actual = $item_retrieved->getUpperBound();
426 
427  // Assert
428  $this->assertEquals($expected, $actual);
429  }
430 
432  {
433  // Arrange
434  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
435  $instance = new assClozeGap(0); // 0 - text gap
436  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
437  $item1 = new assAnswerCloze(20, 1.0, 0);
438 
439  $instance->addItem($item1);
440 
441  $expected = 10;
442 
443  // Act
444  $instance->setItemUpperBound(0, $expected);
445  $item_retrieved = $instance->getItem(0);
446  $actual = $item_retrieved->getUpperBound();
447 
448  // Assert
449  $this->assertNotEquals($expected, $actual);
450  $this->assertEquals($item_retrieved->getAnswerText(), $actual);
451  }
452 
454  {
455  // Arrange
456  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
457  $instance = new assClozeGap(0); // 0 - text gap
458  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
459  $item1 = new assAnswerCloze('Bert', 1.0, 0);
460  $item2 = new assAnswerCloze('Fred', 1.0, 2);
461  $item3 = new assAnswerCloze('Karl', 1.0, 1);
462  $item4 = new assAnswerCloze('Esther', 1.0, 3);
463 
464  $instance->addItem($item1);
465  $instance->addItem($item2);
466  $instance->addItem($item3);
467  $instance->addItem($item4);
468 
469  $expected = strlen($item4->getAnswertext());
470 
471  // Act
472  $actual = $instance->getMaxWidth();
473 
474  // Assert
475  $this->assertEquals($expected, $actual);
476  }
477 
479  {
480  // Arrange
481  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
482  $instance = new assClozeGap(0); // 0 - text gap
483  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
484  $item1 = new assAnswerCloze('Bert', 1.0, 0);
485  $item2 = new assAnswerCloze('Fred', 2.0, 2);
486  $item3 = new assAnswerCloze('Karl', 3.0, 1);
487  $item4 = new assAnswerCloze('Esther', 4.0, 3);
488 
489  $instance->addItem($item1);
490  $instance->addItem($item2);
491  $instance->addItem($item3);
492  $instance->addItem($item4);
493 
494  $expected = array( 0 => 3 );
495 
496  // Act
497  $actual = $instance->getBestSolutionIndexes();
498 
499  // Assert
500  $this->assertEquals($expected, $actual);
501  }
502 
504  {
505  // Arrange
506  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
507  $instance = new assClozeGap(0); // 0 - text gap
508  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
509  $item1 = new assAnswerCloze('Bert', 1.0, 0);
510  $item2 = new assAnswerCloze('Fred', 2.0, 2);
511  $item3 = new assAnswerCloze('Karl', 3.0, 1);
512  $item4 = new assAnswerCloze('Esther', 4.0, 3);
513 
514  // We need the $lng-mock.
515  require_once './Services/Language/classes/class.ilLanguage.php';
516  $lng_mock = $this->getMock('ilLanguage', array('txt'), array(), '', false);
517  $lng_mock->expects( $this->any() )->method( 'txt' )->will( $this->returnValue('Test') );
518  global $lng;
519  $lng = $lng_mock;
520 
521  $instance->addItem($item1);
522  $instance->addItem($item2);
523  $instance->addItem($item3);
524  $instance->addItem($item4);
525 
526  $expected = 'Esther';
527 
528  // Act
529  $actual = $instance->getBestSolutionOutput(new ilArrayElementShuffler);
530 
531  // Assert
532  $this->assertEquals($expected, $actual);
533  }
534 
536  {
537  // Arrange
538  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
539  $instance = new assClozeGap(0); // 0 - text gap
540  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
541  $item1 = new assAnswerCloze('Bert', 1.0, 0);
542  $item2 = new assAnswerCloze('Fred', 2.0, 2);
543  $item3 = new assAnswerCloze('Karl', 4, 1);
544  $item4 = new assAnswerCloze('Esther', 4, 3);
545 
546  // We need the $lng-mock.
547  require_once './Services/Language/classes/class.ilLanguage.php';
548  $lng_mock = $this->getMock('ilLanguage', array('txt'), array(), '', false);
549  $lng_mock->expects( $this->any() )->method( 'txt' )->will( $this->returnValue('or') );
550  global $lng;
551  $lng = $lng_mock;
552 
553  $instance->setShuffle(true);
554  $instance->addItem($item1);
555  $instance->addItem($item2);
556  $instance->addItem($item3);
557  $instance->addItem($item4);
558 
559  $expected1 = 'Karl or Esther';
560  $expected2 = 'Esther or Karl';
561 
562  // Act
563  $actual = $instance->getBestSolutionOutput(new ilArrayElementShuffler);
564 
565  // Assert
566  $this->assertTrue( ($actual == $expected1) || ($actual == $expected2) );
567  }
568 
570  {
571  // Arrange
572  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
573  $instance = new assClozeGap(2); // 0 - text gap
574  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
575  $item1 = new assAnswerCloze(10, 1.0, 0);
576  $item2 = new assAnswerCloze(20, 2.0, 2);
577  $item3 = new assAnswerCloze(30, 3.0, 1);
578  $item4 = new assAnswerCloze(100, 4.0, 3);
579 
580  // We need the $lng-mock.
581  require_once './Services/Language/classes/class.ilLanguage.php';
582  $lng_mock = $this->getMock('ilLanguage', array('txt'), array(), '', false);
583  $lng_mock->expects( $this->any() )->method( 'txt' )->will( $this->returnValue('Test') );
584  global $lng;
585  $lng = $lng_mock;
586 
587  $instance->addItem($item1);
588  $instance->addItem($item2);
589  $instance->addItem($item3);
590  $instance->addItem($item4);
591 
592  $expected = 100;
593 
594  // Act
595  $actual = $instance->getBestSolutionOutput(new ilArrayElementShuffler);
596 
597  // Assert
598  $this->assertEquals($expected, $actual);
599  }
600 
602  {
603  // Arrange
604  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
605  $instance = new assClozeGap(11); // 0 - text gap
606  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
607  $item1 = new assAnswerCloze(10, 1.0, 0);
608  $item2 = new assAnswerCloze(20, 2.0, 2);
609  $item3 = new assAnswerCloze(30, 3.0, 1);
610  $item4 = new assAnswerCloze(100, 4.0, 3);
611 
612  // We need the $lng-mock.
613  require_once './Services/Language/classes/class.ilLanguage.php';
614  $lng_mock = $this->getMock('ilLanguage', array('txt'), array(), '', false);
615  $lng_mock->expects( $this->any() )->method( 'txt' )->will( $this->returnValue('Test') );
616  global $lng;
617  $lng = $lng_mock;
618 
619  $instance->addItem($item1);
620  $instance->addItem($item2);
621  $instance->addItem($item3);
622  $instance->addItem($item4);
623 
624  $expected = '';
625 
626  // Act
627  $actual = $instance->getBestSolutionOutput(new ilArrayElementShuffler);
628 
629  // Assert
630  $this->assertEquals($expected, $actual);
631  }
632 }
Class for cloze question numeric answers.
test_addGetItem_shouldReturnValueUnchanged()
test_getItemsWithShuffle_shouldReturnItemsAddedShuffled()
test_getMaxWidth_shouldReturnCharacterCountOfLongestAnswertext()
test_getBestSolutionOutput_shouldReturnBestSolutionOutput_CaseNumeric()
test_getBestSolutionOutput_shouldReturnBestSolutionOutput_CaseTextMulti()
test_instantiateObject_shouldReturnInstance()
test_setType_shouldSetDefaultIfNotPassed()
Class for cloze question gaps.
test_getItemsRaw_shouldReturnItemsAdded()
test_addGetItem_shouldReturnValueUnchangedMultiplePlus()
test_setItemUpperBound_shouldSetItemsAnswerIfBoundTooLow()
test_deleteItem_shouldDeleteGivenItem()
test_setItemLowerBound_shouldSetItemsLowerBound()
test_getItemCount_shouldReturnCorrectCount()
test_getBestSolutionIndexes_shouldReturnBestSolutionIndexes()
test_setItemUpperBound_shouldSetItemsUpperBound()
Create styles array
The data for the language used.
test_arrayShuffle_shouldNotReturnArrayUnshuffled()
test_getBestSolutionOutput_shouldReturnBestSolutionOutput_CaseText()
test_getItem_shouldReturnNullIfNoItemAtGivenIndex()
test_getItems_shouldReturnItemsAdded()
global $lng
Definition: privfeed.php:17
test_getBestSolutionOutput_shouldReturnEmptyStringOnUnknownType_WhichMakesNoSenseButK()
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27
test_addGetItem_shouldReturnValueUnchangedMultiple()
test_setItemLowerBound_shouldSetItemsAnswerIfBoundTooHigh()
test_setGetType_shouldReturnUnchangedValue()
test_setGetShuffle_shouldReturnUnchangedValue()