ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilStudyProgrammeProgressCalculationsTest.php
Go to the documentation of this file.
1 <?php declare(strict_types=1);
2 
3 require_once(__DIR__ . "/../../../libs/composer/vendor/autoload.php");
4 require_once(__DIR__ . "/prg_mocks.php");
5 
6 
7 class ilStudyProgrammeProgressCalculationsTest extends \PHPUnit\Framework\TestCase
8 {
9  protected function buildProgramme(int $prg_id) : ilObjStudyProgramme
10  {
11  $prg = new PrgMock($prg_id, $this);
12  $settings = new SettingsMock(
13  $prg_id
14  );
15  $settings->setLPMode(ilStudyProgrammeSettings::MODE_POINTS);
17  $set_dl = new ilStudyProgrammeDeadlineSettings(null, null);
18  $set_vq = new ilStudyProgrammeValidityOfAchievedQualificationSettings(null, null, null);
19  $settings = $settings
20  ->withAssessmentSettings($set_ass)
21  ->withDeadlineSettings($set_dl)
22  ->withValidityOfQualificationSettings($set_vq);
23  $this->settings_repo->update($settings);
24 
25  $progress = (new ilStudyProgrammeProgress($prg_id * -1))
26  ->withUserId(666)
28  ->withAmountOfPoints(2)
29  ->withAssignmentId(-42)
30  ->withNodeId($prg_id);
31  $this->progress_repo->update($progress);
32  return $prg;
33  }
34 
35  public function setUp() : void
36  {
37  $this->progress_repo = new ProgressRepoMock();
38  $this->assignment_repo = new AssignmentRepoMock();
39  $this->settings_repo = new SettingsRepoMock();
40  $this->messages = new ilPRGMessageCollection();
41 
42  /*
43  └── 1
44  ├── 11
45  │ ├── 111
46  │ └── 112
47  ├── 12
48  └── 13
49  */
50  $this->mock_tree = [
51  1 => ['parent' => null, 'children' => [11,12,13], 'prg' => $this->buildProgramme(1)],
52  11 => ['parent' => 1, 'children' => [111,112], 'prg' => $this->buildProgramme(11)],
53  111 => ['parent' => 11, 'children' => [], 'prg' => $this->buildProgramme(111)],
54  112 => ['parent' => 11, 'children' => [], 'prg' => $this->buildProgramme(112)],
55  12 => ['parent' => 1, 'children' => [], 'prg' => $this->buildProgramme(12)],
56  13 => ['parent' => 1, 'children' => [], 'prg' => $this->buildProgramme(13)]
57  ];
58 
59  $assignment = (new ilStudyProgrammeAssignment(-42))
60  ->withRootId(1);
61  $this->assignment_repo->update($assignment);
62  }
63 
64 
65  protected function getRootPrg()
66  {
67  return $this->mock_tree[1]['prg'];
68  }
69 
70  protected function setPointsForNode(int $node_id, int $points)
71  {
73  $this->settings_repo->update($this->settings_repo->get($node_id)->withAssessmentSettings($set));
74  $this->progress_repo->update($this->progress_repo->get($node_id)->withAmountOfPoints($points));
75 
76  $this->assertEquals($points, $this->mock_tree[$node_id]['prg']->getPoints());
77  }
78 
79  protected function setModeForNode(int $node_id, int $mode)
80  {
81  $set = $this->settings_repo->get($node_id)->setLPMode($mode);
82  $this->settings_repo->update($set);
83  }
84 
85  //this is a meta-test to assure that this setup is working properly
86  public function testInternalTreeIntegrity()
87  {
88  $progress = $this->progress_repo->get(111);
89  $parent = $this->getRootPrg()->getParentProgress($progress);
90  $this->assertEquals(111, $progress->getNodeId());
91  $this->assertEquals(11, $parent->getNodeId());
92  $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $parent->getStatus());
93  $this->progress_repo->update(
94  $parent->withStatus(ilStudyProgrammeProgress::STATUS_FAILED)
95  );
96  $progress = $this->progress_repo->get(112);
97  $parent = $this->getRootPrg()->getParentProgress($progress);
98  $this->assertEquals(11, $parent->getNodeId());
99  $this->assertEquals(ilStudyProgrammeProgress::STATUS_FAILED, $parent->getStatus());
100 
101  $progress = $this->progress_repo->get(11);
102  $this->assertEquals(
103  [
104  $this->progress_repo->get(111),
105  $this->progress_repo->get(112)
106  ],
107  $this->getRootPrg()->getChildrenProgress($progress)
108  );
109  }
110 
111  //this is another meta-test to assure that there are no unwanted side-effects in the repos
112  public function testInternalRunIntegrity()
113  {
114  $progress = $this->progress_repo->get(11);
115  $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $progress->getStatus());
116  }
117 
118 
127  public function testParentAcquisition()
128  {
129  $progress = $this->getRootPrg()
130  ->testUpdateParentProgress($this->progress_repo->get(112));
131  $this->assertEquals($this->progress_repo->get(1), $progress);
132 
133  $progress = $this->getRootPrg()
134  ->testUpdateParentProgress($this->progress_repo->get(13));
135  $this->assertEquals($this->progress_repo->get(1), $progress);
136  }
137 
147  {
148  $this->setPointsForNode(111, 5);
149  $this->setPointsForNode(112, 10);
150  $this->setPointsForNode(11, 8);
151  $this->setPointsForNode(1, 1);
152  $this->setPointsForNode(12, 12);
153  $this->setPointsForNode(13, 10);
154 
155  $this->assertEquals(
156  15, //111+112
157  $this->getRootPrg()->getPossiblePointsOfRelevantChildren(
158  $this->progress_repo->get(11)
159  )
160  );
161 
162  $this->assertEquals(
163  30, //11+12+13
164  $this->getRootPrg()->getPossiblePointsOfRelevantChildren(
165  $this->progress_repo->get(1)
166  )
167  );
168 
169  $this->getRootPrg()->markNotRelevant(12, 6, $this->messages);
170  $this->getRootPrg()->markNotRelevant(112, 6, $this->messages);
171 
172  $this->assertEquals(
173  5, //111 (w/o + 112)
174  $this->getRootPrg()->getPossiblePointsOfRelevantChildren(
175  $this->progress_repo->get(11)
176  )
177  );
178 
179  $this->assertEquals(
180  18,
181  $this->getRootPrg()->getPossiblePointsOfRelevantChildren(
182  $this->progress_repo->get(1)
183  )
184  );
185  }
186 
195  public function testAchievedPoints()
196  {
197  $this->setPointsForNode(111, 5);
198  $this->setPointsForNode(112, 10);
199  $this->setPointsForNode(11, 8);
200  $this->setPointsForNode(1, 1);
201  $this->setPointsForNode(12, 12);
202  $this->setPointsForNode(13, 10);
203  $prg = $this->getRootPrg();
204 
205  $this->assertEquals(0, $prg->getAchievedPointsOfChildren($this->progress_repo->get(12)));
206  $this->assertEquals(0, $prg->getAchievedPointsOfChildren($this->progress_repo->get(11)));
207  $this->assertEquals(0, $prg->getAchievedPointsOfChildren($this->progress_repo->get(1)));
208 
209  $prg->markAccredited(12, 6, $this->messages);
210  $prg->markAccredited(13, 6, $this->messages);
211  $this->assertEquals(22, $prg->getAchievedPointsOfChildren($this->progress_repo->get(1)));
212  $this->assertEquals(22, $this->progress_repo->get(1)->getCurrentAmountOfPoints());
213 
214  $prg->markAccredited(111, 6, $this->messages);
215  $this->assertEquals(5, $prg->getAchievedPointsOfChildren($this->progress_repo->get(11)));
216  }
217 
218 
229  {
230  $this->setPointsForNode(111, 5);
231  $this->setPointsForNode(112, 7);
232  $this->setPointsForNode(11, 12);
233  $this->setPointsForNode(1, 5);
234 
235  $this->getRootPrg()->markAccredited(111, 6, $this->messages);
236  $this->getRootPrg()->markAccredited(112, 6, $this->messages);
237 
238  $this->assertEquals(5, $this->progress_repo->get(111)->getCurrentAmountOfPoints());
239  $this->assertEquals(7, $this->progress_repo->get(112)->getCurrentAmountOfPoints());
240  $this->assertEquals(12, $this->progress_repo->get(11)->getCurrentAmountOfPoints());
241  $this->assertEquals(12, $this->progress_repo->get(1)->getCurrentAmountOfPoints());
242 
243  $this->assertEquals(
244  16,
245  $this->getRootPrg()->getPossiblePointsOfRelevantChildren(
246  $this->progress_repo->get(1)
247  )
248  );
249  $this->assertEquals(
250  12,
251  $this->getRootPrg()->getAchievedPointsOfChildren(
252  $this->progress_repo->get(1)
253  )
254  );
255 
256  $this->assertEquals(ilStudyProgrammeProgress::STATUS_ACCREDITED, $this->progress_repo->get(111)->getStatus());
257  $this->assertEquals(ilStudyProgrammeProgress::STATUS_ACCREDITED, $this->progress_repo->get(112)->getStatus());
258  $this->assertEquals(ilStudyProgrammeProgress::STATUS_COMPLETED, $this->progress_repo->get(11)->getStatus());
259  $this->assertEquals(ilStudyProgrammeProgress::STATUS_COMPLETED, $this->progress_repo->get(1)->getStatus());
260  }
261 
267  public function testMarkAccreditedOnLPNode()
268  {
269  $this->setPointsForNode(1, 10);
270  $this->setPointsForNode(11, 5);
271  $this->setPointsForNode(12, 5);
273  $this->mock_tree = [
274  1 => $this->mock_tree[1],
275  11 => $this->mock_tree[13],
276  12 => $this->mock_tree[12]
277  ];
278 
279  $this->getRootPrg()->markAccredited(11, 6, $this->messages);
280  $this->assertEquals(ilStudyProgrammeProgress::STATUS_ACCREDITED, $this->progress_repo->get(11)->getStatus());
281  $this->assertEquals(5, $this->progress_repo->get(11)->getCurrentAmountOfPoints());
282  $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $this->progress_repo->get(12)->getStatus());
283  $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $this->progress_repo->get(1)->getStatus());
284 
285  $this->getRootPrg()->markAccredited(12, 6, $this->messages);
286  $this->assertEquals(ilStudyProgrammeProgress::STATUS_ACCREDITED, $this->progress_repo->get(11)->getStatus());
287  $this->assertEquals(ilStudyProgrammeProgress::STATUS_ACCREDITED, $this->progress_repo->get(12)->getStatus());
288  $this->assertEquals(ilStudyProgrammeProgress::STATUS_COMPLETED, $this->progress_repo->get(1)->getStatus());
289  $this->assertEquals(5, $this->progress_repo->get(11)->getCurrentAmountOfPoints());
290  $this->assertEquals(5, $this->progress_repo->get(12)->getCurrentAmountOfPoints());
291  $this->assertEquals(10, $this->progress_repo->get(1)->getCurrentAmountOfPoints());
292  }
293 
303  {
304  $this->progress_repo->update(
305  $this->progress_repo->get(11)->withStatus(ilStudyProgrammeProgress::STATUS_NOT_RELEVANT)
306  );
307 
308  $this->getRootPrg()->markAccredited(111, 6, $this->messages);
309  $this->getRootPrg()->markAccredited(112, 6, $this->messages);
310  $this->assertEquals(ilStudyProgrammeProgress::STATUS_ACCREDITED, $this->progress_repo->get(111)->getStatus());
311  $this->assertEquals(ilStudyProgrammeProgress::STATUS_ACCREDITED, $this->progress_repo->get(112)->getStatus());
312  $this->assertEquals(ilStudyProgrammeProgress::STATUS_NOT_RELEVANT, $this->progress_repo->get(11)->getStatus());
313  $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $this->progress_repo->get(1)->getStatus());
314  $this->assertEquals(0, $this->progress_repo->get(1)->getCurrentAmountOfPoints());
315  }
316 
318  {
319  $this->progress_repo->update(
320  $this->progress_repo->get(11)->withStatus(ilStudyProgrammeProgress::STATUS_NOT_RELEVANT)
321  );
322 
323  $this->getRootPrg()->markAccredited(111, 6, $this->messages);
324  $this->getRootPrg()->markAccredited(112, 6, $this->messages);
325  $this->assertEquals(0, $this->progress_repo->get(1)->getCurrentAmountOfPoints());
326 
327  $this->getRootPrg()->markRelevant(11, 6, $this->messages);
328  $this->assertEquals(ilStudyProgrammeProgress::STATUS_COMPLETED, $this->progress_repo->get(11)->getStatus());
329  $this->assertEquals(2, $this->progress_repo->get(1)->getCurrentAmountOfPoints());
330 
331  $this->getRootPrg()->markNotRelevant(11, 6, $this->messages);
332  $this->assertEquals(ilStudyProgrammeProgress::STATUS_COMPLETED, $this->progress_repo->get(11)->getStatus());
333  $this->assertEquals(ilStudyProgrammeProgress::STATUS_ACCREDITED, $this->progress_repo->get(111)->getStatus());
334  $this->assertEquals(2, $this->progress_repo->get(1)->getCurrentAmountOfPoints());
335  }
336 
337  /*
338  ── 1 (6 points)
339  ├── 11 (4 points)
340  │ ├── 111 (LP-Mode, 2 points) <-- succeed
341  │ └── 112 (accredited, 3 points)
342  ├── 12 (2 points)
343  └── 13 (accredited, 2 points)
344  */
346  {
347  $this->setPointsForNode(1, 6);
348  $this->setPointsForNode(11, 4);
349  $this->setPointsForNode(112, 3);
351 
352  $this->mock_tree[112]['prg']->markAccredited(112, 6, $this->messages);
353  $this->mock_tree[12]['prg']->markAccredited(13, 6, $this->messages);
354  $triggering_obj_id = 9001;
355  $this->mock_tree[111]['prg']->succeed(111, $triggering_obj_id);
356 
357  $this->assertEquals(ilStudyProgrammeProgress::STATUS_COMPLETED, $this->progress_repo->get(111)->getStatus());
358  $this->assertEquals(2, $this->progress_repo->get(111)->getCurrentAmountOfPoints());
359 
360  $this->assertEquals(ilStudyProgrammeProgress::STATUS_COMPLETED, $this->progress_repo->get(11)->getStatus());
361  $this->assertEquals(5, $this->progress_repo->get(11)->getCurrentAmountOfPoints());
362 
363  $this->assertEquals(ilStudyProgrammeProgress::STATUS_COMPLETED, $this->progress_repo->get(1)->getStatus());
364  $this->assertEquals(6, $this->progress_repo->get(1)->getCurrentAmountOfPoints());
365  }
366 
367  /*
368  ── 1 (6 points)
369  ├── 11 (accredited, 2 points)
370  │ ├── 111
371  │ └── 112
372  ├── 12 (2 points)
373  └── 13 (accredited, 2 points)
374  */
376  {
377  $this->setPointsForNode(1, 6);
378  $this->getRootPrg()->markAccredited(11, 6, $this->messages);
379  $this->getRootPrg()->markAccredited(13, 6, $this->messages);
380 
381  $this->assertEquals(4, $this->progress_repo->get(1)->getCurrentAmountOfPoints());
382  $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $this->progress_repo->get(1)->getStatus());
383 
384  $this->getRootPrg()->markNotRelevant(12, 6, $this->messages);
385 
386  $this->assertEquals(4, $this->progress_repo->get(1)->getCurrentAmountOfPoints());
387  $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $this->progress_repo->get(1)->getStatus());
388  }
389 
390 
391  public function testFailByDeadline()
392  {
393  $past = DateTimeImmutable::createFromFormat('Ymd', '20010101');
394  $progress = $this->progress_repo->get(13)->withDeadline($past);
395 
396  $progress = $this->getRootPrg()->testApplyProgressDeadline($progress);
397 
398  $this->assertEquals(
400  $progress->getStatus()
401  );
402  }
403 
405  {
406  $progress = $this->progress_repo->get(13);
407  $future = (new DateTimeImmutable())->add(new DateInterval('P1D'));
408  $progress = $this->getRootPrg()->testApplyProgressDeadline(
409  $progress->withDeadline($future)
410  );
411 
412  $this->assertEquals(
414  $progress->getStatus()
415  );
416  }
417 
419  {
420  $progress = $this->progress_repo->get(13)
422  $this->progress_repo->update($progress);
423 
424  $past = DateTimeImmutable::createFromFormat('Ymd', '20010101');
425  $progress = $this->getRootPrg()->testApplyProgressDeadline(
426  $progress->withDeadline($past)
427  );
428 
429  $this->assertEquals(
431  $progress->getStatus()
432  );
433  }
434 
435  public function testChangingDeadline()
436  {
437  $past = DateTimeImmutable::createFromFormat('Ymd', '20010101');
438  $this->getRootPrg()->changeProgressDeadline(12, 6, $this->messages, $past);
439 
440  $this->assertEquals(
442  $this->progress_repo->get(12)->getStatus()
443  );
444  }
445 
447  {
448  $this->progress_repo->update(
449  $this->progress_repo->get(12)
451  );
452 
453  $past = DateTimeImmutable::createFromFormat('Ymd', '20010101');
454  $this->getRootPrg()->changeProgressDeadline(12, 6, $this->messages, $past);
455 
456  $progress = $this->progress_repo->get(12);
457  $this->assertEquals($progress->getStatus(), ilStudyProgrammeProgress::STATUS_COMPLETED);
458  $this->assertNull($progress->getDeadline());
459  }
460 
462  {
463  $past = DateTimeImmutable::createFromFormat('Ymd', '20010101');
464  $this->progress_repo->update(
465  $this->progress_repo->get(11)
467  ->withDeadline($past)
468  );
469 
470  $this->getRootPrg()->unmarkAccredited(11, 6, $this->messages);
471 
472  $this->assertEquals(
474  $this->progress_repo->get(11)->getStatus()
475  );
476  }
477 
478  public function testChangingValidity()
479  {
480  $future = (new DateTimeImmutable())->add(new DateInterval('P1D'));
481  $this->progress_repo->update(
482  $this->progress_repo->get(1)
484  );
485 
486  $this->getRootPrg()->changeProgressValidityDate(1, 6, $this->messages, $future);
487  $this->assertEquals(
488  $future,
489  $this->progress_repo->get(1)->getValidityOfQualification()
490  );
491  }
492 
494  {
495  $future = (new DateTimeImmutable())->add(new DateInterval('P1D'));
496  $this->progress_repo->update(
497  $this->progress_repo->get(1)
499  );
500  $this->getRootPrg()->changeProgressValidityDate(1, 6, $this->messages, $future);
501  $this->assertNull($this->progress_repo->get(1)->getValidityOfQualification());
502  }
503 
504  public function testMarkAsIndividual()
505  {
506  $this->assertFalse($this->progress_repo->get(11)->hasIndividualModifications());
507 
508  $this->getRootPrg()->markNotRelevant(11, 6, $this->messages);
509  $this->assertTrue($this->progress_repo->get(11)->hasIndividualModifications());
510 
511  $future = (new DateTimeImmutable())->add(new DateInterval('P1D'));
512 
513  $this->getRootPrg()->changeProgressDeadline(12, 6, $this->messages, $future);
514  $this->assertTrue($this->progress_repo->get(12)->hasIndividualModifications());
515 
516  $this->getRootPrg()->changeProgressValidityDate(13, 6, $this->messages, $future);
517  $this->assertFalse($this->progress_repo->get(13)->hasIndividualModifications());
518  }
519 
521  {
522  $future = (new DateTimeImmutable())->add(new DateInterval('P1D'));
523  $prg = $this->getRootPrg();
524  $prg->tree = $this->mock_tree;
525 
526  $prg->changeProgressDeadline(12, 6, $this->messages, $future);
527  $this->assertTrue($this->progress_repo->get(12)->hasIndividualModifications());
528  $prg->updatePlanFromRepository(12, 6);
529  $this->assertFalse($this->progress_repo->get(12)->hasIndividualModifications());
530  }
531 
532  public function testUpdatePlanFromSettings()
533  {
534  $future = (new DateTime())->add(new DateInterval('P1D'));
535  $future2 = (new DateTime())->add(new DateInterval('P4D'));
536  $points = 73;
537 
538  $set_dl = new ilStudyProgrammeDeadlineSettings(null, $future);
539  $set_vq = new ilStudyProgrammeValidityOfAchievedQualificationSettings(null, $future2, null);
541 
542  foreach ([1,11,111] as $id) {
543  $settings = $this->mock_tree[$id]['prg']->getSettings()
544  ->withDeadlineSettings($set_dl)
545  ->withValidityOfQualificationSettings($set_vq)
546  ->withAssessmentSettings($set_as);
547 
548  $this->mock_tree[$id]['prg']->updateSettings($settings);
549  $progress = $this->progress_repo->get($id)
550  ->withAmountOfPoints(69)
551  ->withDeadline(DateTimeImmutable::createFromMutable($future2))
552  ->withValidityOfQualification(DateTimeImmutable::createFromMutable($future));
553  $progress = $progress->markAccredited(
554  new DateTimeImmutable(),
555  6
556  );
557 
558  $this->progress_repo->update($progress);
559  $progress = $this->progress_repo->get($id);
560  $this->assertEquals($future2, $progress->getDeadline());
561  $this->assertEquals($future, $progress->getValidityOfQualification());
562  $this->assertEquals(69, $progress->getAmountOfPoints());
563 
564  $prg = $this->getRootPrg();
565  $prg->tree = &$this->mock_tree;
566  }
567 
568  $this->getRootPrg()->updatePlanFromRepository(11, 6);
569 
570  foreach ([1,11,111] as $prg_id) {
571  $progress = $this->progress_repo->get($prg_id);
572  $this->assertEquals($points, $progress->getAmountOfPoints());
573  $this->assertEquals($future, $progress->getDeadline());
574  }
575  }
576 }
testMarkAccreditedShouldNotChangeIrrelevantParent()
── 1 ├── 11 (irrelevant) │ ├── 111 │ └── 112 ├── 12 └── 13
add()
Definition: add.php:2
testMarkAccreditedOnLPNode()
── 1 (10) ├── 11 (5, LP) └── 12 (5)
Represents one assignment of the user to a program tree.
testMarkAccreditedShouldCompleteParentBySufficientPoints()
PRG: MODE_POINTS ── 1 (5) ├── 11 (12) │ ├── 111 (5) │ └── 112 (7) ├── 12 (2) └── 1...
testParentAcquisition()
── 1 ├── 11 │ ├── 111 │ └── 112 ├── 12 └── 13
Class ilStudyProgrammeProgress.
testAchievedPoints()
── 1 (1) ├── 11 (8) │ ├── 111 (5) │ └── 112 (10) ├── 12 (12) └── 13 (10) ...
testChildrenPossiblePointsAddition()
── 1 (1) ├── 11 (8) │ ├── 111 (5) │ └── 112 (10) <– turns irrelevant ├── 12 (12) <–...
Holds information about multi-actions, mainly in context of member-assignemnts and status changes...