ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  }
28 
30  {
31  // Arrange
32  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
33 
34  // Act
35  $instance = new assClozeGap(0); // 0 - text gap
36 
37  $this->assertInstanceOf('assClozeGap', $instance);
38  }
39 
41  {
42  // Arrange
43  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
44  $instance = new assClozeGap(0); // 0 - text gap
45  $expected = 1; // 1 - select gap
46 
47  // Act
48  $instance->setType($expected);
49  $actual = $instance->getType();
50 
51  // Assert
52  $this->assertEquals($expected, $actual);
53  }
54 
56  {
57  // Arrange
58  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
59  $instance = new assClozeGap(0); // 0 - text gap
60  $expected = 0; // 0 - text gap
61 
62  // Act
63  $instance->setType();
64  $actual = $instance->getType();
65 
66  // Assert
67  $this->assertEquals($expected, $actual);
68  }
69 
71  {
72  // Arrange
73  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
74  $instance = new assClozeGap(0); // 0 - text gap
75  $expected = true;
76 
77  // Act
78  $instance->setShuffle($expected);
79  $actual = $instance->getShuffle();
80 
81  // Assert
82  $this->assertEquals($expected, $actual);
83  }
84 
86  {
87  // Arrange
88  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
89  $instance = new assClozeGap(0); // 0 - text gap
90 
91  // Act
92  $the_unexpected = array('Killing', 'Kunkel', 'Luetzenkirchen',
93  'Meyer', 'Jansen', 'Heyser', 'Becker');
94  $actual = $instance->arrayShuffle($the_unexpected);
95 
96  // Assert
97  $this->assertNotEquals($the_unexpected, $actual);
98  }
99 
101  {
102  // Arrange
103  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
104  $instance = new assClozeGap(0); // 0 - text gap
105  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
106  $expected = new assAnswerCloze('Esther', 1.0, 0);
107 
108  // Act
109  $instance->addItem($expected);
110  $actual = $instance->getItem(0);
111 
112  // Assert
113  $this->assertEquals($expected, $actual);
114  }
115 
117  {
118  // Arrange
119  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
120  $instance = new assClozeGap(0); // 0 - text gap
121  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
122  $answer = new assAnswerCloze('Bert', 1.0, 0);
123  $expected = new assAnswerCloze('Esther', 1.0, 0);
124 
125  // Act
126  $instance->addItem($answer);
127  $instance->addItem($expected);
128  $actual = $instance->getItem(0);
129 
130  // Assert
131  $this->assertEquals($expected, $actual);
132  }
133 
135  {
136  // Arrange
137  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
138  $instance = new assClozeGap(0); // 0 - text gap
139  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
140  $answer1 = new assAnswerCloze('Bert', 1.0, 0);
141  $answer2 = new assAnswerCloze('Esther', 1.0, 1);
142 
143  $instance->addItem($answer1);
144  $instance->addItem($answer2);
145 
146  $expected = null;
147 
148  // Act
149  $actual = $instance->getItem(2);
150 
151  // Assert
152  $this->assertEquals($expected, $actual);
153  }
154 
156  {
157  // Arrange
158  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
159  $instance = new assClozeGap(0); // 0 - text gap
160 
161  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
162  $answer = new assAnswerCloze('Bert', 1.0, 1);
163  $answer2 = new assAnswerCloze('Fred', 1.0, 2);
164  $answer3 = new assAnswerCloze('Karl', 1.0, 3);
165  $expected = new assAnswerCloze('Esther', 1.0, 0);
166 
167  // Act
168  $instance->addItem($answer);
169  $instance->addItem($answer2);
170  $instance->addItem($answer3);
171  $instance->addItem($expected);
172  $actual = $instance->getItem(0);
173 
174  // Assert
175  $this->assertEquals($expected, $actual);
176  }
177 
179  {
180  // Arrange
181  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
182  $instance = new assClozeGap(0); // 0 - text gap
183  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
184  $item1 = new assAnswerCloze('Bert', 1.0, 0);
185  $item2 = new assAnswerCloze('Fred', 1.0, 1);
186  $item3 = new assAnswerCloze('Karl', 1.0, 2);
187  $item4 = new assAnswerCloze('Esther', 1.0, 3);
188  $instance->setShuffle(false);
189  $expected = array($item1, $item2, $item3, $item4);
190 
191  // Act
192  $instance->addItem($item1);
193  $instance->addItem($item2);
194  $instance->addItem($item3);
195  $instance->addItem($item4);
196  $actual = $instance->getItems();
197 
198  // Assert
199  $this->assertEquals($expected, $actual);
200  }
201 
203  {
204  // Arrange
205  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
206  $instance = new assClozeGap(0); // 0 - text gap
207  $instance->setShuffle(true);
208  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
209  $item1 = new assAnswerCloze('Bert', 1.0, 0);
210  $item2 = new assAnswerCloze('Fred', 1.0, 1);
211  $item3 = new assAnswerCloze('Karl', 1.0, 2);
212  $item4 = new assAnswerCloze('Esther', 1.0, 3);
213  $expected = array($item1, $item2, $item3, $item4);
214 
215  // Act
216  $instance->addItem($item1);
217  $instance->addItem($item2);
218  $instance->addItem($item3);
219  $instance->addItem($item4);
220  $actual = $instance->getItems();
221 
222  // Assert
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);
229  }
230 
232  {
233  // Arrange
234  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
235  $instance = new assClozeGap(0); // 0 - text gap
236  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
237  $item1 = new assAnswerCloze('Bert', 1.0, 0);
238  $item2 = new assAnswerCloze('Fred', 1.0, 1);
239  $item3 = new assAnswerCloze('Karl', 1.0, 2);
240  $item4 = new assAnswerCloze('Esther', 1.0, 3);
241  $expected = array($item1, $item2, $item3, $item4);
242 
243  // Act
244  $instance->addItem($item1);
245  $instance->addItem($item2);
246  $instance->addItem($item3);
247  $instance->addItem($item4);
248  $actual = $instance->getItemsRaw();
249 
250  // Assert
251  $this->assertEquals($expected, $actual);
252  }
253 
255  {
256  // Arrange
257  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
258  $instance = new assClozeGap(0); // 0 - text gap
259  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
260  $item1 = new assAnswerCloze('Bert', 1.0, 0);
261  $item2 = new assAnswerCloze('Fred', 1.0, 2);
262  $item3 = new assAnswerCloze('Karl', 1.0, 1);
263  $item4 = new assAnswerCloze('Esther', 1.0, 3);
264  $expected = 4;
265 
266  // Act
267  $instance->addItem($item1);
268  $instance->addItem($item2);
269  $instance->addItem($item3);
270  $instance->addItem($item4);
271  $actual = $instance->getItemCount();
272 
273  // Assert
274  $this->assertEquals($expected, $actual);
275  }
276 
277  public function test_setItemPoints_shouldSetItemPoints()
278  {
279  // Arrange
280  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
281  $instance = new assClozeGap(0); // 0 - text gap
282  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
283  $item1 = new assAnswerCloze('Esther', 1.0, 0);
284  $instance->addItem($item1);
285  $expected = 4;
286 
287  // Act
288  $instance->setItemPoints(0, $expected);
290  $item_retrieved = $instance->getItem(0);
291  $actual = $item_retrieved->getPoints();
292 
293  // Assert
294  $this->assertEquals($expected, $actual);
295  }
296 
298  {
299  // Arrange
300  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
301  $instance = new assClozeGap(0); // 0 - text gap
302  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
303  $item1 = new assAnswerCloze('Bert', 1.0, 0);
304  $item2 = new assAnswerCloze('Fred', 1.0, 1);
305 
306  $instance->addItem($item1);
307  $instance->addItem($item2);
308 
309  $expected = array('1' => $item2);
310 
311  // Act
312  $instance->deleteItem(0);
313 
314  $actual = $instance->getItemsRaw();
315 
316  // Assert
317  $this->assertEquals($expected, $actual);
318  }
319 
321  {
322  // Arrange
323  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
324  $instance = new assClozeGap(0); // 0 - text gap
325  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
326  $item1 = new assAnswerCloze('Bert', 1.0, 0);
327  $item2 = new assAnswerCloze('Fred', 1.0, 2);
328  $item3 = new assAnswerCloze('Karl', 1.0, 1);
329  $item4 = new assAnswerCloze('Esther', 1.0, 3);
330 
331  $instance->addItem($item1);
332  $instance->addItem($item2);
333  $instance->addItem($item3);
334  $instance->addItem($item4);
335 
336  $expected = 0;
337 
338  // Act
339  $instance->clearItems();
340  $actual = $instance->getItemCount();
341 
342  // Assert
343  $this->assertEquals($expected, $actual);
344  }
345 
347  {
348  // Arrange
349  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
350  $instance = new assClozeGap(0); // 0 - text gap
351  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
352  $item1 = new assAnswerCloze(20, 1.0, 0);
353 
354  $instance->addItem($item1);
355 
356  $expected = 10;
357 
358  // Act
359  $instance->setItemLowerBound(0, $expected);
360  $item_retrieved = $instance->getItem(0);
361  $actual = $item_retrieved->getLowerBound();
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 = 40;
378 
379  // Act
380  $instance->setItemLowerBound(0, $expected);
381  $item_retrieved = $instance->getItem(0);
382  $actual = $item_retrieved->getLowerBound();
383 
384  // Assert
385  $this->assertNotEquals($expected, $actual);
386  $this->assertEquals($item_retrieved->getAnswerText(), $actual);
387  }
388 
390  {
391  // Arrange
392  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
393  $instance = new assClozeGap(0); // 0 - text gap
394  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
395  $item1 = new assAnswerCloze(5, 1.0, 0);
396 
397  $instance->addItem($item1);
398 
399  $expected = 10;
400 
401  // Act
402  $instance->setItemUpperBound(0, $expected);
403  $item_retrieved = $instance->getItem(0);
404  $actual = $item_retrieved->getUpperBound();
405 
406  // Assert
407  $this->assertEquals($expected, $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(20, 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->assertNotEquals($expected, $actual);
429  $this->assertEquals($item_retrieved->getAnswerText(), $actual);
430  }
431 
433  {
434  // Arrange
435  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
436  $instance = new assClozeGap(0); // 0 - text gap
437  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
438  $item1 = new assAnswerCloze('Bert', 1.0, 0);
439  $item2 = new assAnswerCloze('Fred', 1.0, 2);
440  $item3 = new assAnswerCloze('Karl', 1.0, 1);
441  $item4 = new assAnswerCloze('Esther', 1.0, 3);
442 
443  $instance->addItem($item1);
444  $instance->addItem($item2);
445  $instance->addItem($item3);
446  $instance->addItem($item4);
447 
448  $expected = strlen($item4->getAnswertext());
449 
450  // Act
451  $actual = $instance->getMaxWidth();
452 
453  // Assert
454  $this->assertEquals($expected, $actual);
455  }
456 
458  {
459  // Arrange
460  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
461  $instance = new assClozeGap(0); // 0 - text gap
462  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
463  $item1 = new assAnswerCloze('Bert', 1.0, 0);
464  $item2 = new assAnswerCloze('Fred', 2.0, 2);
465  $item3 = new assAnswerCloze('Karl', 3.0, 1);
466  $item4 = new assAnswerCloze('Esther', 4.0, 3);
467 
468  $instance->addItem($item1);
469  $instance->addItem($item2);
470  $instance->addItem($item3);
471  $instance->addItem($item4);
472 
473  $expected = array( 0 => 3 );
474 
475  // Act
476  $actual = $instance->getBestSolutionIndexes();
477 
478  // Assert
479  $this->assertEquals($expected, $actual);
480  }
481 
483  {
484  // Arrange
485  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
486  $instance = new assClozeGap(0); // 0 - text gap
487  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
488  $item1 = new assAnswerCloze('Bert', 1.0, 0);
489  $item2 = new assAnswerCloze('Fred', 2.0, 2);
490  $item3 = new assAnswerCloze('Karl', 3.0, 1);
491  $item4 = new assAnswerCloze('Esther', 4.0, 3);
492 
493  // We need the $lng-mock.
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') );
497  global $lng;
498  $lng = $lng_mock;
499 
500  $instance->addItem($item1);
501  $instance->addItem($item2);
502  $instance->addItem($item3);
503  $instance->addItem($item4);
504 
505  $expected = 'Esther';
506 
507  // Act
508  $actual = $instance->getBestSolutionOutput();
509 
510  // Assert
511  $this->assertEquals($expected, $actual);
512  }
513 
515  {
516  // Arrange
517  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
518  $instance = new assClozeGap(0); // 0 - text gap
519  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
520  $item1 = new assAnswerCloze('Bert', 1.0, 0);
521  $item2 = new assAnswerCloze('Fred', 2.0, 2);
522  $item3 = new assAnswerCloze('Karl', 4, 1);
523  $item4 = new assAnswerCloze('Esther', 4, 3);
524 
525  // We need the $lng-mock.
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') );
529  global $lng;
530  $lng = $lng_mock;
531 
532  $instance->addItem($item1);
533  $instance->addItem($item2);
534  $instance->addItem($item3);
535  $instance->addItem($item4);
536 
537  $expected1 = 'Karl or Esther';
538  $expected2 = 'Esther or Karl';
539 
540  // Act
541  $actual = $instance->getBestSolutionOutput();
542 
543  // Assert
544  $this->assertTrue( ($actual == $expected1) || ($actual == $expected2) );
545  }
546 
548  {
549  // Arrange
550  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
551  $instance = new assClozeGap(2); // 0 - text gap
552  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
553  $item1 = new assAnswerCloze(10, 1.0, 0);
554  $item2 = new assAnswerCloze(20, 2.0, 2);
555  $item3 = new assAnswerCloze(30, 3.0, 1);
556  $item4 = new assAnswerCloze(100, 4.0, 3);
557 
558  // We need the $lng-mock.
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') );
562  global $lng;
563  $lng = $lng_mock;
564 
565  $instance->addItem($item1);
566  $instance->addItem($item2);
567  $instance->addItem($item3);
568  $instance->addItem($item4);
569 
570  $expected = 100;
571 
572  // Act
573  $actual = $instance->getBestSolutionOutput();
574 
575  // Assert
576  $this->assertEquals($expected, $actual);
577  }
578 
580  {
581  // Arrange
582  require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
583  $instance = new assClozeGap(11); // 0 - text gap
584  require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
585  $item1 = new assAnswerCloze(10, 1.0, 0);
586  $item2 = new assAnswerCloze(20, 2.0, 2);
587  $item3 = new assAnswerCloze(30, 3.0, 1);
588  $item4 = new assAnswerCloze(100, 4.0, 3);
589 
590  // We need the $lng-mock.
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') );
594  global $lng;
595  $lng = $lng_mock;
596 
597  $instance->addItem($item1);
598  $instance->addItem($item2);
599  $instance->addItem($item3);
600  $instance->addItem($item4);
601 
602  $expected = '';
603 
604  // Act
605  $actual = $instance->getBestSolutionOutput();
606 
607  // Assert
608  $this->assertEquals($expected, $actual);
609  }
610 }