ILIAS  release_8 Revision v8.24
ilStudyProgrammeProgressTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21require_once(__DIR__ . "/../../../../../libs/composer/vendor/autoload.php");
22
24
25class ilStudyProgrammeProgressTest extends \PHPUnit\Framework\TestCase
26{
27 protected $backupGlobals = false;
28
29 public function testPRGProgressInitAndId(): void
30 {
31 $pgs = new ilPRGProgress(123);
32 $this->assertInstanceOf(Node::class, $pgs);
33 $this->assertEquals($pgs->getNodeId(), 123);
34 }
35
36 public function testPRGProgressProperties(): void
37 {
38 $pgs = (new ilPRGProgress(123))
40 $dat = DateTimeImmutable::createFromFormat('Ymd', '20221024');
41
42 $this->assertEquals($pgs->withAmountOfPoints(12)->getAmountOfPoints(), 12);
43 $this->assertEquals($pgs->withCurrentAmountOfPoints(8)->getCurrentAmountOfPoints(), 8);
44
45 $this->assertEquals($pgs->withStatus(ilPRGProgress::STATUS_COMPLETED)->getStatus(), ilPRGProgress::STATUS_COMPLETED);
46 $pgs = $pgs->withLastChange(6, $dat);
47 $this->assertEquals($pgs->getLastChangeBy(), 6);
48 $this->assertEquals($pgs->getLastChange(), $dat);
49 $this->assertEquals($pgs->withAssignmentDate($dat)->getAssignmentDate(), $dat);
50 $pgs = $pgs->withCompletion(6, $dat);
51 $this->assertEquals($pgs->getCompletionBy(), 6);
52 $this->assertEquals($pgs->getCompletionDate(), $dat);
53 $this->assertEquals($pgs->withDeadline($dat)->getDeadline(), $dat);
54 $this->assertEquals($pgs->withValidityOfQualification($dat)->getValidityOfQualification(), $dat);
55 $this->assertTrue($pgs->withIndividualModifications(true)->hasIndividualModifications());
56 }
57
58 public function testPRGProgressStatusChecker(): void
59 {
60 $pgs = (new ilPRGProgress(444))
62 $this->assertTrue($pgs->isRelevant());
63 $this->assertTrue($pgs->withStatus(ilPRGProgress::STATUS_ACCREDITED)->isSuccessful());
64 $this->assertFalse($pgs->withStatus(ilPRGProgress::STATUS_FAILED)->isSuccessful());
65 $this->assertFalse($pgs->withStatus(ilPRGProgress::STATUS_NOT_RELEVANT)->isRelevant());
66 $this->assertFalse($pgs->isAccredited());
67 $this->assertTrue($pgs->withStatus(ilPRGProgress::STATUS_ACCREDITED)->isAccredited());
68 }
69
71 {
72 $today = new DateTimeImmutable();
73 $yesterday = $today->sub(new DateInterval('P1D'));
74 $tomorrow = $today->add(new DateInterval('P1D'));
75
76 $pgs = (new ilPRGProgress(555))
78 ->withValidityOfQualification($today);
79
80 $this->assertNull($pgs->hasValidQualification($today));
81
82 $pgs = $pgs->withStatus(ilPRGProgress::STATUS_COMPLETED);
83 $this->assertTrue($pgs->hasValidQualification($yesterday));
84 $this->assertTrue($pgs->hasValidQualification($today));
85 $this->assertFalse($pgs->hasValidQualification($tomorrow));
86 }
87
88 public function testPRGProgressInvalidation(): void
89 {
90 $today = new DateTimeImmutable();
91 $yesterday = $today->sub(new DateInterval('P1D'));
92
93 $pgs = (new ilPRGProgress(666))
96 ->withValidityOfQualification($today);
97 $this->assertFalse($pgs->isInvalidated());
98
99 $pgs = $pgs
100 ->withValidityOfQualification($yesterday)
101 ->invalidate();
102 $this->assertTrue($pgs->isInvalidated());
103 }
104
106 {
107 $this->expectException(\ilException::class);
108 $today = new DateTimeImmutable();
109 $tomorrow = $today->add(new DateInterval('P1D'));
110 $pgs = (new ilPRGProgress(777))
112 ->withValidityOfQualification($tomorrow)
113 ->invalidate();
114 }
115
117 {
118 $usr = 6;
119 $now = new DateTimeImmutable();
120 $pgs = (new ilPRGProgress(123))
122
123 $pgs = $pgs->markAccredited($now, $usr);
124 $this->assertEquals($now, $pgs->getCompletionDate());
125 $this->assertEquals($usr, $pgs->getCompletionBy());
126 $this->assertEquals($usr, $pgs->getLastChangeBy());
127 $this->assertEquals(
129 $pgs->getLastChange()->format(ilPRGProgress::DATE_TIME_FORMAT)
130 );
131 $this->assertEquals(ilPRGProgress::STATUS_ACCREDITED, $pgs->getStatus());
132 }
133
135 {
136 $usr = 6;
137 $now = new DateTimeImmutable();
138 $pgs = (new ilPRGProgress(123))
140
141 $pgs = $pgs->unmarkAccredited($now, $usr);
142 $this->assertNull($pgs->getCompletionDate());
143 $this->assertNull($pgs->getCompletionBy());
144 $this->assertNull($pgs->getValidityOfQualification());
145 $this->assertEquals($usr, $pgs->getLastChangeBy());
146 $this->assertEquals(
148 $pgs->getLastChange()->format(ilPRGProgress::DATE_TIME_FORMAT)
149 );
150 $this->assertEquals(ilPRGProgress::STATUS_IN_PROGRESS, $pgs->getStatus());
151 }
152
154 {
155 $usr = 6;
156 $now = new DateTimeImmutable();
157 $pgs = (new ilPRGProgress(123))
159
160 $pgs = $pgs->markFailed($now, $usr);
161 $this->assertNull($pgs->getCompletionDate());
162 $this->assertNull($pgs->getCompletionBy());
163 $this->assertEquals($usr, $pgs->getLastChangeBy());
164 $this->assertEquals(
166 $pgs->getLastChange()->format(ilPRGProgress::DATE_TIME_FORMAT)
167 );
168 $this->assertEquals(ilPRGProgress::STATUS_FAILED, $pgs->getStatus());
169 }
170
172 {
173 $usr = 6;
174 $now = new DateTimeImmutable();
175 $pgs = (new ilPRGProgress(123))
177
178 $pgs = $pgs->markNotFailed($now, $usr);
179 $this->assertNull($pgs->getCompletionDate());
180 $this->assertNull($pgs->getCompletionBy());
181 $this->assertEquals($usr, $pgs->getLastChangeBy());
182 $this->assertEquals(
184 $pgs->getLastChange()->format(ilPRGProgress::DATE_TIME_FORMAT)
185 );
186 $this->assertEquals(ilPRGProgress::STATUS_IN_PROGRESS, $pgs->getStatus());
187 }
188
190 {
191 $usr = 6;
192 $now = new DateTimeImmutable();
193 $pgs = (new ilPRGProgress(123))
195
196 $pgs = $pgs->succeed($now, $usr);
197 $this->assertEquals($now, $pgs->getCompletionDate());
198 $this->assertEquals($usr, $pgs->getCompletionBy());
199 $this->assertEquals($usr, $pgs->getLastChangeBy());
200 $this->assertEquals(
202 $pgs->getLastChange()->format(ilPRGProgress::DATE_TIME_FORMAT)
203 );
204 $this->assertEquals(ilPRGProgress::STATUS_COMPLETED, $pgs->getStatus());
205 }
206
208 {
209 $usr = 6;
210 $now = new DateTimeImmutable();
211 $pgs = (new ilPRGProgress(123))
213
214 $pgs = $pgs->markRelevant($now, $usr);
215 $this->assertNull($pgs->getCompletionBy());
216 $this->assertEquals($usr, $pgs->getLastChangeBy());
217 $this->assertEquals(
219 $pgs->getLastChange()->format(ilPRGProgress::DATE_TIME_FORMAT)
220 );
221 $this->assertEquals(ilPRGProgress::STATUS_IN_PROGRESS, $pgs->getStatus());
222 $this->assertTrue($pgs->hasIndividualModifications());
223 }
224
226 {
227 $usr = 6;
228 $now = new DateTimeImmutable();
229 $pgs = (new ilPRGProgress(123))
231
232 $pgs = $pgs->markNotRelevant($now, $usr);
233 $this->assertNull($pgs->getCompletionBy());
234 $this->assertEquals($usr, $pgs->getLastChangeBy());
235 $this->assertEquals(
237 $pgs->getLastChange()->format(ilPRGProgress::DATE_TIME_FORMAT)
238 );
239 $this->assertEquals(ilPRGProgress::STATUS_NOT_RELEVANT, $pgs->getStatus());
240 $this->assertTrue($pgs->hasIndividualModifications());
241 }
242
243 public function status(): array
244 {
245 return [
246 //status, count as 'successful'
252 ];
253 }
254
255 public function testPRGProgressInvalidStatus(): void
256 {
257 $this->expectException(\ilException::class);
258 $pgs = (new ilPRGProgress(123))->withStatus(777);
259 }
260
264 public function testPRGProgressAllowedTransitionsForInProgress(int $status): void
265 {
266 $pgs = (new ilPRGProgress(123))->withStatus(ilPRGProgress::STATUS_IN_PROGRESS);
267 if (in_array($status, [
272 $pgs->getStatus()
273 ])) {
274 $this->assertTrue($pgs->isTransitionAllowedTo($status));
275 } else {
276 $this->assertFalse($pgs->isTransitionAllowedTo($status));
277 }
278 }
279
284 {
285 $pgs = (new ilPRGProgress(123))
288 if (in_array($status, [
293 $pgs->getStatus()
294 ])) {
295 $this->assertTrue($pgs->isTransitionAllowedTo($status));
296 } else {
297 $this->assertFalse($pgs->isTransitionAllowedTo($status));
298 }
299 }
300
305 {
306 $pgs = (new ilPRGProgress(123))
309 if (in_array($status, [
312 $pgs->getStatus()
313 ])) {
314 $this->assertTrue($pgs->isTransitionAllowedTo($status));
315 } else {
316 $this->assertFalse($pgs->isTransitionAllowedTo($status));
317 }
318 }
319
324 {
325 $pgs = (new ilPRGProgress(123))
327 ->withStatus(ilPRGProgress::STATUS_FAILED);
328 if (in_array($status, [
332 $pgs->getStatus()
333 ])) {
334 $this->assertTrue($pgs->isTransitionAllowedTo($status));
335 } else {
336 $this->assertFalse($pgs->isTransitionAllowedTo($status));
337 }
338 }
339
344 {
345 $pgs = (new ilPRGProgress(123))->withStatus(ilPRGProgress::STATUS_NOT_RELEVANT);
347 || $status === $pgs->getStatus()
348 ) {
349 $this->assertTrue($pgs->isTransitionAllowedTo($status));
350 } else {
351 $this->assertFalse($pgs->isTransitionAllowedTo($status));
352 }
353 }
354
355 public function testPRGProgressPointsOfChildren(): void
356 {
357 /*
358 └── 1
359 ├── 11
360 │ ├── 111
361 │ └── 112
362 ├── 12
363 └── 13
364 */
365
367 ->withAmountOfPoints(112);
369 ->withAmountOfPoints(111);
371 ->setSubnodes([$pgs111, $pgs112])
372 ->withAmountOfPoints(11);
374 ->withAmountOfPoints(12);
376 ->withAmountOfPoints(13);
378 ->setSubnodes([$pgs11, $pgs12, $pgs13])
379 ->withAmountOfPoints(1);
380
381 $this->assertEquals(111 + 112, $pgs11->getPossiblePointsOfRelevantChildren());
382 $this->assertEquals(0, $pgs12->getPossiblePointsOfRelevantChildren());
383 $this->assertEquals(11 + 12 + 13 * 0, $pgs1->getPossiblePointsOfRelevantChildren());
384 $this->assertEquals(111 + 112, $pgs11->getAchievedPointsOfChildren());
385 $this->assertEquals(0, $pgs1->getAchievedPointsOfChildren());
386 }
387}
A Progress is the status of a user on a single node of an assignment; it is unique by assignment_id:u...
testPRGProgressAllowedTransitionsForAccredited($status)
@dataProvider status
testPRGProgressAllowedTransitionsForIrrelevant($status)
@dataProvider status
testPRGProgressAllowedTransitionsForCompleted($status)
@dataProvider status
testPRGProgressAllowedTransitionsForFailed($status)
@dataProvider status
testPRGProgressAllowedTransitionsForInProgress(int $status)
@dataProvider status