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