ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilIndividualAssessmentMembersStorageDBTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
24 {
27  ilObjUser $usr,
28  array $record
30  return $this->createAssessmentMember($obj, $usr, $record);
31  }
32 
33  // The access modifier is changed to public here to allow the actual test
34  // to access this.
35  public function getActualDateTime(): string
36  {
37  return "2021-12-02 12:55:33";
38  }
39 
43  public function getWhereFromFilterWrapper($filter): string
44  {
45  return $this->getWhereFromFilter($filter);
46  }
47 
48  public function getOrderByFromSortWrapper(string $sort): string
49  {
50  return $this->getOrderByFromSort($sort);
51  }
52 }
53 
55 {
56  public function testCreateObject(): void
57  {
58  $db = $this->createMock(ilDBInterface::class);
60  $this->assertInstanceOf(ilIndividualAssessmentMembersStorageDB::class, $obj);
61  }
62 
63  public function test_loadMembers(): void
64  {
65  $sql = "SELECT ex.firstname as " . ilIndividualAssessmentMembers::FIELD_EXAMINER_FIRSTNAME
69  . " ,usr.firstname as " . ilIndividualAssessmentMembers::FIELD_FIRSTNAME
70  . " ,usr.lastname as " . ilIndividualAssessmentMembers::FIELD_LASTNAME
71  . " ,usr.login as " . ilIndividualAssessmentMembers::FIELD_LOGIN
73  . " ,iassme.obj_id, iassme.usr_id, iassme.examiner_id, iassme.record, iassme.internal_note, iassme.notify"
74  . " ,iassme.notification_ts, iassme.learning_progress, iassme.finalized,iassme.place"
75  . " ,iassme.event_time, iassme.changer_id, iassme.change_time\n"
76  . " FROM iass_members iassme"
77  . " JOIN usr_data usr ON iassme.usr_id = usr.usr_id"
78  . " LEFT JOIN usr_data ex ON iassme.examiner_id = ex.usr_id"
79  . " LEFT JOIN usr_data ud ON iassme.changer_id = ud.usr_id"
80  . " WHERE obj_id = 22";
81 
82 
83  $iass = $this->createMock(ilObjIndividualAssessment::class);
84  $iass
85  ->expects($this->once())
86  ->method("getId")
87  ->willReturn(22)
88  ;
89 
90  $db_statement = $this->createMock(ilDBStatement::class);
91 
92  $db = $this->createMock(ilDBInterface::class);
93  $db
94  ->expects($this->once())
95  ->method("quote")
96  ->with(22, "integer")
97  ->willReturn("22")
98  ;
99  $db
100  ->expects($this->once())
101  ->method("query")
102  ->with($sql)
103  ->willReturn($db_statement)
104  ;
105  $db
106  ->expects($this->any())
107  ->method("fetchAssoc")
108  ->with($db_statement)
109  ->willReturn(null)
110  ;
111 
113  $result = $obj->loadMembers($iass);
114  $this->assertInstanceOf(ilIndividualAssessmentMembers::class, $result);
115  }
116 
117  public function test_loadMembersAsSingleObjects(): void
118  {
119  $sql = "SELECT "
120  . "iassme.obj_id,"
121  . "iassme.usr_id,"
122  . "iassme.examiner_id,"
123  . "iassme.record,"
124  . "iassme.internal_note,"
125  . "iassme.notify,"
126  . "iassme.notification_ts,"
127  . "iassme.learning_progress,"
128  . "iassme.finalized,"
129  . "iassme.place,"
130  . "iassme.event_time,"
131  . "iassme.user_view_file,"
132  . "iassme.file_name,"
133  . "iassme.changer_id,"
134  . "iassme.change_time,"
135  . "usr.login AS user_login,"
136  . "ex.login AS examiner_login"
138  . " JOIN usr_data usr ON iassme.usr_id = usr.usr_id\n"
139  . " LEFT JOIN usr_data ex ON iassme.examiner_id = ex.usr_id\n"
140  . " WHERE obj_id = 22"
141  ;
142 
143  $iass = $this->createMock(ilObjIndividualAssessment::class);
144  $iass
145  ->expects($this->once())
146  ->method("getId")
147  ->willReturn(22)
148  ;
149 
150  $db_statement = $this->createMock(ilDBStatement::class);
151 
152  $db = $this->createMock(ilDBInterface::class);
153  $db
154  ->expects($this->once())
155  ->method("quote")
156  ->with(22, "integer")
157  ->willReturn("22")
158  ;
159  $db
160  ->expects($this->once())
161  ->method("query")
162  ->with($sql)
163  ->willReturn($db_statement)
164  ;
165  $db
166  ->expects($this->once())
167  ->method("fetchAssoc")
168  ->with($db_statement)
169  ->willReturn(null)
170  ;
171 
173  $result = $obj->loadMembersAsSingleObjects($iass);
174 
175  $this->assertIsArray($result);
176  $this->assertEmpty($result);
177  }
178 
179  public function test_loadMember_exception(): void
180  {
181  $sql = "SELECT "
182  . "iassme.obj_id,"
183  . "iassme.usr_id,"
184  . "iassme.examiner_id,"
185  . "iassme.record,"
186  . "iassme.internal_note,"
187  . "iassme.notify,"
188  . "iassme.notification_ts,"
189  . "iassme.learning_progress,"
190  . "iassme.finalized,"
191  . "iassme.place,"
192  . "iassme.event_time,"
193  . "iassme.user_view_file,"
194  . "iassme.file_name,"
195  . "iassme.changer_id,"
196  . "iassme.change_time,"
197  . "usr.login AS user_login,"
198  . "ex.login AS examiner_login"
200  . " JOIN usr_data usr ON iassme.usr_id = usr.usr_id\n"
201  . " LEFT JOIN usr_data ex ON iassme.examiner_id = ex.usr_id\n"
202  . " WHERE obj_id = 22\n"
203  . " AND iassme.usr_id = 33"
204  ;
205 
206  $iass = $this->createMock(ilObjIndividualAssessment::class);
207  $iass
208  ->expects($this->once())
209  ->method("getId")
210  ->willReturn(22)
211  ;
212 
213  $usr = $this->createMock(ilObjUser::class);
214  $usr
215  ->expects($this->once())
216  ->method("getId")
217  ->willReturn(33)
218  ;
219 
220  $db_statement = $this->createMock(ilDBStatement::class);
221 
222  $db = $this->createMock(ilDBInterface::class);
223  $db
224  ->expects($this->exactly(2))
225  ->method("quote")
226  ->withConsecutive([22, "integer"], [33, "integer"])
227  ->willReturnOnConsecutiveCalls("22", "33")
228  ;
229  $db
230  ->expects($this->once())
231  ->method("query")
232  ->with($sql)
233  ->willReturn($db_statement)
234  ;
235  $db
236  ->expects($this->once())
237  ->method("fetchAssoc")
238  ->with($db_statement)
239  ->willReturn(null)
240  ;
241 
243 
244  $this->expectException(ilIndividualAssessmentException::class);
245  $this->expectExceptionMessage("invalid usr-obj combination");
246  $obj->loadMember($iass, $usr);
247  }
248 
249  public function test_loadMember(): void
250  {
251  $sql = "SELECT "
252  . "iassme.obj_id,"
253  . "iassme.usr_id,"
254  . "iassme.examiner_id,"
255  . "iassme.record,"
256  . "iassme.internal_note,"
257  . "iassme.notify,"
258  . "iassme.notification_ts,"
259  . "iassme.learning_progress,"
260  . "iassme.finalized,"
261  . "iassme.place,"
262  . "iassme.event_time,"
263  . "iassme.user_view_file,"
264  . "iassme.file_name,"
265  . "iassme.changer_id,"
266  . "iassme.change_time,"
267  . "usr.login AS user_login,"
268  . "ex.login AS examiner_login"
270  . " JOIN usr_data usr ON iassme.usr_id = usr.usr_id\n"
271  . " LEFT JOIN usr_data ex ON iassme.examiner_id = ex.usr_id\n"
272  . " WHERE obj_id = 22\n"
273  . " AND iassme.usr_id = 33"
274  ;
275 
276  $iass = $this->createMock(ilObjIndividualAssessment::class);
277  $iass
278  ->expects($this->once())
279  ->method("getId")
280  ->willReturn(22)
281  ;
282 
283  $usr = $this->createMock(ilObjUser::class);
284  $usr
285  ->expects($this->once())
286  ->method("getId")
287  ->willReturn(33)
288  ;
289 
290  $db_statement = $this->createMock(ilDBStatement::class);
291 
292  $db = $this->createMock(ilDBInterface::class);
293  $db
294  ->expects($this->exactly(2))
295  ->method("quote")
296  ->withConsecutive([22, "integer"], [33, "integer"])
297  ->willReturnOnConsecutiveCalls("22", "33")
298  ;
299  $db
300  ->expects($this->once())
301  ->method("query")
302  ->with($sql)
303  ->willReturn($db_statement)
304  ;
305  $db
306  ->expects($this->once())
307  ->method("fetchAssoc")
308  ->with($db_statement)
309  ->willReturn(null)
310  ;
311 
313 
314  $this->expectException(ilIndividualAssessmentException::class);
315  $this->expectExceptionMessage("invalid usr-obj combination");
316  $obj->loadMember($iass, $usr);
317  }
318 
319  public function test_createAssessmentMember(): void
320  {
321  $iass = $this->createMock(ilObjIndividualAssessment::class);
322  $usr = $this->createMock(ilObjUser::class);
323  $usr
324  ->expects($this->once())
325  ->method("getFullname")
326  ->willReturn("Full Name")
327  ;
328 
329  $timestamp = 1638431626;
330 
331  $record = [
345  ];
346 
347  $db = $this->createMock(ilDBInterface::class);
349 
350  $member = $obj->createAssessmentMemberWrapper($iass, $usr, $record);
351 
352  $this->assertEquals("Full Name", $member->getGrading()->getName());
353  $this->assertEquals(11, $member->changerId());
354  $this->assertEquals("2021-12-02", $member->changeTime()->format("Y-m-d"));
355  $this->assertEquals(22, $member->examinerId());
356  $this->assertEquals($timestamp, $member->notificationTS());
357  $this->assertEquals($timestamp, $member->eventTime()->getTimestamp());
358  $this->assertEquals("record", $member->record());
359  $this->assertEquals("internal_note", $member->internalNote());
360  $this->assertEquals("file_name", $member->fileName());
361  $this->assertTrue($member->viewFile());
362  $this->assertEquals(33, $member->LPStatus());
363  $this->assertTrue($member->notify());
364  $this->assertTrue($member->finalized());
365  }
366 
367  public function test_updateMember(): void
368  {
369  $timestamp = 1638431626;
370  $date = (new DateTimeImmutable())->setTimestamp($timestamp);
371 
372  $member = $this->createMock(ilIndividualAssessmentMember::class);
373  $member
374  ->expects($this->once())
375  ->method("assessmentId")
376  ->willReturn(11)
377  ;
378  $member
379  ->expects($this->once())
380  ->method("id")
381  ->willReturn(22)
382  ;
383  $member
384  ->expects($this->once())
385  ->method("eventTime")
386  ->willReturn($date)
387  ;
388  $member
389  ->expects($this->once())
390  ->method("LPStatus")
391  ->willReturn(33)
392  ;
393  $member
394  ->expects($this->once())
395  ->method("examinerId")
396  ->willReturn(44)
397  ;
398  $member
399  ->expects($this->once())
400  ->method("record")
401  ->willReturn("record")
402  ;
403  $member
404  ->expects($this->once())
405  ->method("internalNote")
406  ->willReturn("internalNote")
407  ;
408  $member
409  ->expects($this->once())
410  ->method("place")
411  ->willReturn("place")
412  ;
413  $member
414  ->expects($this->once())
415  ->method("notify")
416  ->willReturn(true)
417  ;
418  $member
419  ->expects($this->once())
420  ->method("finalized")
421  ->willReturn(true)
422  ;
423  $member
424  ->expects($this->once())
425  ->method("notificationTS")
426  ->willReturn($timestamp)
427  ;
428  $member
429  ->expects($this->once())
430  ->method("fileName")
431  ->willReturn("fileName")
432  ;
433  $member
434  ->expects($this->once())
435  ->method("viewFile")
436  ->willReturn(true)
437  ;
438  $member
439  ->expects($this->once())
440  ->method("changerId")
441  ->willReturn(55)
442  ;
443 
444  $db = $this->createMock(ilDBInterface::class);
446 
447  $where = [
448  "obj_id" => ["integer", 11],
449  "usr_id" => ["integer", 22]
450  ];
451 
452  $values = [
455  ilIndividualAssessmentMembers::FIELD_RECORD => ["text", "record"],
456  ilIndividualAssessmentMembers::FIELD_INTERNAL_NOTE => ["text", "internalNote"],
457  ilIndividualAssessmentMembers::FIELD_PLACE => ["text", "place"],
459  ilIndividualAssessmentMembers::FIELD_NOTIFY => ["integer", true],
462  ilIndividualAssessmentMembers::FIELD_FILE_NAME => ["text", "fileName"],
465  ilIndividualAssessmentMembers::FIELD_CHANGE_TIME => ["string", $obj->getActualDateTime()]
466  ];
467 
468  $db
469  ->expects($this->once())
470  ->method("update")
471  ->with("iass_members", $values, $where)
472  ;
473 
474 
475  $obj->updateMember($member);
476  }
477 
478  public function test_deleteMembers(): void
479  {
480  $iass = $this->createMock(ilObjIndividualAssessment::class);
481  $iass
482  ->expects($this->once())
483  ->method("getId")
484  ->willReturn(22)
485  ;
486 
487  $sql = "DELETE FROM iass_members WHERE obj_id = 22";
488 
489  $db = $this->createMock(ilDBInterface::class);
490  $db
491  ->expects($this->once())
492  ->method("quote")
493  ->with(22, "integer")
494  ->willReturn("22")
495  ;
496  $db
497  ->expects($this->once())
498  ->method("manipulate")
499  ->with($sql)
500  ;
501 
503  $obj->deleteMembers($iass);
504  }
505 
506  public function test_insertMembersRecord(): void
507  {
508  $timestamp = 1638431626;
509 
510  $iass = $this->createMock(ilObjIndividualAssessment::class);
511  $iass
512  ->expects($this->once())
513  ->method("getId")
514  ->willReturn(11)
515  ;
516 
517  $db = $this->createMock(ilDBInterface::class);
519 
520  $record = [
534  ilIndividualAssessmentMembers::FIELD_CHANGE_TIME => $obj->getActualDateTime()
535  ];
536 
537  $values = [
538  "obj_id" => ["integer", 11],
541  ilIndividualAssessmentMembers::FIELD_NOTIFY => ["integer", true],
545  ilIndividualAssessmentMembers::FIELD_RECORD => ["text", "record"],
546  ilIndividualAssessmentMembers::FIELD_INTERNAL_NOTE => ["text", "internalNote"],
547  ilIndividualAssessmentMembers::FIELD_PLACE => ["text", "place"],
549  ilIndividualAssessmentMembers::FIELD_FILE_NAME => ["text", "fileName"],
552  ilIndividualAssessmentMembers::FIELD_CHANGE_TIME => ["text", $obj->getActualDateTime()]
553  ];
554 
555  $db
556  ->expects($this->once())
557  ->method("insert")
558  ->with("iass_members", $values)
559  ;
560 
561  $obj->insertMembersRecord($iass, $record);
562  }
563 
564  public function test_removeMembersRecord(): void
565  {
566  $iass = $this->createMock(ilObjIndividualAssessment::class);
567  $iass
568  ->expects($this->once())
569  ->method("getId")
570  ->willReturn(11)
571  ;
572 
574 
575  $sql =
576  "DELETE FROM iass_members" . PHP_EOL
577  . "WHERE obj_id = 11" . PHP_EOL
578  . "AND usr_id = 22" . PHP_EOL
579  ;
580 
581  $db = $this->createMock(ilDBInterface::class);
582  $db
583  ->expects($this->exactly(2))
584  ->method("quote")
585  ->withConsecutive([11, "integer"], [22, "integer"])
586  ->willReturnOnConsecutiveCalls("11", "22")
587  ;
588  $db
589  ->expects($this->once())
590  ->method("manipulate")
591  ->with($sql)
592  ;
593 
595  $obj->removeMembersRecord($iass, $record);
596  }
597 
598  public function dataFor_getWhereFromFilter(): array
599  {
600  return [
601  [
603  " AND finalized = 0 AND examiner_id IS NULL\n"
604  ],
605  [
607  " AND finalized = 0 AND examiner_id IS NOT NULL\n"
608  ],
609  [
611  " AND finalized = 1 AND learning_progress = 2\n"
612  ],
613  [
615  " AND finalized = 1 AND learning_progress = 3\n"
616  ],
617  [
618  "test",
619  ""
620  ]
621  ];
622  }
623 
627  public function test_getWhereFromFilter($filter, $result): void
628  {
629  $db = $this->createMock(ilDBInterface::class);
631  $res = $obj->getWhereFromFilterWrapper($filter);
632 
633  $this->assertEquals($result, $res);
634  }
635 
636  public function test_getOrderByFromSort(): void
637  {
638  $db = $this->createMock(ilDBInterface::class);
640 
641  $sort = "test:foo";
642 
643  $res = $obj->getOrderByFromSortWrapper($sort);
644 
645  $this->assertEquals(" ORDER BY test foo", $res);
646  }
647 }
createAssessmentMember(ilObjIndividualAssessment $obj, ilObjUser $usr, array $record)
$res
Definition: ltiservices.php:69
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
test_getWhereFromFilter($filter, $result)
dataFor_getWhereFromFilter
createAssessmentMemberWrapper(ilObjIndividualAssessment $obj, ilObjUser $usr, array $record)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:70
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...