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