ILIAS  release_7 Revision v7.30-3-g800a261c036
ilStudyProgrammeProgressTest.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
3class ilStudyProgrammeProgressTest extends \PHPUnit\Framework\TestCase
4{
5 protected function getUserIdAndNow() : array
6 {
7 return [6, new DateTimeImmutable()];
8 }
9
10 public function test_init_and_id()
11 {
12 $spp = new ilStudyProgrammeProgress(123);
13 $this->assertEquals($spp->getId(), 123);
14 return $spp;
15 }
16
20 public function test_assignment_id()
21 {
22 $spp = (new ilStudyProgrammeProgress(123))->withAssignmentId(321);
23 $this->assertEquals($spp->getAssignmentId(), 321);
24 }
25
29 public function test_node_id()
30 {
31 $spp = (new ilStudyProgrammeProgress(123))->withNodeId(321);
32 $this->assertEquals($spp->getNodeId(), 321);
33 }
34
38 public function test_user_id()
39 {
40 $spp = (new ilStudyProgrammeProgress(123))->withUserId(321);
41 $this->assertEquals($spp->getUserId(), 321);
42 }
43
47 public function test_amount_of_points()
48 {
49 $spp = (new ilStudyProgrammeProgress(123))->withAmountOfPoints(321);
50 $this->assertEquals($spp->getAmountOfPoints(), 321);
51 }
52
57 {
58 $this->expectException(\ilException::class);
59 $spp = (new ilStudyProgrammeProgress(123))->withAmountOfPoints(-321);
60 }
61
66 {
67 $spp = (new ilStudyProgrammeProgress(123))->withCurrentAmountOfPoints(321);
68 $this->assertEquals($spp->getCurrentAmountOfPoints(), 321);
69 }
70
71 public function status()
72 {
73 return [
74 //status, count as 'successful'
80 ];
81 }
82
86 public function test_status($status)
87 {
88 $spp = (new ilStudyProgrammeProgress(123))->withStatus($status);
89 $this->assertEquals($spp->getStatus(), $status);
90 }
91
95 public function test_status_invalid()
96 {
97 $this->expectException(\ilException::class);
98 $spp = (new ilStudyProgrammeProgress(123))->withStatus(321);
99 }
100
104 public function testWithLastChange() : void
105 {
106 list($acting_usr, $now) = $this->getUserIdAndNow();
107 $spp = (new ilStudyProgrammeProgress(123))->withLastChange($acting_usr, $now);
108 $this->assertEquals($spp->getLastChangeBy(), $acting_usr);
109 $this->assertEquals($spp->getLastChange()->format('Y-m-d H:i:s'), $now->format('Y-m-d H:i:s'));
110 }
111
115 public function test_assignment_date()
116 {
117 $ad = new DateTimeImmutable();
118 $spp = (new ilStudyProgrammeProgress(123))->withAssignmentDate($ad);
119 $this->assertEquals($spp->getAssignmentDate()->format('Y-m-d'), $ad->format('Y-m-d'));
120 }
121
125 public function test_completion()
126 {
127 list($acting_usr, $now) = $this->getUserIdAndNow();
128
129 $spp = (new ilStudyProgrammeProgress(123))->withCompletion($acting_usr, $now);
130 $this->assertEquals($now->format('Y-m-d'), $spp->getCompletionDate()->format('Y-m-d'));
131 $this->assertEquals($acting_usr, $spp->getCompletionBy());
132
133 $spp = (new ilStudyProgrammeProgress(123))->withCompletion(null, null);
134 $this->assertNull($spp->getCompletionDate());
135 $this->assertNull($spp->getCompletionBy());
136 }
137
141 public function test_deadline()
142 {
143 $dl = new DateTimeImmutable();
144 $spp = (new ilStudyProgrammeProgress(123))->withDeadline($dl);
145 $this->assertEquals($spp->getDeadline()->format('Y-m-d'), $dl->format('Y-m-d'));
146 }
147
151 public function test_vq_date()
152 {
153 $dl = DateTimeImmutable::createFromFormat('Ymd', '20201011');
154 $spp = (new ilStudyProgrammeProgress(123))->withValidityOfQualification($dl);
155 $this->assertEquals($spp->getValidityOfQualification()->format('Ymd'), '20201011');
156 }
157
162 {
163 $this->assertFalse($spp->hasIndividualModifications());
164
165 $this->assertTrue($spp->withIndividualModifications(true)->hasIndividualModifications());
166 $this->assertFalse($spp->withIndividualModifications(false)->hasIndividualModifications());
167 }
168
172 public function test_invalidate()
173 {
174 $spp = new ilStudyProgrammeProgress(123);
175 $this->assertFalse($spp->isInvalidated());
176 $past = DateTimeImmutable::createFromFormat('Ymd', '20180101');
177 $spp = $spp
178 ->withValidityOfQualification($past)
179 ->invalidate();
180 $this->assertTrue($spp->isInvalidated());
181 }
182
187 {
188 $this->expectException(\ilException::class);
189 $tomorrow = (new DateTimeImmutable())->add(new DateInterval('P1D'));
190 $spp = (new ilStudyProgrammeProgress(123))->withValidityOfQualification($tomorrow)->invalidate();
191 }
192
197 {
198 $this->expectException(\ilException::class);
199 $spp = (new ilStudyProgrammeProgress(123))->invalidate();
200 }
201
205 public function testIsSuccessful($status, $success)
206 {
207 $spp = (new ilStudyProgrammeProgress(123))->withStatus($status);
208 $this->assertEquals($success, $spp->isSuccessful());
209 }
210
212 {
213 $today = new DateTimeImmutable();
214 $yesterday = $today->sub(new DateInterval('P1D'));
215 $tomorrow = $today->add(new DateInterval('P1D'));
216
217 $spp = (new ilStudyProgrammeProgress(123))
219 ->withValidityOfQualification($today);
220
221 $this->assertNull($spp->hasValidQualification($today));
222
223 $spp = $spp->withStatus(ilStudyProgrammeProgress::STATUS_COMPLETED);
224 $this->assertTrue($spp->hasValidQualification($yesterday));
225 $this->assertTrue($spp->hasValidQualification($today));
226 $this->assertFalse($spp->hasValidQualification($tomorrow));
227 }
228
229 public function testMarkRelevant()
230 {
231 $usr = 6;
232 $now = new DateTimeImmutable();
233 $spp = (new ilStudyProgrammeProgress(123))
234 ->markRelevant($now, $usr);
235
236 $this->assertNull($spp->getCompletionBy());
237 $this->assertEquals($usr, $spp->getLastChangeBy());
238 $this->assertEquals(
240 $spp->getLastChange()->format(ilStudyProgrammeProgress::DATE_FORMAT)
241 );
242 $this->assertEquals(
244 $spp->getStatus()
245 );
246 $this->assertTrue($spp->hasIndividualModifications());
247 }
248
249 public function testMarkNotRelevant()
250 {
251 $usr = 6;
252 $now = new DateTimeImmutable();
253 $spp = (new ilStudyProgrammeProgress(123))
254 ->markNotRelevant($now, $usr);
255
256 $this->assertNull($spp->getCompletionBy());
257 $this->assertEquals($usr, $spp->getLastChangeBy());
258 $this->assertEquals(
260 $spp->getLastChange()->format(ilStudyProgrammeProgress::DATE_FORMAT)
261 );
262 $this->assertEquals(
264 $spp->getStatus()
265 );
266 $this->assertTrue($spp->hasIndividualModifications());
267 }
268
269 public function testMarkFailed()
270 {
271 $usr = 6;
272 $now = new DateTimeImmutable();
273 $spp = (new ilStudyProgrammeProgress(123))
274 ->markFailed($now, $usr);
275
276 $this->assertNull($spp->getCompletionDate());
277 $this->assertNull($spp->getCompletionBy());
278 $this->assertEquals($usr, $spp->getLastChangeBy());
279 $this->assertEquals(
281 $spp->getLastChange()->format(ilStudyProgrammeProgress::DATE_FORMAT)
282 );
283 $this->assertEquals(
285 $spp->getStatus()
286 );
287 }
288
289 public function testMarkNotFailed()
290 {
291 list($usr, $now) = $this->getUserIdAndNow();
292 $spp = (new ilStudyProgrammeProgress(123))
293 ->markNotFailed($now, $usr);
294
295 $this->assertNull($spp->getCompletionDate());
296 $this->assertNull($spp->getCompletionBy());
297 $this->assertEquals($usr, $spp->getLastChangeBy());
298 $this->assertEquals(
300 $spp->getLastChange()->format(ilStudyProgrammeProgress::DATE_FORMAT)
301 );
302 $this->assertEquals(
304 $spp->getStatus()
305 );
306 }
307
308 public function testMarkAccredited()
309 {
310 $usr = 6;
311 $now = new DateTimeImmutable();
312 $spp = (new ilStudyProgrammeProgress(123))
313 ->markAccredited($now, $usr);
314
315 $this->assertEquals($now, $spp->getCompletionDate());
316 $this->assertEquals($usr, $spp->getCompletionBy());
317 $this->assertEquals($usr, $spp->getLastChangeBy());
318 $this->assertEquals(
320 $spp->getLastChange()->format(ilStudyProgrammeProgress::DATE_FORMAT)
321 );
322 $this->assertEquals(
324 $spp->getStatus()
325 );
326 }
327
328 public function testUnmarkAccredited()
329 {
330 $usr = 6;
331 $now = new DateTimeImmutable();
332 $spp = (new ilStudyProgrammeProgress(123))
333 ->unmarkAccredited($now, $usr);
334
335 $this->assertNull($spp->getCompletionDate());
336 $this->assertNull($spp->getCompletionBy());
337 $this->assertNull($spp->getValidityOfQualification());
338 $this->assertEquals($usr, $spp->getLastChangeBy());
339 $this->assertEquals(
341 $spp->getLastChange()->format(ilStudyProgrammeProgress::DATE_FORMAT)
342 );
343 $this->assertEquals(
345 $spp->getStatus()
346 );
347 }
348
349 public function testSucceed()
350 {
351 $triggering_obj = 777;
352 $now = new DateTimeImmutable();
353 $spp = (new ilStudyProgrammeProgress(123))
354 ->succeed($now, $triggering_obj);
355
356 $this->assertEquals($now, $spp->getCompletionDate());
357 $this->assertEquals($triggering_obj, $spp->getCompletionBy());
358 $this->assertEquals($triggering_obj, $spp->getLastChangeBy());
359 $this->assertEquals(
361 $spp->getLastChange()->format(ilStudyProgrammeProgress::DATE_FORMAT)
362 );
363 $this->assertEquals(
365 $spp->getStatus()
366 );
367 }
368
372 public function testAllowedTransitionsForInProgress($status)
373 {
375 if (in_array($status, [
380 $spp->getStatus()
381 ])) {
382 $this->assertTrue($spp->isTransitionAllowedTo($status));
383 } else {
384 $this->assertFalse($spp->isTransitionAllowedTo($status));
385 }
386 }
387
391 public function testAllowedTransitionsForAccredited($status)
392 {
394 if (in_array($status, [
399 $spp->getStatus()
400 ])) {
401 $this->assertTrue($spp->isTransitionAllowedTo($status));
402 } else {
403 $this->assertFalse($spp->isTransitionAllowedTo($status));
404 }
405 }
406
410 public function testAllowedTransitionsForCompleted($status)
411 {
413 if (in_array($status, [
415 $spp->getStatus()
416 ])) {
417 $this->assertTrue($spp->isTransitionAllowedTo($status));
418 } else {
419 $this->assertFalse($spp->isTransitionAllowedTo($status));
420 }
421 }
422
426 public function testAllowedTransitionsForFailed($status)
427 {
429 if (in_array($status, [
433 $spp->getStatus()
434 ])) {
435 $this->assertTrue($spp->isTransitionAllowedTo($status));
436 } else {
437 $this->assertFalse($spp->isTransitionAllowedTo($status));
438 }
439 }
440
444 public function testAllowedTransitionsForIrrelevant($status)
445 {
448 || $status === $spp->getStatus()
449 ) {
450 $this->assertTrue($spp->isTransitionAllowedTo($status));
451 } else {
452 $this->assertFalse($spp->isTransitionAllowedTo($status));
453 }
454 }
455}
$success
Definition: Utf8Test.php:86
add()
Definition: add.php:2
An exception for terminatinating execution or to throw for unit testing.
testAllowedTransitionsForIrrelevant($status)
@dataProvider status
test_completion()
@depends test_init_and_id
test_amount_of_points_invalid()
@depends test_init_and_id
test_current_amount_of_points()
@depends test_init_and_id
test_invalidate_non_expired_2()
@depends test_vq_date
testAllowedTransitionsForInProgress($status)
@dataProvider status
testIndividualPlan(ilStudyProgrammeProgress $spp)
@depends test_init_and_id
test_assignment_id()
@depends test_init_and_id
test_deadline()
@depends test_init_and_id
test_node_id()
@depends test_init_and_id
test_assignment_date()
@depends test_init_and_id
testAllowedTransitionsForFailed($status)
@dataProvider status
testAllowedTransitionsForAccredited($status)
@dataProvider status
test_user_id()
@depends test_init_and_id
testWithLastChange()
@depends test_init_and_id
test_amount_of_points()
@depends test_init_and_id
test_status_invalid()
@depends test_init_and_id
test_status($status)
@dataProvider status
test_invalidate_non_expired_1()
@depends test_vq_date
testAllowedTransitionsForCompleted($status)
@dataProvider status
testIsSuccessful($status, $success)
@dataProvider status
Class ilStudyProgrammeProgress.