ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilTestRandomQuestionSetQuestionCollectionTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
26 {
28 
29  protected function setUp(): void
30  {
31  parent::setUp();
32 
33  $this->testObj = new ilTestRandomQuestionSetQuestionCollection();
34  }
35 
37  {
38  $this->assertInstanceOf(ilTestRandomQuestionSetQuestionCollection::class, $this->testObj);
39  }
40 
41  public function testQuestions(): void
42  {
43  $expected = [
46  ];
47 
48  $this->testObj->setQuestions($expected);
49  $this->assertEquals($expected, $this->testObj->getQuestions());
50  }
51 
52  public function testAddQuestions(): void
53  {
54  $this->testObj->addQuestion(new ilTestRandomQuestionSetQuestion());
55  $this->testObj->addQuestion(new ilTestRandomQuestionSetQuestion());
56  $this->testObj->addQuestion(new ilTestRandomQuestionSetQuestion());
57  $this->assertCount(3, $this->testObj->getQuestions());
58  }
59 
60  public function testCurrent(): void
61  {
62  $questions = [];
63  $ids = [125, 112, 10];
64  foreach ($ids as $id) {
65  $question = new ilTestRandomQuestionSetQuestion();
66  $question->setQuestionId($id);
67  $questions[] = $question;
68  }
69 
70  $this->testObj->setQuestions($questions);
71 
72  $this->assertEquals($questions[0], $this->testObj->current());
73  }
74 
75  public function testNext(): void
76  {
77  $questions = [];
78  $ids = [125, 112, 10];
79  foreach ($ids as $id) {
80  $question = new ilTestRandomQuestionSetQuestion();
81  $question->setQuestionId($id);
82  $questions[] = $question;
83  }
84 
85  $this->testObj->setQuestions($questions);
86 
87  $this->assertEquals($questions[1], $this->testObj->next());
88  }
89 
90  public function testKey(): void
91  {
92  $questions = [];
93  $ids = [125, 112, 10];
94  foreach ($ids as $id) {
95  $question = new ilTestRandomQuestionSetQuestion();
96  $question->setQuestionId($id);
97  $questions[] = $question;
98  }
99 
100  $this->testObj->setQuestions($questions);
101 
102  $this->assertEquals(0, $this->testObj->key());
103 
104  $this->testObj->next();
105  $this->testObj->next();
106  $this->assertEquals(2, $this->testObj->key());
107  }
108 
109  public function testValid(): void
110  {
111  $questions = [];
112  $ids = [125, 112, 10];
113  foreach ($ids as $id) {
114  $question = new ilTestRandomQuestionSetQuestion();
115  $question->setQuestionId($id);
116  $questions[] = $question;
117  }
118 
119  $this->testObj->setQuestions($questions);
120 
121  $this->assertTrue($this->testObj->valid());
122 
123  $this->testObj->setQuestions([]);
124  $this->assertFalse($this->testObj->valid());
125  }
126 
127  public function testRewind(): void
128  {
129  $questions = [];
130  $ids = [125, 112, 10];
131  foreach ($ids as $id) {
132  $question = new ilTestRandomQuestionSetQuestion();
133  $question->setQuestionId($id);
134  $questions[] = $question;
135  }
136 
137  $this->testObj->setQuestions($questions);
138 
139  $this->assertEquals($questions[0], $this->testObj->current());
140 
141  $this->testObj->next();
142  $this->testObj->next();
143  $this->assertEquals($questions[2], $this->testObj->current());
144 
145  $this->testObj->rewind();
146  $this->assertEquals($questions[0], $this->testObj->current());
147  }
148 
149  public function testIsGreaterThan(): void
150  {
151  $questions = [];
152  $ids = [125, 112, 10];
153  foreach ($ids as $id) {
154  $question = new ilTestRandomQuestionSetQuestion();
155  $question->setQuestionId($id);
156  $questions[] = $question;
157  }
158 
159  $this->testObj->setQuestions($questions);
160 
161  $this->assertTrue($this->testObj->isGreaterThan(2));
162  $this->assertTrue($this->testObj->isGreaterThan(1));
163  $this->assertFalse($this->testObj->isGreaterThan(6));
164  }
165 
166  public function testIsSmallerThan(): void
167  {
168  $questions = [];
169  $ids = [125, 112, 10];
170  foreach ($ids as $id) {
171  $question = new ilTestRandomQuestionSetQuestion();
172  $question->setQuestionId($id);
173  $questions[] = $question;
174  }
175 
176  $this->testObj->setQuestions($questions);
177 
178  $this->assertFalse($this->testObj->isSmallerThan(3));
179  $this->assertFalse($this->testObj->isSmallerThan(1));
180  $this->assertTrue($this->testObj->isSmallerThan(6));
181  }
182 
183  public function testGetMissingCount(): void
184  {
185  $questions = [];
186  $ids = [125, 112, 10];
187  foreach ($ids as $id) {
188  $question = new ilTestRandomQuestionSetQuestion();
189  $question->setQuestionId($id);
190  $questions[] = $question;
191  }
192 
193  $this->testObj->setQuestions($questions);
194 
195  $this->assertEquals(0, $this->testObj->getMissingCount(3));
196  $this->assertEquals(0, $this->testObj->getMissingCount(1));
197  $this->assertEquals(3, $this->testObj->getMissingCount(6));
198  }
199 
200  public function testMergeQuestionCollection(): void
201  {
202  $questions = [];
203  $ids = [125, 112, 10];
204  foreach ($ids as $index => $id) {
205  $question = new ilTestRandomQuestionSetQuestion();
206  $question->setQuestionId($id);
207  $questions[$index] = $question;
208  $this->testObj->addQuestion($question);
209  }
210 
211  $collection = new ilTestRandomQuestionSetQuestionCollection();
212 
213  $ids = [1, 5, 8];
214  foreach ($ids as $index => $id) {
215  $question = new ilTestRandomQuestionSetQuestion();
216  $question->setQuestionId($id);
217  $questions[$index + 3] = $question;
218  $collection->addQuestion($question);
219  }
220 
221  $this->testObj->mergeQuestionCollection($collection);
222 
223  $this->assertEquals($questions, $this->testObj->getQuestions());
224  }
225 
226  public function testGetUniqueQuestionCollection(): void
227  {
228  $ids = [125, 112, 10, 112];
229  foreach ($ids as $id) {
230  $question = new ilTestRandomQuestionSetQuestion();
231  $question->setQuestionId($id);
232  $this->testObj->addQuestion($question);
233  }
234 
235  $this->assertCount(3, $this->testObj->getUniqueQuestionCollection()->getQuestions());
236  }
237 
238  public function testGetQuestionAmount(): void
239  {
240  $ids = [125, 112, 10];
241  foreach ($ids as $id) {
242  $question = new ilTestRandomQuestionSetQuestion();
243  $question->setQuestionId($id);
244  $this->testObj->addQuestion($question);
245  }
246 
247  $this->assertEquals(3, $this->testObj->getQuestionAmount());
248  }
249 
250  public function testGetInvolvedQuestionIds(): void
251  {
252  $ids = [125, 112, 10];
253  foreach ($ids as $id) {
254  $question = new ilTestRandomQuestionSetQuestion();
255  $question->setQuestionId($id);
256  $this->testObj->addQuestion($question);
257  }
258 
259  $this->assertEquals($ids, $this->testObj->getInvolvedQuestionIds());
260  }
261 }
$index
Definition: metadata.php:145
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilTestBaseClass.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23