ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilStudyProgrammeProgressTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 class ilStudyProgrammeProgressTest extends \PHPUnit\Framework\TestCase
24 {
25  protected $backupGlobals = false;
26 
27  public function testPRGProgressInitAndId(): void
28  {
29  $pgs = new ilPRGProgress(123);
30  $this->assertInstanceOf(Node::class, $pgs);
31  $this->assertEquals($pgs->getNodeId(), 123);
32  }
33 
34  public function testPRGProgressProperties(): void
35  {
36  $pgs = (new ilPRGProgress(123))
38  $dat = DateTimeImmutable::createFromFormat('Ymd', '20221024');
39 
40  $this->assertEquals($pgs->withAmountOfPoints(12)->getAmountOfPoints(), 12);
41  $this->assertEquals($pgs->withCurrentAmountOfPoints(8)->getCurrentAmountOfPoints(), 8);
42 
43  $this->assertEquals($pgs->withStatus(ilPRGProgress::STATUS_COMPLETED)->getStatus(), ilPRGProgress::STATUS_COMPLETED);
44  $pgs = $pgs->withLastChange(6, $dat);
45  $this->assertEquals($pgs->getLastChangeBy(), 6);
46  $this->assertEquals($pgs->getLastChange(), $dat);
47  $this->assertEquals($pgs->withAssignmentDate($dat)->getAssignmentDate(), $dat);
48  $pgs = $pgs->withCompletion(6, $dat);
49  $this->assertEquals($pgs->getCompletionBy(), 6);
50  $this->assertEquals($pgs->getCompletionDate(), $dat);
51  $this->assertEquals($pgs->withDeadline($dat)->getDeadline(), $dat);
52  $this->assertEquals($pgs->withValidityOfQualification($dat)->getValidityOfQualification(), $dat);
53  $this->assertTrue($pgs->withIndividualModifications(true)->hasIndividualModifications());
54  }
55 
56  public function testPRGProgressStatusChecker(): void
57  {
58  $pgs = (new ilPRGProgress(444))
60  $this->assertTrue($pgs->isRelevant());
61  $this->assertTrue($pgs->withStatus(ilPRGProgress::STATUS_ACCREDITED)->isSuccessful());
62  $this->assertFalse($pgs->withStatus(ilPRGProgress::STATUS_FAILED)->isSuccessful());
63  $this->assertFalse($pgs->withStatus(ilPRGProgress::STATUS_NOT_RELEVANT)->isRelevant());
64  $this->assertFalse($pgs->isAccredited());
65  $this->assertTrue($pgs->withStatus(ilPRGProgress::STATUS_ACCREDITED)->isAccredited());
66  }
67 
68  public function testPRGProgressHasValidQualification(): void
69  {
70  $today = new DateTimeImmutable();
71  $yesterday = $today->sub(new DateInterval('P1D'));
72  $tomorrow = $today->add(new DateInterval('P1D'));
73 
74  $pgs = (new ilPRGProgress(555))
76  ->withValidityOfQualification($today);
77 
78  $this->assertNull($pgs->hasValidQualification($today));
79 
80  $pgs = $pgs->withStatus(ilPRGProgress::STATUS_COMPLETED);
81  $this->assertTrue($pgs->hasValidQualification($yesterday));
82  $this->assertTrue($pgs->hasValidQualification($today));
83  $this->assertFalse($pgs->hasValidQualification($tomorrow));
84  }
85 
86  public function testPRGProgressInvalidation(): void
87  {
88  $today = new DateTimeImmutable();
89  $yesterday = $today->sub(new DateInterval('P1D'));
90 
91  $pgs = (new ilPRGProgress(666))
94  ->withValidityOfQualification($today);
95  $this->assertFalse($pgs->isInvalidated());
96 
97  $pgs = $pgs
98  ->withValidityOfQualification($yesterday)
99  ->invalidate();
100  $this->assertTrue($pgs->isInvalidated());
101  }
102 
103  public function testPRGProgressInvalidInvalidation(): void
104  {
105  $this->expectException(\ilException::class);
106  $today = new DateTimeImmutable();
107  $tomorrow = $today->add(new DateInterval('P1D'));
108  $pgs = (new ilPRGProgress(777))
109  ->withStatus(ilPRGProgress::STATUS_COMPLETED)
110  ->withValidityOfQualification($tomorrow)
111  ->invalidate();
112  }
113 
115  {
116  $usr = 6;
117  $now = new DateTimeImmutable();
118  $pgs = (new ilPRGProgress(123))
119  ->withStatus(ilPRGProgress::STATUS_IN_PROGRESS);
120 
121  $pgs = $pgs->markAccredited($now, $usr);
122  $this->assertEquals($now, $pgs->getCompletionDate());
123  $this->assertEquals($usr, $pgs->getCompletionBy());
124  $this->assertEquals($usr, $pgs->getLastChangeBy());
125  $this->assertEquals(
126  $now->format(ilPRGProgress::DATE_TIME_FORMAT),
127  $pgs->getLastChange()->format(ilPRGProgress::DATE_TIME_FORMAT)
128  );
129  $this->assertEquals(ilPRGProgress::STATUS_ACCREDITED, $pgs->getStatus());
130  }
131 
133  {
134  $usr = 6;
135  $now = new DateTimeImmutable();
136  $pgs = (new ilPRGProgress(123))
137  ->withStatus(ilPRGProgress::STATUS_IN_PROGRESS);
138 
139  $pgs = $pgs->unmarkAccredited($now, $usr);
140  $this->assertNull($pgs->getCompletionDate());
141  $this->assertNull($pgs->getCompletionBy());
142  $this->assertNull($pgs->getValidityOfQualification());
143  $this->assertEquals($usr, $pgs->getLastChangeBy());
144  $this->assertEquals(
145  $now->format(ilPRGProgress::DATE_TIME_FORMAT),
146  $pgs->getLastChange()->format(ilPRGProgress::DATE_TIME_FORMAT)
147  );
148  $this->assertEquals(ilPRGProgress::STATUS_IN_PROGRESS, $pgs->getStatus());
149  }
150 
152  {
153  $usr = 6;
154  $now = new DateTimeImmutable();
155  $pgs = (new ilPRGProgress(123))
156  ->withStatus(ilPRGProgress::STATUS_IN_PROGRESS);
157 
158  $pgs = $pgs->markFailed($now, $usr);
159  $this->assertNull($pgs->getCompletionDate());
160  $this->assertNull($pgs->getCompletionBy());
161  $this->assertEquals($usr, $pgs->getLastChangeBy());
162  $this->assertEquals(
163  $now->format(ilPRGProgress::DATE_TIME_FORMAT),
164  $pgs->getLastChange()->format(ilPRGProgress::DATE_TIME_FORMAT)
165  );
166  $this->assertEquals(ilPRGProgress::STATUS_FAILED, $pgs->getStatus());
167  }
168 
170  {
171  $usr = 6;
172  $now = new DateTimeImmutable();
173  $pgs = (new ilPRGProgress(123))
174  ->withStatus(ilPRGProgress::STATUS_IN_PROGRESS);
175 
176  $pgs = $pgs->markNotFailed($now, $usr);
177  $this->assertNull($pgs->getCompletionDate());
178  $this->assertNull($pgs->getCompletionBy());
179  $this->assertEquals($usr, $pgs->getLastChangeBy());
180  $this->assertEquals(
181  $now->format(ilPRGProgress::DATE_TIME_FORMAT),
182  $pgs->getLastChange()->format(ilPRGProgress::DATE_TIME_FORMAT)
183  );
184  $this->assertEquals(ilPRGProgress::STATUS_IN_PROGRESS, $pgs->getStatus());
185  }
186 
187  public function testPRGProgressStatusActionsSucceed(): void
188  {
189  $usr = 6;
190  $now = new DateTimeImmutable();
191  $pgs = (new ilPRGProgress(123))
192  ->withStatus(ilPRGProgress::STATUS_IN_PROGRESS);
193 
194  $pgs = $pgs->succeed($now, $usr);
195  $this->assertEquals($now, $pgs->getCompletionDate());
196  $this->assertEquals($usr, $pgs->getCompletionBy());
197  $this->assertEquals($usr, $pgs->getLastChangeBy());
198  $this->assertEquals(
199  $now->format(ilPRGProgress::DATE_TIME_FORMAT),
200  $pgs->getLastChange()->format(ilPRGProgress::DATE_TIME_FORMAT)
201  );
202  $this->assertEquals(ilPRGProgress::STATUS_COMPLETED, $pgs->getStatus());
203  }
204 
206  {
207  $usr = 6;
208  $now = new DateTimeImmutable();
209  $pgs = (new ilPRGProgress(123))
210  ->withStatus(ilPRGProgress::STATUS_IN_PROGRESS);
211 
212  $pgs = $pgs->markRelevant($now, $usr);
213  $this->assertNull($pgs->getCompletionBy());
214  $this->assertEquals($usr, $pgs->getLastChangeBy());
215  $this->assertEquals(
216  $now->format(ilPRGProgress::DATE_TIME_FORMAT),
217  $pgs->getLastChange()->format(ilPRGProgress::DATE_TIME_FORMAT)
218  );
219  $this->assertEquals(ilPRGProgress::STATUS_IN_PROGRESS, $pgs->getStatus());
220  $this->assertTrue($pgs->hasIndividualModifications());
221  }
222 
224  {
225  $usr = 6;
226  $now = new DateTimeImmutable();
227  $pgs = (new ilPRGProgress(123))
228  ->withStatus(ilPRGProgress::STATUS_IN_PROGRESS);
229 
230  $pgs = $pgs->markNotRelevant($now, $usr);
231  $this->assertNull($pgs->getCompletionBy());
232  $this->assertEquals($usr, $pgs->getLastChangeBy());
233  $this->assertEquals(
234  $now->format(ilPRGProgress::DATE_TIME_FORMAT),
235  $pgs->getLastChange()->format(ilPRGProgress::DATE_TIME_FORMAT)
236  );
237  $this->assertEquals(ilPRGProgress::STATUS_NOT_RELEVANT, $pgs->getStatus());
238  $this->assertTrue($pgs->hasIndividualModifications());
239  }
240 
241  public static function ilPRGProgressStatus(): array
242  {
243  return [
244  //status, count as 'successful'
250  ];
251  }
252 
253  public function testPRGProgressInvalidStatus(): void
254  {
255  $this->expectException(\ilException::class);
256  $pgs = (new ilPRGProgress(123))->withStatus(777);
257  }
258 
262  public function testPRGProgressAllowedTransitionsForInProgress(int $status): void
263  {
264  $pgs = (new ilPRGProgress(123))->withStatus(ilPRGProgress::STATUS_IN_PROGRESS);
265  if (in_array($status, [
270  $pgs->getStatus()
271  ])) {
272  $this->assertTrue($pgs->isTransitionAllowedTo($status));
273  } else {
274  $this->assertFalse($pgs->isTransitionAllowedTo($status));
275  }
276  }
277 
282  {
283  $pgs = (new ilPRGProgress(123))
285  ->withStatus(ilPRGProgress::STATUS_ACCREDITED);
286  if (in_array($status, [
291  $pgs->getStatus()
292  ])) {
293  $this->assertTrue($pgs->isTransitionAllowedTo($status));
294  } else {
295  $this->assertFalse($pgs->isTransitionAllowedTo($status));
296  }
297  }
298 
303  {
304  $pgs = (new ilPRGProgress(123))
306  ->withStatus(ilPRGProgress::STATUS_COMPLETED);
307  if (in_array($status, [
310  $pgs->getStatus()
311  ])) {
312  $this->assertTrue($pgs->isTransitionAllowedTo($status));
313  } else {
314  $this->assertFalse($pgs->isTransitionAllowedTo($status));
315  }
316  }
317 
322  {
323  $pgs = (new ilPRGProgress(123))
325  ->withStatus(ilPRGProgress::STATUS_FAILED);
326  if (in_array($status, [
330  $pgs->getStatus()
331  ])) {
332  $this->assertTrue($pgs->isTransitionAllowedTo($status));
333  } else {
334  $this->assertFalse($pgs->isTransitionAllowedTo($status));
335  }
336  }
337 
341  public function testPRGProgressAllowedTransitionsForIrrelevant($status): void
342  {
343  $pgs = (new ilPRGProgress(123))->withStatus(ilPRGProgress::STATUS_NOT_RELEVANT);
344  if ($status === ilPRGProgress::STATUS_IN_PROGRESS
345  || $status === $pgs->getStatus()
346  ) {
347  $this->assertTrue($pgs->isTransitionAllowedTo($status));
348  } else {
349  $this->assertFalse($pgs->isTransitionAllowedTo($status));
350  }
351  }
352 
353  public function testPRGProgressPointsOfChildren(): void
354  {
355  /*
356  └── 1
357  ├── 11
358  │ ├── 111
359  │ └── 112
360  ├── 12
361  └── 13
362  */
363 
364  $pgs112 = (new ilPRGProgress(112, ilPRGProgress::STATUS_COMPLETED))
365  ->withAmountOfPoints(112);
366  $pgs111 = (new ilPRGProgress(111, ilPRGProgress::STATUS_COMPLETED))
367  ->withAmountOfPoints(111);
369  ->setSubnodes([$pgs111, $pgs112])
370  ->withAmountOfPoints(11);
372  ->withAmountOfPoints(12);
374  ->withAmountOfPoints(13);
376  ->setSubnodes([$pgs11, $pgs12, $pgs13])
377  ->withAmountOfPoints(1);
378 
379  $this->assertEquals(111 + 112, $pgs11->getPossiblePointsOfRelevantChildren());
380  $this->assertEquals(0, $pgs12->getPossiblePointsOfRelevantChildren());
381  $this->assertEquals(11 + 12 + 13 * 0, $pgs1->getPossiblePointsOfRelevantChildren());
382  $this->assertEquals(111 + 112, $pgs11->getAchievedPointsOfChildren());
383  $this->assertEquals(0, $pgs1->getAchievedPointsOfChildren());
384  }
385 }
testPRGProgressAllowedTransitionsForFailed($status)
ilPRGProgressStatus
testPRGProgressAllowedTransitionsForAccredited($status)
ilPRGProgressStatus
testPRGProgressAllowedTransitionsForCompleted($status)
ilPRGProgressStatus
A Progress is the status of a user on a single node of an assignment; it is unique by assignment_id:u...
testPRGProgressAllowedTransitionsForIrrelevant($status)
ilPRGProgressStatus
testPRGProgressAllowedTransitionsForInProgress(int $status)
ilPRGProgressStatus