ILIAS  release_8 Revision v8.24
ilIndividualAssessmentMemberTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21use PHPUnit\Framework\TestCase;
22use PHPUnit\Framework\MockObject\MockObject;
23
25{
29 private $iass_object;
33 private $grading;
37 private $obj_user;
38
39 protected function setUp(): void
40 {
41 $this->iass_object = $this->createMock(ilObjIndividualAssessment::class);
42 $this->grading = $this->createMock(ilIndividualAssessmentUserGrading::class);
43 $this->obj_user = $this->createMock(ilObjUser::class);
44 }
45
46 public function test_createObject(): void
47 {
49 $this->iass_object,
50 $this->obj_user,
51 $this->grading,
52 22222
53 );
54
55 $this->assertInstanceOf(ilIndividualAssessmentMember::class, $obj);
56 }
57
58 public function test_getRecord(): void
59 {
60 $this->grading
61 ->expects($this->once())
62 ->method("getRecord")
63 ->willReturn("testRecord")
64 ;
65
67 $this->iass_object,
68 $this->obj_user,
69 $this->grading,
70 22222
71 );
72
73 $this->assertEquals("testRecord", $obj->record());
74 }
75
76 public function test_internalNote(): void
77 {
78 $this->grading
79 ->expects($this->once())
80 ->method("getInternalNote")
81 ->willReturn("internalNote")
82 ;
83
85 $this->iass_object,
86 $this->obj_user,
87 $this->grading,
88 22222
89 );
90
91 $this->assertEquals("internalNote", $obj->internalNote());
92 }
93
94 public function test_examinerId_not_set(): void
95 {
97 $this->iass_object,
98 $this->obj_user,
99 $this->grading,
100 22222
101 );
102
103 $this->assertNull($obj->examinerId());
104 }
105
106 public function test_examinerId(): void
107 {
109 $this->iass_object,
110 $this->obj_user,
111 $this->grading,
112 22222,
113 3434
114 );
115
116 $this->assertEquals(3434, $obj->examinerId());
117 }
118
119 public function test_changerId_not_set(): void
120 {
122 $this->iass_object,
123 $this->obj_user,
124 $this->grading,
125 22222
126 );
127
128 $this->assertNull($obj->changerId());
129 }
130
131 public function test_changerId(): void
132 {
134 $this->iass_object,
135 $this->obj_user,
136 $this->grading,
137 22222,
138 0,
139 5656
140 );
141
142 $this->assertEquals(5656, $obj->changerId());
143 }
144
145 public function test_changeTime_not_set(): void
146 {
148 $this->iass_object,
149 $this->obj_user,
150 $this->grading,
151 22222
152 );
153
154 $this->assertNull($obj->changeTime());
155 }
156
157 public function test_changeTime(): void
158 {
160 $this->iass_object,
161 $this->obj_user,
162 $this->grading,
163 22222,
164 0,
165 0,
166 new DateTimeImmutable('2021-11-25')
167 );
168
169 $this->assertEquals('2021-11-25', $obj->changeTime()->format('Y-m-d'));
170 }
171
172 public function test_notify(): void
173 {
174 $this->grading
175 ->expects($this->once())
176 ->method("isNotify")
177 ->willReturn(true)
178 ;
179
181 $this->iass_object,
182 $this->obj_user,
183 $this->grading,
184 22222
185 );
186
187 $this->assertTrue($obj->notify());
188 }
189
191 {
192 $notificator = $this->createMock(ilIndividualAssessmentNotificator::class);
193
194 $this->grading
195 ->expects($this->once())
196 ->method("isFinalized")
197 ->willReturn(false)
198 ;
199
201 $this->iass_object,
202 $this->obj_user,
203 $this->grading,
204 22222
205 );
206
207 $this->expectException(ilIndividualAssessmentException::class);
208 $this->expectExceptionMessage('must finalize before notification');
209 $obj->maybeSendNotification($notificator);
210 }
211
213 {
214 $notificator = $this->createMock(ilIndividualAssessmentNotificator::class);
215
216 $this->grading
217 ->expects($this->once())
218 ->method("isFinalized")
219 ->willReturn(true)
220 ;
221 $this->grading
222 ->expects($this->once())
223 ->method("isNotify")
224 ->willReturn(false)
225 ;
226
228 $this->iass_object,
229 $this->obj_user,
230 $this->grading,
231 22222
232 );
233
234 $this->assertEquals($obj, $obj->maybeSendNotification($notificator));
235 }
236
237 public function test_id(): void
238 {
239 $this->obj_user
240 ->expects($this->once())
241 ->method("getId")
242 ->willReturn(22)
243 ;
244
246 $this->iass_object,
247 $this->obj_user,
248 $this->grading,
249 22222
250 );
251
252 $this->assertEquals(22, $obj->id());
253 }
254
255 public function test_assessmentId(): void
256 {
257 $this->iass_object
258 ->expects($this->once())
259 ->method("getId")
260 ->willReturn(22)
261 ;
262
264 $this->iass_object,
265 $this->obj_user,
266 $this->grading,
267 22222
268 );
269
270 $this->assertEquals(22, $obj->assessmentId());
271 }
272
273 public function test_assessment(): void
274 {
276 $this->iass_object,
277 $this->obj_user,
278 $this->grading,
279 22222
280 );
281
282 $this->assertEquals($this->iass_object, $obj->assessment());
283 }
284
285 public function test_finalized(): void
286 {
287 $this->grading
288 ->expects($this->once())
289 ->method("isFinalized")
290 ->willReturn(true)
291 ;
292
294 $this->iass_object,
295 $this->obj_user,
296 $this->grading,
297 22222
298 );
299
300 $this->assertTrue($obj->finalized());
301 }
302
303 public function fileNamesDataProvider(): array
304 {
305 return [
306 [''],
307 [null]
308 ];
309 }
310
315 {
316 $settings = $this->createMock(ilIndividualAssessmentSettings::class);
318 ->expects($this->once())
319 ->method("isFileRequired")
320 ->willReturn(true)
321 ;
322
323 $this->iass_object
324 ->expects($this->once())
325 ->method("getSettings")
326 ->willReturn($settings)
327 ;
328
329 $this->grading
330 ->expects($this->once())
331 ->method("getFile")
332 ->willReturn($filename)
333 ;
334
336 $this->iass_object,
337 $this->obj_user,
338 $this->grading,
339 22222
340 );
341
342 $this->assertFalse($obj->mayBeFinalized());
343 }
344
345 public function positiveLPStatusDataProvider(): array
346 {
347 return [
350 ];
351 }
352
356 public function test_mayBeFinalized_with_positive_lp_status(int $lp_status): void
357 {
358 $settings = $this->createMock(ilIndividualAssessmentSettings::class);
360 ->expects($this->once())
361 ->method("isFileRequired")
362 ->willReturn(false)
363 ;
364
365 $this->iass_object
366 ->expects($this->once())
367 ->method("getSettings")
368 ->willReturn($settings)
369 ;
370
371 $this->grading
372 ->expects($this->once())
373 ->method("getLearningProgress")
374 ->willReturn($lp_status)
375 ;
376 $this->grading
377 ->expects($this->once())
378 ->method("isFinalized")
379 ->willReturn(false)
380 ;
381
383 $this->iass_object,
384 $this->obj_user,
385 $this->grading,
386 22222
387 );
388
389 $this->assertTrue($obj->mayBeFinalized());
390 }
391
393 {
394 $settings = $this->createMock(ilIndividualAssessmentSettings::class);
396 ->expects($this->once())
397 ->method("isFileRequired")
398 ->willReturn(false)
399 ;
400
401 $this->iass_object
402 ->expects($this->once())
403 ->method("getSettings")
404 ->willReturn($settings)
405 ;
406
407 $this->grading
408 ->expects($this->once())
409 ->method("getLearningProgress")
411 ;
412 $this->grading
413 ->expects($this->once())
414 ->method("isFinalized")
415 ->willReturn(true)
416 ;
417
419 $this->iass_object,
420 $this->obj_user,
421 $this->grading,
422 22222
423 );
424
425 $this->assertFalse($obj->mayBeFinalized());
426 }
427
428 public function negativeLPStatusDataProvider(): array
429 {
430 return [
433 ];
434 }
435
439 public function test_mayBeFinalized_with_negative_lp_status(int $lp_status): void
440 {
441 $settings = $this->createMock(ilIndividualAssessmentSettings::class);
443 ->expects($this->once())
444 ->method("isFileRequired")
445 ->willReturn(false)
446 ;
447
448 $this->iass_object
449 ->expects($this->once())
450 ->method("getSettings")
451 ->willReturn($settings)
452 ;
453
454 $this->grading
455 ->expects($this->once())
456 ->method("getLearningProgress")
457 ->willReturn($lp_status)
458 ;
459
461 $this->iass_object,
462 $this->obj_user,
463 $this->grading,
464 22222
465 );
466
467 $this->assertFalse($obj->mayBeFinalized());
468 }
469
470 public function test_withExaminerId(): void
471 {
473 $this->iass_object,
474 $this->obj_user,
475 $this->grading,
476 22222
477 );
478
479 $new_obj = $obj->withExaminerId(333);
480
481 $this->assertNull($obj->examinerId());
482 $this->assertEquals(333, $new_obj->examinerId());
483 }
484
485 public function test_withChangerId(): void
486 {
488 $this->iass_object,
489 $this->obj_user,
490 $this->grading,
491 22222
492 );
493
494 $new_obj = $obj->withChangerId(534);
495
496 $this->assertNull($obj->changerId());
497 $this->assertEquals(534, $new_obj->changerId());
498 }
499
500 public function test_withChangeTime(): void
501 {
503 $this->iass_object,
504 $this->obj_user,
505 $this->grading,
506 22222
507 );
508
509 $new_obj = $obj->withChangeTime(new DateTimeImmutable("2021-11-25"));
510
511 $this->assertNull($obj->changeTime());
512 $this->assertEquals("2021-11-25", $new_obj->changeTime()->format("Y-m-d"));
513 }
514
515 public function test_lastname(): void
516 {
517 $this->obj_user
518 ->expects($this->once())
519 ->method("getLastname")
520 ->willReturn("lastname")
521 ;
522
524 $this->iass_object,
525 $this->obj_user,
526 $this->grading,
527 22222
528 );
529
530 $this->assertEquals("lastname", $obj->lastname());
531 }
532
533 public function test_firstname(): void
534 {
535 $this->obj_user
536 ->expects($this->once())
537 ->method("getFirstname")
538 ->willReturn("firstname")
539 ;
540
542 $this->iass_object,
543 $this->obj_user,
544 $this->grading,
545 22222
546 );
547
548 $this->assertEquals("firstname", $obj->firstname());
549 }
550
551 public function test_login(): void
552 {
553 $this->obj_user
554 ->expects($this->once())
555 ->method("getLogin")
556 ->willReturn("login")
557 ;
558
560 $this->iass_object,
561 $this->obj_user,
562 $this->grading,
563 22222
564 );
565
566 $this->assertEquals("login", $obj->login());
567 }
568
569 public function test_name(): void
570 {
571 $this->obj_user
572 ->expects($this->once())
573 ->method("getFullName")
574 ->willReturn("first last")
575 ;
576
578 $this->iass_object,
579 $this->obj_user,
580 $this->grading,
581 22222
582 );
583
584 $this->assertEquals("first last", $obj->name());
585 }
586
587 public function test_LPStatus(): void
588 {
589 $this->grading
590 ->expects($this->once())
591 ->method("getLearningProgress")
593 ;
594
596 $this->iass_object,
597 $this->obj_user,
598 $this->grading,
599 22222
600 );
601
602 $this->assertEquals(ilIndividualAssessmentMembers::LP_COMPLETED, $obj->LPStatus());
603 }
604
605 public function test_notificationTS(): void
606 {
608 $this->iass_object,
609 $this->obj_user,
610 $this->grading,
611 22222
612 );
613
614 $this->assertEquals(22222, $obj->notificationTS());
615 }
616
617 public function test_place(): void
618 {
619 $this->grading
620 ->expects($this->once())
621 ->method("getPlace")
622 ->willReturn("place")
623 ;
624
626 $this->iass_object,
627 $this->obj_user,
628 $this->grading,
629 22222
630 );
631
632 $this->assertEquals("place", $obj->place());
633 }
634
635 public function test_eventTime(): void
636 {
637 $this->grading
638 ->expects($this->once())
639 ->method("getEventTime")
640 ->willReturn(new DateTimeImmutable("2021-11-25"))
641 ;
642
644 $this->iass_object,
645 $this->obj_user,
646 $this->grading,
647 22222
648 );
649
650 $this->assertEquals("2021-11-25", $obj->eventTime()->format("Y-m-d"));
651 }
652
653 public function test_fileName(): void
654 {
655 $this->grading
656 ->expects($this->once())
657 ->method("getFile")
658 ->willReturn("file_name")
659 ;
660
662 $this->iass_object,
663 $this->obj_user,
664 $this->grading,
665 22222
666 );
667
668 $this->assertEquals("file_name", $obj->fileName());
669 }
670
671 public function test_viewFile(): void
672 {
673 $this->grading
674 ->expects($this->once())
675 ->method("isFileVisible")
676 ->willReturn(true)
677 ;
678
680 $this->iass_object,
681 $this->obj_user,
682 $this->grading,
683 22222
684 );
685
686 $this->assertTrue($obj->viewFile());
687 }
688
689 public function test_getGrading(): void
690 {
692 $this->iass_object,
693 $this->obj_user,
694 $this->grading,
695 22222
696 );
697
698 $this->assertEquals($this->grading, $obj->getGrading());
699 }
700
701 public function test_withGrading(): void
702 {
704 $this->iass_object,
705 $this->obj_user,
706 $this->grading,
707 22222
708 );
709
710 $new_grading = $this->createMock(ilIndividualAssessmentUserGrading::class);
711 $new_grading = $new_grading->withFinalized(true);
712 $new_obj = $obj->withGrading($new_grading);
713
714 $this->assertNotEquals($new_grading, $obj->getGrading());
715 $this->assertEquals($new_grading, $new_obj->getGrading());
716 }
717}
$filename
Definition: buildRTE.php:78
test_mayBeFinalized_file_required_filename_empty(?string $filename)
@dataProvider fileNamesDataProvider
test_mayBeFinalized_with_negative_lp_status(int $lp_status)
@dataProvider negativeLPStatusDataProvider
test_mayBeFinalized_with_positive_lp_status(int $lp_status)
@dataProvider positiveLPStatusDataProvider
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200