ILIAS  release_7 Revision v7.30-3-g800a261c036
ilStudyProgrammeCronRiskyToFailTest.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
3require_once(__DIR__ . "/../../../../libs/composer/vendor/autoload.php");
4require_once(__DIR__ . "/../prg_mocks.php");
5
6
7class ilStudyProgrammeCronRiskyToFailTest extends \PHPUnit\Framework\TestCase
8{
9 public function setUp() : void
10 {
11 $this->job = $this
12 ->getMockBuilder(ilPrgUserRiskyToFailCronJob::class)
13 ->disableOriginalConstructor()
14 ->onlyMethods(['getEvents', 'getSettingsRepository', 'getProgressRepository', 'log'])
15 ->getMock();
16
17 $this->settings_repo = $this->getMockBuilder(ilStudyProgrammeSettingsDBRepository::class)
18 ->disableOriginalConstructor()
19 ->onlyMethods(['getProgrammeIdsWithRiskyToFailSettings'])
20 ->getMock();
21
22 $this->progress_repo = $this->getMockBuilder(ilStudyProgrammeProgressDBRepository::class)
23 ->disableOriginalConstructor()
24 ->onlyMethods(['getRiskyToFail'])
25 ->getMock();
26
27 $this->events = new ProgrammeEventsMock();
28 }
29
30 public function testRiskyToFailNoSettings() : void
31 {
32 $this->settings_repo
33 ->expects($this->once())
34 ->method('getProgrammeIdsWithRiskyToFailSettings')
35 ->willReturn([]);
36
37
38 $this->job->expects($this->once())
39 ->method('getSettingsRepository')
40 ->willReturn($this->settings_repo);
41
42 $this->job->expects($this->never())
43 ->method('getProgressRepository');
44
45 $this->job->expects($this->never())
46 ->method('getEvents');
47
48 $this->job->run();
49 }
50
51 public function testRiskyToFailNoRepos()
52 {
53 $this->settings_repo
54 ->expects($this->once())
55 ->method('getProgrammeIdsWithRiskyToFailSettings')
56 ->willReturn([
57 71 => 2, //id 71, 2 days
58 72 => 4
59 ]);
60
61 $this->progress_repo
62 ->expects($this->once())
63 ->method('getRiskyToFail')
64 ->willReturn([]);
65
66 $this->job->expects($this->once())
67 ->method('getSettingsRepository')
68 ->willReturn($this->settings_repo);
69
70 $this->job->expects($this->once())
71 ->method('getProgressRepository')
72 ->willReturn($this->progress_repo);
73
74 $this->job->expects($this->never())
75 ->method('getEvents');
76
77 $this->job->run();
78 }
79
80 public function testRiskyToFail()
81 {
82 $this->settings_repo
83 ->expects($this->once())
84 ->method('getProgrammeIdsWithRiskyToFailSettings')
85 ->willReturn([71 => 2]);
86
87 $progress_1 = (new ilStudyProgrammeProgress(1))->withUserId(11)->withNodeId(71);
88 $progress_2 = (new ilStudyProgrammeProgress(2))->withUserId(22)->withNodeId(71);
89 $progress_3 = (new ilStudyProgrammeProgress(3))->withUserId(33)->withNodeId(71);
90
91 $expected_events = [
92 ['userRiskyToFail', ["progress_id" => 1, "usr_id" => 11]],
93 ['userRiskyToFail', ["progress_id" => 2, "usr_id" => 22]],
94 ['userRiskyToFail', ["progress_id" => 3, "usr_id" => 33]]
95 ];
96
97 $this->progress_repo
98 ->expects($this->once())
99 ->method('getRiskyToFail')
100 ->willReturn([
101 $progress_1,
102 $progress_2,
103 $progress_3
104 ]);
105
106 $this->job->expects($this->once())
107 ->method('getSettingsRepository')
108 ->willReturn($this->settings_repo);
109
110 $this->job->expects($this->once())
111 ->method('getProgressRepository')
112 ->willReturn($this->progress_repo);
113
114 $this->job->expects($this->once())
115 ->method('getEvents')
116 ->willReturn($this->events);
117
118 $this->job->run();
119 $this->assertEquals($expected_events, $this->events->raised);
120 }
121}
An exception for terminatinating execution or to throw for unit testing.
Class ilStudyProgrammeProgress.