ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilStudyProgrammeProgressTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23class 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
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
104 {
105 $this->expectException(\ilException::class);
106 $today = new DateTimeImmutable();
107 $tomorrow = $today->add(new DateInterval('P1D'));
108 $pgs = (new ilPRGProgress(777))
110 ->withValidityOfQualification($tomorrow)
111 ->invalidate();
112 }
113
115 {
116 $usr = 6;
117 $now = new DateTimeImmutable();
118 $pgs = (new ilPRGProgress(123))
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(
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))
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(
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))
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(
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))
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(
182 $pgs->getLastChange()->format(ilPRGProgress::DATE_TIME_FORMAT)
183 );
184 $this->assertEquals(ilPRGProgress::STATUS_IN_PROGRESS, $pgs->getStatus());
185 }
186
188 {
189 $usr = 6;
190 $now = new DateTimeImmutable();
191 $pgs = (new ilPRGProgress(123))
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(
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))
211
212 $pgs = $pgs->markRelevant($now, $usr);
213 $this->assertNull($pgs->getCompletionBy());
214 $this->assertEquals($usr, $pgs->getLastChangeBy());
215 $this->assertEquals(
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))
229
230 $pgs = $pgs->markNotRelevant($now, $usr);
231 $this->assertNull($pgs->getCompletionBy());
232 $this->assertEquals($usr, $pgs->getLastChangeBy());
233 $this->assertEquals(
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
259 #[\PHPUnit\Framework\Attributes\DataProvider('ilPRGProgressStatus')]
260 public function testPRGProgressAllowedTransitionsForInProgress(int $status): void
261 {
262 $pgs = (new ilPRGProgress(123))->withStatus(ilPRGProgress::STATUS_IN_PROGRESS);
263 if (in_array($status, [
268 $pgs->getStatus()
269 ])) {
270 $this->assertTrue($pgs->isTransitionAllowedTo($status));
271 } else {
272 $this->assertFalse($pgs->isTransitionAllowedTo($status));
273 }
274 }
275
276 #[\PHPUnit\Framework\Attributes\DataProvider('ilPRGProgressStatus')]
278 {
279 $pgs = (new ilPRGProgress(123))
282 if (in_array($status, [
287 $pgs->getStatus()
288 ])) {
289 $this->assertTrue($pgs->isTransitionAllowedTo($status));
290 } else {
291 $this->assertFalse($pgs->isTransitionAllowedTo($status));
292 }
293 }
294
295 #[\PHPUnit\Framework\Attributes\DataProvider('ilPRGProgressStatus')]
297 {
298 $pgs = (new ilPRGProgress(123))
301 if (in_array($status, [
304 $pgs->getStatus()
305 ])) {
306 $this->assertTrue($pgs->isTransitionAllowedTo($status));
307 } else {
308 $this->assertFalse($pgs->isTransitionAllowedTo($status));
309 }
310 }
311
312 #[\PHPUnit\Framework\Attributes\DataProvider('ilPRGProgressStatus')]
314 {
315 $pgs = (new ilPRGProgress(123))
317 ->withStatus(ilPRGProgress::STATUS_FAILED);
318 if (in_array($status, [
322 $pgs->getStatus()
323 ])) {
324 $this->assertTrue($pgs->isTransitionAllowedTo($status));
325 } else {
326 $this->assertFalse($pgs->isTransitionAllowedTo($status));
327 }
328 }
329
330 #[\PHPUnit\Framework\Attributes\DataProvider('ilPRGProgressStatus')]
332 {
333 $pgs = (new ilPRGProgress(123))->withStatus(ilPRGProgress::STATUS_NOT_RELEVANT);
335 || $status === $pgs->getStatus()
336 ) {
337 $this->assertTrue($pgs->isTransitionAllowedTo($status));
338 } else {
339 $this->assertFalse($pgs->isTransitionAllowedTo($status));
340 }
341 }
342
343 public function testPRGProgressPointsOfChildren(): void
344 {
345 /*
346 └── 1
347 ├── 11
348 │ ├── 111
349 │ └── 112
350 ├── 12
351 └── 13
352 */
353
355 ->withAmountOfPoints(112);
357 ->withAmountOfPoints(111);
359 ->setSubnodes([$pgs111, $pgs112])
360 ->withAmountOfPoints(11);
362 ->withAmountOfPoints(12);
364 ->withAmountOfPoints(13);
366 ->setSubnodes([$pgs11, $pgs12, $pgs13])
367 ->withAmountOfPoints(1);
368
369 $this->assertEquals(111 + 112, $pgs11->getPossiblePointsOfRelevantChildren());
370 $this->assertEquals(0, $pgs12->getPossiblePointsOfRelevantChildren());
371 $this->assertEquals(11 + 12 + 13 * 0, $pgs1->getPossiblePointsOfRelevantChildren());
372 $this->assertEquals(111 + 112, $pgs11->getAchievedPointsOfChildren());
373 $this->assertEquals(0, $pgs1->getAchievedPointsOfChildren());
374 }
375}
A Progress is the status of a user on a single node of an assignment; it is unique by assignment_id:u...