ILIAS  trunk Revision v11.0_alpha-1731-gff9cd7e2bd3
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilIndividualAssessmentMembersTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
25 {
26  public function buildNewRecordOfUserWrapper(ilObjUser $user): array
27  {
28  return $this->buildNewRecordOfUser($user);
29  }
30 
31  public function initMemberRecords(array $arr): void
32  {
33  $this->member_records = $arr;
34  }
35 
36  public function getMemberRecords(): array
37  {
38  return $this->member_records;
39  }
40 
41  protected function userExists(int $usr_id): bool
42  {
43  if ($usr_id === 22) {
44  return false;
45  }
46  return true;
47  }
48 }
49 
51 {
55  private $iass;
56 
57  protected function setUp(): void
58  {
59  $this->iass = $this->createMock(ilObjIndividualAssessment::class);
60  }
61 
62  public function test_createObject(): void
63  {
64  $obj = new ilIndividualAssessmentMembers($this->iass);
65  $this->assertInstanceOf(ilIndividualAssessmentMembers::class, $obj);
66  }
67 
68  public function test_count(): void
69  {
70  $obj = new TestObj($this->iass);
71  $obj->initMemberRecords([1,2,3,4,5]);
72  $this->assertEquals(5, $obj->count());
73  }
74 
75  public function test_current(): void
76  {
77  $obj = new TestObj($this->iass);
78  $obj->initMemberRecords([1,2,3,4,5]);
79  $this->assertEquals(1, $obj->current());
80  $obj->initMemberRecords([21,324,53,54,55]);
81  $this->assertEquals(21, $obj->current());
82  $obj->next();
83  $this->assertEquals(324, $obj->current());
84  }
85 
86  public function test_current_false(): void
87  {
88  $obj = new TestObj($this->iass);
89  $obj->initMemberRecords([1]);
90  $obj->next();
91  $this->assertFalse($obj->current());
92  }
93 
94  public function test_key(): void
95  {
96  $obj = new TestObj($this->iass);
97  $obj->initMemberRecords([1,2,3,4]);
98  $this->assertEquals(0, $obj->key());
99  $obj->next();
100  $this->assertEquals(1, $obj->key());
101  }
102 
103  public function test_key_null(): void
104  {
105  $obj = new TestObj($this->iass);
106  $obj->initMemberRecords([]);
107  $this->assertNull($obj->key());
108  }
109 
110  public function test_key_string(): void
111  {
112  $obj = new TestObj($this->iass);
113  $obj->initMemberRecords(["test" => "foo", "bar" => "boo"]);
114  $this->assertEquals("test", $obj->key());
115  $obj->next();
116  $this->assertEquals("bar", $obj->key());
117  }
118 
119  public function test_next(): void
120  {
121  $obj = new TestObj($this->iass);
122  $obj->initMemberRecords([1,2,3,4,5]);
123  $obj->next();
124  $obj->next();
125  $obj->next();
126  $this->assertEquals(4, $obj->current());
127  }
128 
129  public function test_rewind(): void
130  {
131  $obj = new TestObj($this->iass);
132  $obj->initMemberRecords([1,2,3,4,5]);
133  $obj->next();
134  $obj->next();
135  $obj->next();
136  $this->assertEquals(4, $obj->current());
137  $obj->rewind();
138  $this->assertEquals(1, $obj->current());
139  }
140 
141  public function test_valid(): void
142  {
143  $obj = new TestObj($this->iass);
144  $obj->initMemberRecords([1,2,3,4,5]);
145  $this->assertTrue($obj->valid());
146  }
147 
148  public function test_valid_false(): void
149  {
150  $obj = new TestObj($this->iass);
151  $obj->initMemberRecords([1]);
152  $this->assertTrue($obj->valid());
153  $obj->next();
154  $this->assertFalse($obj->valid());
155  }
156 
157  public function test_recordOK_with_non_existing_user(): void
158  {
159  $usr = $this->createMock(ilObjUser::class);
160  $usr
161  ->expects($this->once())
162  ->method("getId")
163  ->willReturn(22)
164  ;
165  $usr
166  ->expects($this->once())
167  ->method("getFirstname")
168  ->willReturn("Firstname")
169  ;
170  $usr
171  ->expects($this->once())
172  ->method("getLastname")
173  ->willReturn("Lastname")
174  ;
175  $usr
176  ->expects($this->once())
177  ->method("getLogin")
178  ->willReturn("Firstname Lastname")
179  ;
180 
181  $obj = new TestObj($this->iass);
182  $record = $obj->buildNewRecordOfUserWrapper($usr);
183 
184  $this->assertFalse($obj->recordOK($record));
185  }
186 
188  {
189  $usr = $this->getRecordOKUserMock();
190 
191  $obj = new TestObj($this->iass);
192 
193  $obj->initMemberRecords([23 => "already_member"]);
194  $record = $obj->buildNewRecordOfUserWrapper($usr);
195 
196  $this->assertFalse($obj->recordOK($record));
197  }
198 
199  public function test_recordOK_with_wrong_lp_status(): void
200  {
201  $usr = $this->getRecordOKUserMock();
202 
203  $obj = new TestObj($this->iass);
204 
205  $record = $obj->buildNewRecordOfUserWrapper($usr);
207 
208  $this->assertFalse($obj->recordOK($record));
209  }
210 
211  public function test_recordOK(): void
212  {
213  $usr = $this->getRecordOKUserMock();
214 
215  $obj = new TestObj($this->iass);
216 
217  $record = $obj->buildNewRecordOfUserWrapper($usr);
218 
219  $this->assertTrue($obj->recordOK($record));
220  }
221 
225  public function getRecordOKUserMock()
226  {
227  $usr = $this->createMock(ilObjUser::class);
228  $usr
229  ->expects($this->once())
230  ->method("getId")
231  ->willReturn(23)
232  ;
233  $usr
234  ->expects($this->once())
235  ->method("getFirstname")
236  ->willReturn("Firstname")
237  ;
238  $usr
239  ->expects($this->once())
240  ->method("getLastname")
241  ->willReturn("Lastname")
242  ;
243  $usr
244  ->expects($this->once())
245  ->method("getLogin")
246  ->willReturn("Firstname Lastname")
247  ;
248 
249  return $usr;
250  }
251 
252  public function test_userAllreadyMemberByUsrId(): void
253  {
254  $obj = new TestObj($this->iass);
255  $obj->initMemberRecords([22 => "is_set"]);
256  $this->assertTrue($obj->userAllreadyMemberByUsrId(22));
257  }
258 
259  public function test_userAllreadyMemberByUsrId_false(): void
260  {
261  $obj = new TestObj($this->iass);
262  $obj->initMemberRecords([23 => "is_set"]);
263  $this->assertFalse($obj->userAllreadyMemberByUsrId(22));
264  }
265 
266  public function test_userAllreadyMember(): void
267  {
268  $usr = $this->createMock(ilObjUser::class);
269  $usr
270  ->expects($this->once())
271  ->method("getId")
272  ->willReturn(22)
273  ;
274 
275  $obj = new TestObj($this->iass);
276  $obj->initMemberRecords([22 => "is_set"]);
277  $this->assertTrue($obj->userAllreadyMember($usr));
278  }
279 
280  public function test_userAllreadyMember_false(): void
281  {
282  $usr = $this->createMock(ilObjUser::class);
283  $usr
284  ->expects($this->once())
285  ->method("getId")
286  ->willReturn(22)
287  ;
288 
289  $obj = new TestObj($this->iass);
290  $obj->initMemberRecords([23 => "is_set"]);
291  $this->assertFalse($obj->userAllreadyMember($usr));
292  }
293 
294  public function test_withAdditionalRecord(): void
295  {
296  $usr = $this->getRecordOKUserMock();
297 
298  $obj = new TestObj($this->iass);
299 
300  $record = $obj->buildNewRecordOfUserWrapper($usr);
301  $new_obj = $obj->withAdditionalRecord($record);
302 
303  $records = $obj->getMemberRecords();
304  $this->assertEmpty($records);
305 
306  $records = $new_obj->getMemberRecords();
307  $record = $records[23];
308 
309  $this->assertEquals(23, $record[ilIndividualAssessmentMembers::FIELD_USR_ID]);
310  $this->assertEquals("", $record[ilIndividualAssessmentMembers::FIELD_RECORD]);
311  $this->assertEquals(0, $record[ilIndividualAssessmentMembers::FIELD_NOTIFY]);
312  $this->assertEquals("Firstname", $record[ilIndividualAssessmentMembers::FIELD_FIRSTNAME]);
313  $this->assertEquals("Lastname", $record[ilIndividualAssessmentMembers::FIELD_LASTNAME]);
314  $this->assertEquals("Firstname Lastname", $record[ilIndividualAssessmentMembers::FIELD_LOGIN]);
315  $this->assertEquals(0, $record[ilIndividualAssessmentMembers::FIELD_LEARNING_PROGRESS]);
316  $this->assertNull($record[ilIndividualAssessmentMembers::FIELD_EXAMINER_ID]);
318  $this->assertNull($record[ilIndividualAssessmentMembers::FIELD_EXAMINER_LASTNAME]);
319  $this->assertNull($record[ilIndividualAssessmentMembers::FIELD_INTERNAL_NOTE]);
320  $this->assertNull($record[ilIndividualAssessmentMembers::FIELD_FILE_NAME]);
321  $this->assertFalse($record[ilIndividualAssessmentMembers::FIELD_USER_VIEW_FILE]);
322  $this->assertEquals(0, $record[ilIndividualAssessmentMembers::FIELD_FINALIZED]);
323  $this->assertNull($record[ilIndividualAssessmentMembers::FIELD_CHANGER_ID]);
324  $this->assertNull($record[ilIndividualAssessmentMembers::FIELD_CHANGER_FIRSTNAME]);
325  $this->assertNull($record[ilIndividualAssessmentMembers::FIELD_CHANGER_LASTNAME]);
326  }
327 
328  public function test_withAdditionalRecord_exceptio(): void
329  {
330  $obj = new TestObj($this->iass);
331 
332  $this->expectException(ilIndividualAssessmentException::class);
333  $this->expectExceptionMessage("Ill defined record.");
334  $obj->withAdditionalRecord([ilIndividualAssessmentMembers::FIELD_USR_ID => 22]);
335  }
336 
337  public function test_withAdditionalUser(): void
338  {
339  $usr = $this->createMock(ilObjUser::class);
340  $usr
341  ->expects($this->any())
342  ->method("getId")
343  ->willReturn(23)
344  ;
345  $usr
346  ->expects($this->once())
347  ->method("getFirstname")
348  ->willReturn("Firstname")
349  ;
350  $usr
351  ->expects($this->once())
352  ->method("getLastname")
353  ->willReturn("Lastname")
354  ;
355  $usr
356  ->expects($this->once())
357  ->method("getLogin")
358  ->willReturn("Firstname Lastname")
359  ;
360 
361  $obj = new TestObj($this->iass);
362 
363  $new_obj = $obj->withAdditionalUser($usr);
364  $record = $obj->getMemberRecords();
365  $this->assertFalse(isset($record[23]));
366 
367 
368  $record = $new_obj->getMemberRecords();
369  $this->assertTrue(isset($record[23]));
370  }
371 
372  public function test_withAdditionalUser_exception(): void
373  {
374  $usr = $this->createMock(ilObjUser::class);
375  $usr
376  ->expects($this->any())
377  ->method("getId")
378  ->willReturn(23)
379  ;
380 
381  $obj = new TestObj($this->iass);
382  $obj->initMemberRecords([23 => "test"]);
383 
384  $this->expectException(ilIndividualAssessmentException::class);
385  $this->expectExceptionMessage("User allready member");
386  $obj->withAdditionalUser($usr);
387  }
388 
389  public function test_withoutPresentUser(): void
390  {
391  $usr = $this->createMock(ilObjUser::class);
392  $usr
393  ->expects($this->any())
394  ->method("getId")
395  ->willReturn(23)
396  ;
397 
398  $obj = new TestObj($this->iass);
399  $obj->initMemberRecords([23 => [ilIndividualAssessmentMembers::FIELD_FINALIZED => "0"]]);
400 
401  $new_obj = $obj->withoutPresentUser($usr);
402  $record = $obj->getMemberRecords();
403  $this->assertTrue(isset($record[23]));
404 
405  $record = $new_obj->getMemberRecords();
406  $this->assertFalse(isset($record[23]));
407  }
408 
410  {
411  $usr = $this->createMock(ilObjUser::class);
412  $usr
413  ->expects($this->any())
414  ->method("getId")
415  ->willReturn(23)
416  ;
417 
418  $obj = new TestObj($this->iass);
419 
420  $this->expectException(ilIndividualAssessmentException::class);
421  $this->expectExceptionMessage("User not member or allready finished");
422  $obj->withoutPresentUser($usr);
423  }
424 
426  {
427  $usr = $this->createMock(ilObjUser::class);
428  $usr
429  ->expects($this->any())
430  ->method("getId")
431  ->willReturn(23)
432  ;
433 
434  $obj = new TestObj($this->iass);
435  $obj->initMemberRecords([23 => [ilIndividualAssessmentMembers::FIELD_FINALIZED => "1"]]);
436 
437  $this->expectException(ilIndividualAssessmentException::class);
438  $this->expectExceptionMessage("User not member or allready finished");
439  $obj->withoutPresentUser($usr);
440  }
441 
442  public function test_withOnlyUsersByIds(): void
443  {
444  $keep_usr_ids = [18, 22];
445 
446  $obj = new TestObj($this->iass);
447  $obj->initMemberRecords([
448  23 => "user",
449  44 => "user",
450  365 => "user",
451  18 => "user",
452  45 => "user",
453  22 => "user",
454  16 => "user"
455  ]);
456 
457  $new_obj = $obj->withOnlyUsersByIds($keep_usr_ids);
458  $this->assertEmpty(array_diff([23, 44, 365, 18, 44, 22, 16], array_keys($obj->getMemberRecords())));
459 
460  $this->assertEmpty(array_diff([18, 22], array_keys($new_obj->getMemberRecords())));
461  }
462 }
buildNewRecordOfUserWrapper(ilObjUser $user)
Member administration related logic, add and remove members, get the list of all members, etc ...