ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilTestParticipantListTest.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 ilTestParticipantList($this->createMock(ilObjTest::class));
34  }
35 
37  {
38  $this->assertInstanceOf(ilTestParticipantList::class, $this->testObj);
39  }
40 
41  public function testTestObj(): void
42  {
43  $objTest_mock = $this->createMock(ilObjTest::class);
44  $this->testObj->setTestObj($objTest_mock);
45  $this->assertEquals($objTest_mock, $this->testObj->getTestObj());
46  }
47 
48  public function testAddParticipant(): void
49  {
50  $participant = new ilTestParticipant();
51  $participant->setActiveId(22);
52  $this->testObj->addParticipant($participant);
53  $this->assertEquals($participant, $this->testObj->getParticipantByActiveId(22));
54  }
55 
56  public function testGetParticipantByUsrId(): void
57  {
58  $participant = new ilTestParticipant();
59  $participant->setUsrId(125);
60  $this->testObj->addParticipant($participant);
61  $this->assertEquals($participant, $this->testObj->getParticipantByUsrId(125));
62  }
63 
64  public function testHasUnfinishedPasses(): void
65  {
66  $participant = new ilTestParticipant();
67  $participant->setUnfinishedPasses(false);
68  $this->testObj->addParticipant($participant);
69 
70  $this->assertFalse($this->testObj->hasUnfinishedPasses());
71 
72  $participant = new ilTestParticipant();
73  $participant->setUnfinishedPasses(true);
74  $this->testObj->addParticipant($participant);
75 
76  $this->assertTrue($this->testObj->hasUnfinishedPasses());
77  }
78 
79  public function testGetAllUserIds(): void
80  {
81  $ids = [
82  12,
83  125,
84  176,
85  12111,
86  1
87  ];
88 
89  foreach ($ids as $id) {
90  $participant = new ilTestParticipant();
91  $participant->setUsrId($id);
92  $this->testObj->addParticipant($participant);
93  }
94  $this->assertEquals($ids, $this->testObj->getAllUserIds());
95  }
96 
97  public function testGetAllActiveIds(): void
98  {
99  $ids = [
100  12,
101  125,
102  176,
103  12111,
104  1
105  ];
106 
107  foreach ($ids as $id) {
108  $participant = new ilTestParticipant();
109  $participant->setActiveId($id);
110  $this->testObj->addParticipant($participant);
111  }
112  $this->assertEquals($ids, $this->testObj->getAllActiveIds());
113  }
114 
115  public function testIsActiveIdInList(): void
116  {
117  $ids = [
118  12,
119  125,
120  176,
121  12111,
122  1
123  ];
124 
125  foreach ($ids as $id) {
126  $participant = new ilTestParticipant();
127  $participant->setActiveId($id);
128  $this->testObj->addParticipant($participant);
129  }
130  $this->assertTrue($this->testObj->isActiveIdInList(12));
131  $this->assertFalse($this->testObj->isActiveIdInList(222222));
132  }
133 
134  public function testGetAccessFilteredList(): void
135  {
136  $ids = [
137  12,
138  125,
139  176,
140  12111,
141  1
142  ];
143 
144  $expected = [
145  12,
146  125,
147  176,
148  ];
149 
150  foreach ($ids as $id) {
151  $participant = new ilTestParticipant();
152  $participant->setUsrId($id);
153  $this->testObj->addParticipant($participant);
154  }
155 
156  $callback = static function ($userIds) use ($expected) {
157  return $expected;
158  };
159 
160  $result = $this->testObj->getAccessFilteredList($callback);
161 
162  $this->assertNotNull($result->getParticipantByUsrId(12));
163  $this->assertNotNull($result->getParticipantByUsrId(125));
164  $this->assertNotNull($result->getParticipantByUsrId(176));
165  $this->assertNull($result->getParticipantByUsrId(212121));
166  }
167 
168  public function testCurrent(): void
169  {
170  $ids = [
171  12,
172  125,
173  176,
174  ];
175 
176  foreach ($ids as $id) {
177  $participant = new ilTestParticipant();
178  $participant->setUsrId($id);
179  $this->testObj->addParticipant($participant);
180  }
181 
182  $this->assertEquals($ids[0], $this->testObj->current()->getUsrId());
183 
184  $this->testObj->next();
185  $this->assertEquals($ids[1], $this->testObj->current()->getUsrId());
186  }
187 
188  public function testNext(): void
189  {
190  $ids = [
191  12,
192  125,
193  176,
194  ];
195 
196  foreach ($ids as $id) {
197  $participant = new ilTestParticipant();
198  $participant->setUsrId($id);
199  $this->testObj->addParticipant($participant);
200  }
201 
202  $this->testObj->next();
203  $this->testObj->next();
204 
205  $this->assertEquals($ids[2], $this->testObj->current()->getUsrId());
206  }
207 
208  public function testKey(): void
209  {
210  $ids = [
211  12,
212  125,
213  176,
214  ];
215 
216  foreach ($ids as $id) {
217  $participant = new ilTestParticipant();
218  $participant->setUsrId($id);
219  $this->testObj->addParticipant($participant);
220  }
221 
222  $this->testObj->next();
223  $this->testObj->next();
224 
225  $this->assertEquals(2, $this->testObj->key());
226  }
227 
228  public function testValid(): void
229  {
230  $ids = [
231  12,
232  125,
233  176,
234  ];
235 
236  foreach ($ids as $id) {
237  $participant = new ilTestParticipant();
238  $participant->setUsrId($id);
239  $this->testObj->addParticipant($participant);
240  }
241 
242  $this->testObj->next();
243  $this->testObj->next();
244  $this->assertTrue($this->testObj->valid());
245 
246  $this->testObj->next();
247  $this->assertFalse($this->testObj->valid());
248  }
249 
250  public function testRewind(): void
251  {
252  $ids = [
253  12,
254  125,
255  176,
256  ];
257 
258  foreach ($ids as $id) {
259  $participant = new ilTestParticipant();
260  $participant->setUsrId($id);
261  $this->testObj->addParticipant($participant);
262  }
263 
264  $this->testObj->next();
265  $this->testObj->next();
266  $this->assertEquals($ids[2], $this->testObj->current()->getUsrId());
267 
268  $this->testObj->rewind();
269  $this->assertEquals($ids[0], $this->testObj->current()->getUsrId());
270  }
271 }
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