ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilStudyProgrammeUserProgressTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2015 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5require_once(__DIR__ . "/mocks.php");
6
16{
17 protected $backupGlobals = false;
18
19 protected function setUp()
20 {
21 PHPUnit_Framework_Error_Deprecated::$enabled = false;
22
23 require_once("./Modules/StudyProgramme/classes/class.ilObjStudyProgramme.php");
24
25 include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
26 ilUnitUtil::performInitialisation();
27
29 $this->root->putInTree(ROOT_FOLDER_ID);
30 $this->root->object_factory = new ilObjectFactoryWrapperMock();
31
34
35 $this->leaf1 = new ilStudyProgrammeLeafMock();
36 $this->leaf2 = new ilStudyProgrammeLeafMock();
37
38 $this->root->addNode($this->node1);
39 $this->root->addNode($this->node2);
40 $this->node1->addLeaf($this->leaf1);
41 $this->node2->addLeaf($this->leaf2);
42
43 global $DIC;
44 $tree = $DIC['tree'];
45 $this->tree = $tree;
46
47 global $DIC;
48 $ilUser = $DIC['ilUser'];
49 $this->user = $ilUser;
50 }
51
52 protected function tearDown()
53 {
54 if ($this->root) {
55 $this->root->delete();
56 }
57 }
58
59 protected function newUser()
60 {
61 $user = new ilObjUser();
62 $user->create();
63 return $user;
64 }
65
66 protected function setAllNodesActive()
67 {
68 $this->root->setStatus(ilStudyProgramme::STATUS_ACTIVE)->update();
69 $this->node1->setStatus(ilStudyProgramme::STATUS_ACTIVE)->update();
70 $this->node2->setStatus(ilStudyProgramme::STATUS_ACTIVE)->update();
71 }
72
73 protected function assignNewUserToRoot()
74 {
75 $user = $this->newUser();
76 return array($this->root->assignUser($user->getId()), $user);
77 }
78
79 public function testInitialProgressActive()
80 {
81 $this->setAllNodesActive();
82 $tmp = $this->assignNewUserToRoot();
83 $ass = $tmp[0];
84 $user = $tmp[1];
85
86 $root_progresses = $this->root->getProgressesOf($user->getId());
87 $this->assertCount(1, $root_progresses);
88 $root_progress = $root_progresses[0];
89 $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $root_progress->getStatus());
90 $this->assertEquals($this->root->getPoints(), $root_progress->getAmountOfPoints());
91 $this->assertEquals(0, $root_progress->getCurrentAmountOfPoints());
92 $this->assertEquals($this->root->getId(), $root_progress->getStudyProgramme()->getId());
93 $this->assertEquals($ass->getId(), $root_progress->getAssignment()->getId());
94 $this->assertEquals($user->getId(), $root_progress->getUserId());
95 $this->assertNull($root_progress->getLastChangeBy());
96 $this->assertNull($root_progress->getCompletionBy());
97
98 $node1_progresses = $this->node1->getProgressesOf($user->getId());
99 $this->assertCount(1, $node1_progresses);
100 $node1_progress = $node1_progresses[0];
101 $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $node1_progress->getStatus());
102 $this->assertEquals($this->node1->getPoints(), $node1_progress->getAmountOfPoints());
103 $this->assertEquals(0, $node1_progress->getCurrentAmountOfPoints());
104 $this->assertEquals($this->node1->getId(), $node1_progress->getStudyProgramme()->getId());
105 $this->assertEquals($ass->getId(), $node1_progress->getAssignment()->getId());
106 $this->assertEquals($user->getId(), $node1_progress->getUserId());
107 $this->assertNull($node1_progress->getLastChangeBy());
108 $this->assertNull($node1_progress->getCompletionBy());
109
110 $node2_progresses = $this->node2->getProgressesOf($user->getId());
111 $this->assertCount(1, $node2_progresses);
112 $node2_progress = $node2_progresses[0];
113 $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $node2_progress->getStatus());
114 $this->assertEquals($this->node2->getPoints(), $node2_progress->getAmountOfPoints());
115 $this->assertEquals(0, $node2_progress->getCurrentAmountOfPoints());
116 $this->assertEquals($this->node2->getId(), $node2_progress->getStudyProgramme()->getId());
117 $this->assertEquals($ass->getId(), $node2_progress->getAssignment()->getId());
118 $this->assertEquals($user->getId(), $node2_progress->getUserId());
119 $this->assertNull($node2_progress->getLastChangeBy());
120 $this->assertNull($node2_progress->getCompletionBy());
121 }
122
123 public function testInitialProgressDraft()
124 {
125 $this->root->setStatus(ilStudyProgramme::STATUS_ACTIVE)->update();
126 $this->node1->setStatus(ilStudyProgramme::STATUS_ACTIVE)->update();
127 $this->node2->setStatus(ilStudyProgramme::STATUS_DRAFT)->update();
128
129 $tmp = $this->assignNewUserToRoot();
130 $user = $tmp[1];
131 $ass = $tmp[0];
132
133 $root_progresses = $this->root->getProgressesOf($user->getId());
134 $root_progress = $root_progresses[0];
135 $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $root_progress->getStatus());
136
137 $node1_progresses = $this->node1->getProgressesOf($user->getId());
138 $node1_progress = $node1_progresses[0];
139 $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $node1_progress->getStatus());
140
141 $node2_progresses = $this->node2->getProgressesOf($user->getId());
142 $node2_progress = $node2_progresses[0];
143 $this->assertEquals(ilStudyProgrammeProgress::STATUS_NOT_RELEVANT, $node2_progress->getStatus());
144 }
145
147 {
148 $this->root->setStatus(ilStudyProgramme::STATUS_ACTIVE)->update();
149 $this->node1->setStatus(ilStudyProgramme::STATUS_ACTIVE)->update();
150 $this->node2->setStatus(ilStudyProgramme::STATUS_OUTDATED)->update();
151
152 $tmp = $this->assignNewUserToRoot();
153 $user = $tmp[1];
154 $ass = $tmp[0];
155
156 $root_progresses = $this->root->getProgressesOf($user->getId());
157 $root_progress = $root_progresses[0];
158 $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $root_progress->getStatus());
159
160 $node1_progresses = $this->node1->getProgressesOf($user->getId());
161 $node1_progress = $node1_progresses[0];
162 $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $node1_progress->getStatus());
163
164 $node2_progresses = $this->node2->getProgressesOf($user->getId());
165 $node2_progress = $node2_progresses[0];
166 $this->assertEquals(ilStudyProgrammeProgress::STATUS_NOT_RELEVANT, $node2_progress->getStatus());
167 }
168
169 public function testUserSelection()
170 {
171 $this->setAllNodesActive();
172 $this->assignNewUserToRoot();
173 $tmp = $this->assignNewUserToRoot();
174 $ass = $tmp[0];
175 $user = $tmp[1];
176
177 $root_progresses = $this->root->getProgressesOf($user->getId());
178 $this->assertCount(1, $root_progresses);
179 }
180
181 public function testMarkAccredited()
182 {
183 $this->setAllNodesActive();
184 $tmp = $this->assignNewUserToRoot();
185 $ass = $tmp[0];
186 $user = $tmp[1];
187
188 $user2 = $this->newUser();
189 $USER_ID = $user2->getId();
190
191 $root_progress = array_shift($this->root->getProgressesOf($user->getId()));
192 $node1_progress = array_shift($this->node1->getProgressesOf($user->getId()));
193
194 $node2_progress = array_shift($this->node2->getProgressesOf($user->getId()));
195 $this->assertEquals($root_progress->getAmountOfPoints(), ilStudyProgramme::DEFAULT_POINTS);
196 $this->assertEquals($node1_progress->getAmountOfPoints(), ilStudyProgramme::DEFAULT_POINTS);
197 $this->assertEquals($node2_progress->getAmountOfPoints(), ilStudyProgramme::DEFAULT_POINTS);
198
199 $ts_before_change = $node2_progress->getLastChange()->get(IL_CAL_DATETIME);
200 $node2_progress->markAccredited($USER_ID);
201 $ts_after_change = $node2_progress->getLastChange()->get(IL_CAL_DATETIME);
202
203 $this->assertTrue($node2_progress->isSuccessful());
204 $this->assertEquals($root_progress->getAmountOfPoints(), $root_progress->getCurrentAmountOfPoints());
205
206 $this->assertEquals(ilStudyProgrammeProgress::STATUS_COMPLETED, $root_progress->getStatus());
207 $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $node1_progress->getStatus());
208 $this->assertEquals(ilStudyProgrammeProgress::STATUS_ACCREDITED, $node2_progress->getStatus());
209
210 $this->assertEquals($USER_ID, $node2_progress->getCompletionBy());
211 $this->assertLessThanOrEqual($ts_before_change, $ts_after_change);
212 }
213
214 public function testUnmarkAccredited()
215 {
216 $this->setAllNodesActive();
217 $tmp = $this->assignNewUserToRoot();
218 $ass = $tmp[0];
219 $user = $tmp[1];
220
221 $user2 = $this->newUser();
222 $USER_ID = $user2->getId();
223
224 $root_progress = array_shift($this->root->getProgressesOf($user->getId()));
225 $node1_progress = array_shift($this->node1->getProgressesOf($user->getId()));
226 $node2_progress = array_shift($this->node2->getProgressesOf($user->getId()));
227
228 $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $root_progress->getStatus());
229 $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $node1_progress->getStatus());
230 $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $node2_progress->getStatus());
231
232 $ts_before_change = $node2_progress->getLastChange()->get(IL_CAL_DATETIME);
233 $node2_progress->markAccredited($USER_ID);
234 $node2_progress->unmarkAccredited();
235 $ts_after_change = $node2_progress->getLastChange()->get(IL_CAL_DATETIME);
236
237 // The root node will still be completed, as we do not go back from completed to some other
238 // status.
239 $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $root_progress->getStatus());
240 $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $node1_progress->getStatus());
241 $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $node2_progress->getStatus());
242 $this->assertEquals(null, $node2_progress->getCompletionBy());
243 $this->assertLessThanOrEqual($ts_before_change, $ts_after_change);
244 }
245
246 public function testMarkFailed()
247 {
248 $this->setAllNodesActive();
249 $tmp = $this->assignNewUserToRoot();
250 $ass = $tmp[0];
251 $user = $tmp[1];
252
253 $user2 = $this->newUser();
254 $USER_ID = $user2->getId();
255
256 $root_progress = array_shift($this->root->getProgressesOf($user->getId()));
257 $node1_progress = array_shift($this->node1->getProgressesOf($user->getId()));
258 $node2_progress = array_shift($this->node2->getProgressesOf($user->getId()));
259 $node2_progress->markFailed($USER_ID);
260
261 $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $root_progress->getStatus());
262 $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $node1_progress->getStatus());
263 $this->assertEquals(ilStudyProgrammeProgress::STATUS_FAILED, $node2_progress->getStatus());
264 }
265
266 public function testMarkNotFailed()
267 {
268 $this->setAllNodesActive();
269 $tmp = $this->assignNewUserToRoot();
270 $ass = $tmp[0];
271 $user = $tmp[1];
272
273 $user2 = $this->newUser();
274 $USER_ID = $user2->getId();
275
276 $root_progress = array_shift($this->root->getProgressesOf($user->getId()));
277 $node1_progress = array_shift($this->node1->getProgressesOf($user->getId()));
278 $node2_progress = array_shift($this->node2->getProgressesOf($user->getId()));
279 $node2_progress->markFailed($USER_ID);
280
281 $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $root_progress->getStatus());
282 $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $node1_progress->getStatus());
283 $this->assertEquals(ilStudyProgrammeProgress::STATUS_FAILED, $node2_progress->getStatus());
284
285 $node2_progress->markNotFailed($USER_ID);
286
287 $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $node2_progress->getStatus());
288 }
289
290 public function testMarkNotRelevant()
291 {
292 $this->setAllNodesActive();
293 $tmp = $this->assignNewUserToRoot();
294 $ass = $tmp[0];
295 $user = $tmp[1];
296
297 $user2 = $this->newUser();
298 $USER_ID = $user2->getId();
299
300 $root_progress = array_shift($this->root->getProgressesOf($user->getId()));
301 $node1_progress = array_shift($this->node1->getProgressesOf($user->getId()));
302 $node2_progress = array_shift($this->node2->getProgressesOf($user->getId()));
303 $ts_before_change = $node2_progress->getLastChange()->get(IL_CAL_DATETIME);
304 $node2_progress->markNotRelevant($USER_ID);
305 $ts_after_change = $node2_progress->getLastChange()->get(IL_CAL_DATETIME);
306 $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $root_progress->getStatus());
307 $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $node1_progress->getStatus());
308 $this->assertEquals(ilStudyProgrammeProgress::STATUS_NOT_RELEVANT, $node2_progress->getStatus());
309 $this->assertEquals($USER_ID, $node2_progress->getCompletionBy());
310 $this->assertLessThanOrEqual($ts_before_change, $ts_after_change);
311 $this->assertTrue($node2_progress->hasIndividualModifications());
312 }
313
314 // Neues Moduls: Wird dem Studierenden-Studierenden inkl. Kurse, Punkte als "Nicht relevant" hinzugefügt.
316 {
317 $this->setAllNodesActive();
318 $tmp = $this->assignNewUserToRoot();
319 $ass = $tmp[0];
320 $user = $tmp[1];
321
323 $this->root->addNode($node3);
324
325 $node3_progress = array_shift($node3->getProgressesOf($user->getId()));
326 $this->assertNotNull($node3_progress);
327 $this->assertEquals(ilStudyProgrammeProgress::STATUS_NOT_RELEVANT, $node3_progress->getStatus());
328 }
329
331 {
332 $this->setAllNodesActive();
333 $tmp = $this->assignNewUserToRoot();
334 $ass1 = $tmp[0];
335 $user1 = $tmp[1];
336
337
338 $NEW_AMOUNT_OF_POINTS_1 = 205;
339 $this->assertNotEquals($NEW_AMOUNT_OF_POINTS_1, ilStudyProgramme::DEFAULT_POINTS);
340
341 $node2_progress1 = array_shift($this->node2->getProgressesOf($user1->getId()));
342 $node2_progress1->setRequiredAmountOfPoints($NEW_AMOUNT_OF_POINTS_1, $this->user->getId());
343
344 $this->assertEquals($NEW_AMOUNT_OF_POINTS_1, $node2_progress1->getAmountOfPoints());
345 }
346
348 {
349 $this->setAllNodesActive();
350 $tmp = $this->assignNewUserToRoot();
351 $ass = $tmp[0];
352 $user = $tmp[1];
353
354 $root_progress = array_shift($this->root->getProgressesOf($user->getId()));
355 $node1_progress = array_shift($this->node1->getProgressesOf($user->getId()));
356 $node2_progress = array_shift($this->node2->getProgressesOf($user->getId()));
357
358 $this->assertEquals(2 * ilStudyProgramme::DEFAULT_POINTS, $root_progress->getMaximumPossibleAmountOfPoints());
359 $this->assertEquals(ilStudyProgramme::DEFAULT_POINTS, $node1_progress->getMaximumPossibleAmountOfPoints());
360 $this->assertEquals(ilStudyProgramme::DEFAULT_POINTS, $node2_progress->getMaximumPossibleAmountOfPoints());
361 }
362
364 {
365 $this->setAllNodesActive();
366 $tmp = $this->assignNewUserToRoot();
367 $ass = $tmp[0];
368 $user = $tmp[1];
369
370 $root_progress = array_shift($this->root->getProgressesOf($user->getId()));
371 $node1_progress = array_shift($this->node1->getProgressesOf($user->getId()));
372 $node2_progress = array_shift($this->node2->getProgressesOf($user->getId()));
373
374 $this->assertEquals(2 * ilStudyProgramme::DEFAULT_POINTS, $root_progress->getMaximumPossibleAmountOfPoints());
375 $this->assertEquals(ilStudyProgramme::DEFAULT_POINTS, $node1_progress->getMaximumPossibleAmountOfPoints());
376 $this->assertEquals(ilStudyProgramme::DEFAULT_POINTS, $node2_progress->getMaximumPossibleAmountOfPoints());
377 }
378
379 public function testCanBeCompleted1()
380 {
381 $this->setAllNodesActive();
382 $tmp = $this->assignNewUserToRoot();
383 $ass = $tmp[0];
384 $user = $tmp[1];
385
386 $root_progress = array_shift($this->root->getProgressesOf($user->getId()));
387 $node1_progress = array_shift($this->node1->getProgressesOf($user->getId()));
388 $node2_progress = array_shift($this->node2->getProgressesOf($user->getId()));
389
390 $this->assertTrue($root_progress->canBeCompleted());
391 $this->assertTrue($node1_progress->canBeCompleted());
392 $this->assertTrue($node2_progress->canBeCompleted());
393 }
394
395 public function testCanBeCompleted2()
396 {
397 $NEW_AMOUNT_OF_POINTS = 3003;
398 $this->assertGreaterThan(ilStudyProgramme::DEFAULT_POINTS, $NEW_AMOUNT_OF_POINTS);
399
400 $this->setAllNodesActive();
401 $this->root->setPoints($NEW_AMOUNT_OF_POINTS)
402 ->update();
403 $tmp = $this->assignNewUserToRoot();
404 $ass = $tmp[0];
405 $user = $tmp[1];
406
407 $this->assertLessThan($NEW_AMOUNT_OF_POINTS, $this->node1->getPoints() + $this->node2->getPoints());
408
409 $root_progress = array_shift($this->root->getProgressesOf($user->getId()));
410 $this->assertFalse($root_progress->canBeCompleted());
411 }
412
413 public function testCanBeCompleted3()
414 {
415 $NEW_AMOUNT_OF_POINTS = 3003;
416 $this->assertGreaterThan(ilStudyProgramme::DEFAULT_POINTS, $NEW_AMOUNT_OF_POINTS);
417
418 $this->setAllNodesActive();
420 $this->root->addNode($node3);
421 $node3->setPoints($NEW_AMOUNT_OF_POINTS)
423 ->update();
424
425
426 $tmp = $this->assignNewUserToRoot();
427 $ass = $tmp[0];
428 $user = $tmp[1];
429
430 $root_progress = array_shift($this->root->getProgressesOf($user->getId()));
431 $node3_progress = array_shift($node3->getProgressesOf($user->getId()));
432
433 $this->assertFalse($root_progress->canBeCompleted());
434 $this->assertFalse($node3_progress->canBeCompleted());
435 }
436
438 {
439 $this->setAllNodesActive();
440 $tmp = $this->assignNewUserToRoot();
441 $ass = $tmp[0];
442 $user = $tmp[1];
443
444 $user->delete();
445
446 $root_progresses = $this->root->getProgressesOf($user->getId());
447 $this->assertCount(0, $root_progresses);
448 $node1_progresses = $this->root->getProgressesOf($user->getId());
449 $this->assertCount(0, $node1_progresses);
450 $node2_progresses = $this->root->getProgressesOf($user->getId());
451 $this->assertCount(0, $node2_progresses);
452 }
453
454 // - Änderungen von Punkten bei bestehenden qua-Objekten werden nicht direkt übernommen
456 {
457 $this->setAllNodesActive();
458 $tmp = $this->assignNewUserToRoot();
459 $ass = $tmp[0];
460 $user = $tmp[1];
461
462 $NEW_AMOUNT_OF_POINTS = 201;
463 $this->assertNotEquals($NEW_AMOUNT_OF_POINTS, ilStudyProgramme::DEFAULT_POINTS);
464
465 $this->root->setPoints($NEW_AMOUNT_OF_POINTS)
466 ->update();
467
468 $root_progress = array_shift($this->root->getProgressesOf($user->getId()));
469 $this->assertEquals(ilStudyProgramme::DEFAULT_POINTS, $root_progress->getAmountOfPoints());
470 }
471
472 // Änderungen von Punkten bei bestehenden qua-Objekten werden nicht direkt übernommen,
473 // sondern dann bei bewusster Aktualisierung.
474 public function testExplicitPointUpdate1()
475 {
476 $this->setAllNodesActive();
477 $tmp = $this->assignNewUserToRoot();
478 $ass = $tmp[0];
479 $user = $tmp[1];
480
481 $NEW_AMOUNT_OF_POINTS = 202;
482 $this->assertNotEquals($NEW_AMOUNT_OF_POINTS, ilStudyProgramme::DEFAULT_POINTS);
483
484 $this->root->setPoints($NEW_AMOUNT_OF_POINTS)
485 ->update();
486
487 $ass->updateFromProgram();
488 $root_progress = array_shift($this->root->getProgressesOf($user->getId()));
489 $this->assertEquals($NEW_AMOUNT_OF_POINTS, $root_progress->getAmountOfPoints());
490 }
491
492 // Änderungen von Punkten bei bestehenden qua-Objekten werden nicht direkt übernommen,
493 // sondern dann bei bewusster Aktualisierung.
494 // Similar to testExplicitPointUpdate1, but order of calls differs.
495 public function testExplicitPointUpdate2()
496 {
497 $this->setAllNodesActive();
498 $tmp = $this->assignNewUserToRoot();
499 $ass = $tmp[0];
500 $user = $tmp[1];
501
502 $NEW_AMOUNT_OF_POINTS = 203;
503 $this->assertNotEquals($NEW_AMOUNT_OF_POINTS, ilStudyProgramme::DEFAULT_POINTS);
504
505 $this->root->setPoints($NEW_AMOUNT_OF_POINTS)
506 ->update();
507
508 $root_progress = array_shift($this->root->getProgressesOf($user->getId()));
509 $ass->updateFromProgram();
510 $this->assertEquals($NEW_AMOUNT_OF_POINTS, $root_progress->getAmountOfPoints());
511 }
512
513 // Änderungen von Punkten bei bestehenden qua-Objekten werden nicht direkt übernommen,
514 // sondern dann bei bewusster Aktualisierung (sofern nicht ein darüberliegenden
515 // Knotenpunkt manuell angepasst worden ist)
517 {
518 $this->setAllNodesActive();
519 $tmp = $this->assignNewUserToRoot();
520 $ass1 = $tmp[0];
521 $user1 = $tmp[1];
522
523 $tmp = $this->assignNewUserToRoot();
524 $ass2 = $tmp[0];
525 $user2 = $tmp[1];
526
527 $NEW_AMOUNT_OF_POINTS_1 = 205;
528 $this->assertNotEquals($NEW_AMOUNT_OF_POINTS_1, ilStudyProgramme::DEFAULT_POINTS);
529 $NEW_AMOUNT_OF_POINTS_2 = 206;
530 $this->assertNotEquals($NEW_AMOUNT_OF_POINTS_2, ilStudyProgramme::DEFAULT_POINTS);
531 $this->assertNotEquals($NEW_AMOUNT_OF_POINTS_1, $NEW_AMOUNT_OF_POINTS_2);
532
533 $node2_progress1 = array_shift($this->node2->getProgressesOf($user1->getId()));
534 $node2_progress2 = array_shift($this->node2->getProgressesOf($user2->getId()));
535
536 $node2_progress1->setRequiredAmountOfPoints($NEW_AMOUNT_OF_POINTS_1, $this->user->getId());
537
538 $this->node2->setPoints($NEW_AMOUNT_OF_POINTS_2)
539 ->update();
540 $this->root->updateAllAssignments();
541
542 $this->assertEquals($NEW_AMOUNT_OF_POINTS_1, $node2_progress1->getAmountOfPoints());
543 $this->assertEquals($NEW_AMOUNT_OF_POINTS_2, $node2_progress2->getAmountOfPoints());
544 }
545
553 {
554 $this->setAllNodesActive();
555 $this->node1->setStatus(ilStudyProgramme::STATUS_OUTDATED);
556 $tmp = $this->assignNewUserToRoot();
557 $ass1 = $tmp[0];
558 $user1 = $tmp[1];
559
560 $progress = $this->node1->getProgressForAssignment($ass1->getId());
561 $this->assertEquals(ilStudyProgrammeProgress::STATUS_NOT_RELEVANT, $progress->getStatus());
562 $progress->markAccredited($this->user->getId());
563 }
564
565 // Hinweis bei der bei der Studierenden-Instanz des Studienplanes, falls dieser vom
566 // Original-Studienplan abweicht.
568 {
569 $this->setAllNodesActive();
570 $tmp = $this->assignNewUserToRoot();
571 $ass1 = $tmp[0];
572 $user1 = $tmp[1];
573
574 $progress = $this->node1->getProgressForAssignment($ass1->getId());
575 $this->assertFalse($progress->hasIndividualModifications());
576 }
577
579 {
580 $this->setAllNodesActive();
581 $tmp = $this->assignNewUserToRoot();
582 $ass1 = $tmp[0];
583 $user1 = $tmp[1];
584
585 $progress = $this->node1->getProgressForAssignment($ass1->getId());
586 $progress->setRequiredAmountOfPoints(1000, $this->user->getId());
587 $this->assertTrue($progress->hasIndividualModifications());
588 }
589
591 {
592 $this->setAllNodesActive();
593 $tmp = $this->assignNewUserToRoot();
594 $ass1 = $tmp[0];
595 $user1 = $tmp[1];
596
597 $progress = $this->node1->getProgressForAssignment($ass1->getId());
598 $progress->markNotRelevant($this->user->getId());
599 $this->assertTrue($progress->hasIndividualModifications());
600 }
601
603 {
604 $this->setAllNodesActive();
605 $tmp = $this->assignNewUserToRoot();
606 $ass1 = $tmp[0];
607 $user1 = $tmp[1];
608
609 $progress = $this->node1->getProgressForAssignment($ass1->getId());
610 $progress->markAccredited($this->user->getId());
611 $this->assertFalse($progress->hasIndividualModifications());
612 }
613
615 {
616 $this->setAllNodesActive();
617 $tmp = $this->assignNewUserToRoot();
618 $ass = $tmp[0];
619 $user = $tmp[1];
620
621 $user2 = $this->newUser();
622 $USER_ID = $user2->getId();
623
624 $this->node1->setTitle("node1");
625 $this->node1->update();
626 $this->node2->setTitle("node2");
627 $this->node2->update();
628
629 $names = $this->root->getProgressForAssignment($ass->getId())
630 ->getNamesOfCompletedOrAccreditedChildren();
631 $this->assertEquals($names, array());
632
633 $this->node1->getProgressForAssignment($ass->getId())->markAccredited($USER_ID);
634 $names = $this->root->getProgressForAssignment($ass->getId())
635 ->getNamesOfCompletedOrAccreditedChildren();
636 $this->assertEquals($names, array("node1"));
637
638 $this->node2->getProgressForAssignment($ass->getId())->markAccredited($USER_ID);
639 $names = $this->root->getProgressForAssignment($ass->getId())
640 ->getNamesOfCompletedOrAccreditedChildren();
641 $this->assertEquals($names, array("node1", "node2"));
642 }
643
645 {
650 $depth1->putInTree(ROOT_FOLDER_ID);
651 $depth1->addNode($depth2);
652 $depth2->addNode($depth3);
653 $depth3->addNode($depth4);
654 $depth1->setStatus(ilStudyProgramme::STATUS_ACTIVE);
655 $depth2->setStatus(ilStudyProgramme::STATUS_ACTIVE);
656 $depth3->setStatus(ilStudyProgramme::STATUS_ACTIVE);
657 $depth4->setStatus(ilStudyProgramme::STATUS_ACTIVE);
658
659 $user = $this->newUser();
660
661 $assignment = $depth1->assignUser($user->getId());
662 $progress4 = $depth4->getProgressForAssignment($assignment->getId());
663 $progress4->markAccredited(6);
664
665 $progress1 = $depth1->getProgressForAssignment($assignment->getId());
666 $progress2 = $depth2->getProgressForAssignment($assignment->getId());
667 $progress3 = $depth3->getProgressForAssignment($assignment->getId());
668
669 $this->assertTrue($progress1->isSuccessful());
670 $this->assertTrue($progress2->isSuccessful());
671 $this->assertTrue($progress3->isSuccessful());
672 $this->assertTrue($progress4->isSuccessful());
673
674 $this->assertEquals(ilStudyProgramme::DEFAULT_POINTS, $progress1->getCurrentAmountOfPoints());
675 $this->assertEquals(ilStudyProgramme::DEFAULT_POINTS, $progress2->getCurrentAmountOfPoints());
676 $this->assertEquals(ilStudyProgramme::DEFAULT_POINTS, $progress3->getCurrentAmountOfPoints());
677 $this->assertEquals(ilStudyProgramme::DEFAULT_POINTS, $progress4->getCurrentAmountOfPoints());
678 }
679
680
681 public function testPossibleActions()
682 {
683 //node is root-node, status is "not relevant"
684 $expected = array(
687 );
688 $this->assertEquals(
689 $expected,
691 1,
692 1,
694 )
695 );
696
697 //node is root-node, status is "in progress"
698 $expected = array(
702 );
703 $this->assertEquals(
704 $expected,
706 1,
707 1,
709 )
710 );
711
712 //node is root-node, status is "accredited"
713 $expected = array(
717 );
718 $this->assertEquals(
719 $expected,
721 1,
722 1,
724 )
725 );
726
727 //node is _not_ root-node, status is "accredited"
728 $expected = array(
730 );
731 $this->assertEquals(
732 $expected,
734 0,
735 1,
737 )
738 );
739 }
740
741 //get progress instance via DB-class
742 public function testGetInstance()
743 {
744 $this->setAllNodesActive();
745 $tmp = $this->assignNewUserToRoot();
746 $ass = $tmp[0];
747 $user = $tmp[1];
748
749 $sp_user_progress_db = new ilStudyProgrammeUserProgressDB();
750 $inst = $sp_user_progress_db->getInstance(
751 $ass->getId(),
752 $this->root->getId(),
753 $user->getId()
754 );
755 $this->assertInstanceOf(ilStudyProgrammeUserProgress::class, $inst);
756 $this->assertEquals(
757 $this->root->getProgressesOf($user->getId()),
758 $sp_user_progress_db->getInstancesForUser($this->root->getId(), $user->getId())
759 );
760
761 $up = $this->root->getProgressesOf($user->getId())[0];
762 $this->assertEquals(
763 $up,
764 $sp_user_progress_db->getInstanceById($up->getId())
765 );
766 }
767
768 public function testGetInstanceCalls()
769 {
770 $sp_user_progress_db = new ilStudyProgrammeUserProgressDB();
771 try {
772 $sp_user_progress_db->getInstanceById(-1);
773 $this->assertFalse("This should not happen");
774 } catch (ilException $e) {
775 $this->assertTrue(true);
776 }
777
778
779 try {
780 $sp_user_progress_db->getInstancesForAssignment(-1);
781 $this->assertFalse("This should not happen");
783 $this->assertTrue(true);
784 }
785 }
786}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
Base class for ILIAS Exception handling.
static createInstance()
Create an instance of ilObjStudyProgramme, put in cache.
Mock for object factory.
Definition: mocks.php:69
Mock classes for tests.
Definition: mocks.php:21
Exception is thrown when a progress for some programme node and assignment is missing.
Storage implementation for ilStudyProgrammeUserProgress.
TestCase for the progress of users at a programme.
testOutdatedNodesCantBeSetToRelevant()
QUA-Objekte, welche "Inaktiv" sind können bei Studierenden-Studienplänen nicht von "nicht relevant" a...
static getPossibleActions($a_node_id, $a_root_prg_id, $a_status)
Get a list with possible actions on a progress record.
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18