ILIAS  release_8 Revision v8.25
assClozeSelectGapTest.php
Go to the documentation of this file.
1<?php
2
19
29{
30 protected $backupGlobals = false;
31
32 protected function setUp(): void
33 {
34 chdir(dirname(__FILE__));
35 chdir('../../../');
36 }
37
39 {
40 // Arrange
41 require_once './Modules/TestQuestionPool/classes/class.assClozeSelectGap.php';
42
43 // Act
44 $instance = new assClozeSelectGap(1); // 1 - select gap
45
46 $this->assertInstanceOf('assClozeSelectGap', $instance);
47 }
48
50 {
51 // Arrange
52 require_once './Modules/TestQuestionPool/classes/class.assClozeSelectGap.php';
53 $instance = new assClozeSelectGap(1); // 1 - select gap
54 $expected = true;
55
56 $actual = $instance->getShuffle();
57
58 $this->assertEquals($expected, $actual);
59 }
60
62 {
63 // Arrange
64 require_once './Modules/TestQuestionPool/classes/class.assClozeSelectGap.php';
65 $instance = new assClozeSelectGap(1); // 1 - select gap
66 $expected = ['shfksdfs', 'sfsdf', 'sdfsdfdf'];
67
68 $transformationMock = $this->getMockBuilder(Transformation::class)->getMock();
69 $transformationMock->expects(self::once())->method('transform')->willReturn($expected);
70 $actual = $instance->getItems($transformationMock);
71 $this->assertEquals($expected, $actual);
72 }
73
75 {
76 require_once './Modules/TestQuestionPool/classes/class.assClozeSelectGap.php';
77 $instance = new assClozeSelectGap(1); // 1 - select gap
78
79 require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
80 $item1 = new assAnswerCloze('Bert', 1.0, 0);
81 $item2 = new assAnswerCloze('Fred', 2.0, 2);
82 $item3 = new assAnswerCloze('Karl', 4, 1);
83 $item4 = new assAnswerCloze('Esther', 4, 3);
84 $item5 = new assAnswerCloze('Herbert', 1.0, 4);
85 $item6 = new assAnswerCloze('Karina', 1.0, 5);
86 $item7 = new assAnswerCloze('Helmut', 1.0, 6);
87 $item8 = new assAnswerCloze('Kerstin', 1.0, 7);
88
89 $instance->addItem($item1);
90 $instance->addItem($item2);
91 $instance->addItem($item3);
92 $instance->addItem($item4);
93 $instance->addItem($item5);
94 $instance->addItem($item6);
95 $instance->addItem($item7);
96 $instance->addItem($item8);
97
98 $instance->setType(true);
99
100 $sequence = [$item1, $item3, $item2, $item4, $item5, $item6, $item7, $item8];
101 $expectedSequence = array_reverse($sequence);
102
103 $randomElmProvider = $this->getMockBuilder(Transformation::class)->getMock();
104 $randomElmProvider->expects($this->once())
105 ->method('transform')
106 ->with($sequence)
107 ->willReturn($expectedSequence);
108
109 $actual = $instance->getItems($randomElmProvider);
110 $this->assertEquals($actual, $expectedSequence);
111 }
112
114 {
115 require_once './Modules/TestQuestionPool/classes/class.assClozeSelectGap.php';
116 $instance = new assClozeSelectGap(1); // 1 - select gap
117
118 require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
119 $item1 = new assAnswerCloze('Bert', 1.0, 0);
120 $item2 = new assAnswerCloze('Fred', 2.0, 1);
121 $item3 = new assAnswerCloze('Karl', 4, 2);
122 $item4 = new assAnswerCloze('Esther', 4, 3);
123
124 $instance->addItem($item1);
125 $instance->addItem($item2);
126 $instance->addItem($item3);
127 $instance->addItem($item4);
128
129 $instance->setType(false);
130
131 $expected = array($item1, $item2, $item3, $item4);
132 $transformationMock = $this->getMockBuilder(Transformation::class)->getMock();
133 $transformationMock->expects(self::once())->method('transform')->willReturnCallback(function ($value) {
134 return $value;
135 });
136 $actual = $instance->getItems($transformationMock);
137
138 $this->assertEquals($expected, $actual);
139 }
140}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class assBaseTestCase.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A transformation is a function from one datatype to another.