ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilTestRandomQuestionSetQuestionCollectionTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
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  for ($count = 0; $count < 3; $count++) {
55  $this->testObj->addQuestion(new ilTestRandomQuestionSetQuestion());
56  }
57  $this->assertCount($count, $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 testKey(): 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  $iMax = count($ids);
88  if ($iMax > 0) {
89  $this->assertEquals(0, $this->testObj->key());
90 
91  for ($i = 1; $i < $iMax; $i++) {
92  $this->testObj->next();
93  }
94 
95  $this->assertEquals(--$i, $this->testObj->key());
96  } else {
97  $this->assertTrue(false);
98  }
99  }
100 
101  public function testValid(): void
102  {
103  $questions = [];
104  $ids = [125, 112, 10];
105  foreach ($ids as $id) {
106  $question = new ilTestRandomQuestionSetQuestion();
107  $question->setQuestionId($id);
108  $questions[] = $question;
109  }
110 
111  $this->testObj->setQuestions($questions);
112 
113  $this->assertTrue($this->testObj->valid());
114 
115  $this->testObj->setQuestions([]);
116  $this->assertFalse($this->testObj->valid());
117  }
118 
119  public function testRewind(): void
120  {
121  $questions = [];
122  $ids = [125, 112, 10];
123  foreach ($ids as $id) {
124  $question = new ilTestRandomQuestionSetQuestion();
125  $question->setQuestionId($id);
126  $questions[] = $question;
127  }
128 
129  $this->testObj->setQuestions($questions);
130 
131  $iMax = count($questions);
132  if ($iMax > 0) {
133  $this->assertEquals($questions[0], $this->testObj->current());
134 
135  for ($i = 1; $i < $iMax; $i++) {
136  $this->testObj->next();
137  }
138 
139  $this->assertEquals($questions[--$i], $this->testObj->current());
140 
141  for ($j = $i; $j > 0; $j--) {
142  $this->testObj->rewind();
143  }
144 
145  $this->assertEquals($questions[$j], $this->testObj->current());
146  } else {
147  $this->assertTrue(false);
148  }
149  }
150 
151  public function testIsGreaterThan(): void
152  {
153  $questions = [];
154  $ids = [125, 112, 10];
155  foreach ($ids as $id) {
156  $question = new ilTestRandomQuestionSetQuestion();
157  $question->setQuestionId($id);
158  $questions[] = $question;
159  }
160 
161  $this->testObj->setQuestions($questions);
162 
163  for ($i = 0, $iMax = count($questions); $i < $iMax; $i++) {
164  $this->assertTrue($this->testObj->isGreaterThan($i));
165  }
166  $this->assertFalse($this->testObj->isGreaterThan($i));
167  }
168 
169  public function testIsSmallerThan(): void
170  {
171  $questions = [];
172  $ids = [125, 112, 10];
173  foreach ($ids as $id) {
174  $question = new ilTestRandomQuestionSetQuestion();
175  $question->setQuestionId($id);
176  $questions[] = $question;
177  }
178 
179  $this->testObj->setQuestions($questions);
180 
181  for ($questionsCount = count($questions), $i = $questionsCount * 2; $i > $questionsCount; $i--) {
182  $this->assertTrue($this->testObj->isSmallerThan($i));
183  }
184  $this->assertFalse($this->testObj->isSmallerThan($i));
185  }
186 
187  public function testGetMissingCount(): void
188  {
189  $questions = [];
190  $ids = [125, 112, 10];
191  foreach ($ids as $id) {
192  $question = new ilTestRandomQuestionSetQuestion();
193  $question->setQuestionId($id);
194  $questions[] = $question;
195  }
196 
197  $this->testObj->setQuestions($questions);
198 
199  $questionsCount = count($questions);
200 
201  for ($i = 0, $iMax = $questionsCount; $i < $iMax; $i++) {
202  $this->assertEquals(0, $this->testObj->getMissingCount($i));
203  }
204 
205  for ($i = $questionsCount, $iMax = $questionsCount * 2; $i <= $iMax; $i++) {
206  $this->assertEquals($i - $questionsCount, $this->testObj->getMissingCount($i));
207  }
208  }
209 
210  public function testMergeQuestionCollection(): void
211  {
212  $questions = [];
213  $ids = [125, 112, 10];
214  foreach ($ids as $id) {
215  $question = new ilTestRandomQuestionSetQuestion();
216  $question->setQuestionId($id);
217  $questions[] = $question;
218  $this->testObj->addQuestion($question);
219  }
220 
221  $collection = new ilTestRandomQuestionSetQuestionCollection();
222 
223  $ids = [1, 5, 8];
224  foreach ($ids as $id) {
225  $question = new ilTestRandomQuestionSetQuestion();
226  $question->setQuestionId($id);
227  $questions[] = $question;
228  $collection->addQuestion($question);
229  }
230 
231  $this->testObj->mergeQuestionCollection($collection);
232 
233  $this->assertEquals($questions, $this->testObj->getQuestions());
234  }
235 
236  public function testGetUniqueQuestionCollection(): void
237  {
238  $ids = [125, 112, 10, 112];
239  foreach ($ids as $id) {
240  $question = new ilTestRandomQuestionSetQuestion();
241  $question->setQuestionId($id);
242  $this->testObj->addQuestion($question);
243  }
244 
245  $this->assertCount(count(array_unique($ids)), $this->testObj->getUniqueQuestionCollection()->getQuestions());
246  }
247 
248  public function testGetQuestionAmount(): void
249  {
250  $ids = [125, 112, 10];
251  foreach ($ids as $id) {
252  $question = new ilTestRandomQuestionSetQuestion();
253  $question->setQuestionId($id);
254  $this->testObj->addQuestion($question);
255  }
256 
257  $this->assertEquals(count($ids), $this->testObj->getQuestionAmount());
258  }
259 
260  public function testGetInvolvedQuestionIds(): void
261  {
262  $ids = [125, 112, 10];
263  foreach ($ids as $id) {
264  $question = new ilTestRandomQuestionSetQuestion();
265  $question->setQuestionId($id);
266  $this->testObj->addQuestion($question);
267  }
268 
269  $this->assertEquals($ids, $this->testObj->getInvolvedQuestionIds());
270  }
271 }
Class ilTestRandomQuestionSetQuestionCollectionTest.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23