ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilPrgRestartAssignmentsCronJobTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
23 
25 {
26  public array $logs = [];
28 
29  public function __construct(
33  ) {
34  $this->assignment_repo = $repo;
35  $this->adapter = $adapter;
36  $this->prg = $prg;
37  }
38  protected function getNow(): DateTimeImmutable
39  {
40  return \DateTimeImmutable::createFromFormat('Ymd', '20221224');
41  }
42 
43  protected function log(string $msg): void
44  {
45  $this->logs[] = $msg;
46  }
47  protected function getStudyProgramme(int $prg_obj_id): ilObjStudyProgramme
48  {
49  return $this->prg;
50  }
51 }
52 
53 class ilPrgRestartAssignmentsCronJobTest extends TestCase
54 {
58  protected ProgrammeEventsMock $events;
59 
60  protected function setUp(): void
61  {
62  $this->events = new ProgrammeEventsMock();
63 
64  $this->settings_repo = $this->getMockBuilder(ilStudyProgrammeSettingsDBRepository::class)
65  ->disableOriginalConstructor()
66  ->onlyMethods(['getProgrammeIdsWithReassignmentForExpiringValidity'])
67  ->getMock();
68 
69  $this->adapter = $this->getMockBuilder(ilPrgRestart::class)
70  ->setConstructorArgs([$this->settings_repo, $this->events])
71  ->getMock();
72 
73  $this->real_adapter = new ilPrgRestart($this->settings_repo, $this->events);
74 
75  $this->assignment_repo = $this->getMockBuilder(ilPRGAssignmentDBRepository::class)
76  ->disableOriginalConstructor()
77  ->onlyMethods(['getAboutToExpire', 'store'])
78  ->getMock();
79 
80  $this->prg = $this->getMockBuilder(ilObjStudyProgramme::class)
81  ->disableOriginalConstructor()
82  ->onlyMethods(['getApplicableMembershipSourceForUser', 'getSettings', 'assignUser', 'getRefIdFor'])
83  ->getMock();
84 
85  $this->job = new ilPrgRestartAssignmentsCronJobMock($this->assignment_repo, $this->adapter, $this->prg);
86  }
87 
89  {
90  $this->adapter
91  ->expects($this->once())
92  ->method('getRelevantProgrammeIds')
93  ->willReturn([]);
94  $this->assignment_repo
95  ->expects($this->never())
96  ->method('getAboutToExpire');
97  $this->assignment_repo
98  ->expects($this->never())
99  ->method('store');
100  $this->adapter
101  ->expects($this->never())
102  ->method('actOnSingleAssignment');
103  $this->job->run();
104  }
105 
107  {
109  $ass1 = (new ilPRGAssignment(42, 7))
110  ->withProgressTree($pgs1)
111  ->withManuallyAssigned(false);//will not be restarted
112  $ass2 = (new ilPRGAssignment(43, 8))
113  ->withProgressTree($pgs1)
114  ->withManuallyAssigned(true);
115  $this->adapter
116  ->expects($this->once())
117  ->method('getRelevantProgrammeIds')
118  ->willReturn([
119  1=>3
120  ]);
121  $this->assignment_repo
122  ->expects($this->once())
123  ->method('getAboutToExpire')
124  ->willReturn([$ass1, $ass2]);
125 
126  $this->assignment_repo
127  ->expects($this->exactly(1))
128  ->method('store');
129 
130  $validity_settings = $this->getMockBuilder(ilStudyProgrammeValidityOfAchievedQualificationSettings::class)
131  ->disableOriginalConstructor()
132  ->onlyMethods(['getRestartRecheck'])
133  ->getMock();
134 
135  $validity_settings
136  ->expects($this->exactly(2))
137  ->method('getRestartRecheck')
138  ->willReturn(true);
139 
140  $settings = $this->getMockBuilder(ilStudyProgrammeSettings::class)
141  ->disableOriginalConstructor()
142  ->onlyMethods(['getValidityOfQualificationSettings'])
143  ->getMock();
144  $settings
145  ->expects($this->exactly(2))
146  ->method('getValidityOfQualificationSettings')
147  ->willReturn($validity_settings);
148 
149  $this->prg
150  ->expects($this->exactly(2))
151  ->method('getSettings')
152  ->willReturn($settings);
153 
154  $this->prg
155  ->expects($this->exactly(1))
156  ->method('getApplicableMembershipSourceForUser')
157  ->willReturn(null);
158 
159  $this->prg
160  ->expects($this->exactly(1))
161  ->method('assignUser')
162  ->willReturn($ass1);
163 
164 
165  $this->adapter
166  ->expects($this->exactly(1))
167  ->method('actOnSingleAssignment');
168 
169  $this->job->run();
170  }
171 
172  public function testRestartAssignmentsEvents(): void
173  {
175  $ass1 = (new ilPRGAssignment(42, 7))->withProgressTree($pgs1);
176  $ass2 = (new ilPRGAssignment(43, 8))->withProgressTree($pgs1)
177  ->withManuallyAssigned(true);
178 
179  $this->settings_repo
180  ->expects($this->once())
181  ->method('getProgrammeIdsWithReassignmentForExpiringValidity')
182  ->willReturn([
183  42=>3,
184  43=>3
185  ]);
186 
187  $this->assignment_repo
188  ->expects($this->once())
189  ->method('getAboutToExpire')
190  ->willReturn([$ass1, $ass2]);
191  $this->prg
192  ->expects($this->exactly(2))
193  ->method('assignUser')
194  ->will($this->onConsecutiveCalls($ass1, $ass2));
195 
196  $job = new ilPrgRestartAssignmentsCronJobMock($this->assignment_repo, $this->real_adapter, $this->prg);
197  $job->run();
198 
199  $this->assertEquals(2, count($job->logs));
200  $expected_events = [
201  ['userReAssigned', ["ass_id" => 42, 'root_prg_id' => 11]],
202  ['userReAssigned', ["ass_id" => 43, 'root_prg_id' => 11]]
203  ];
204  $this->assertEquals($expected_events, $this->events->raised);
205  }
206 }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A Progress is the status of a user on a single node of an assignment; it is unique by assignment_id:u...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Re-assign users (according to restart-date).
ilStudyProgrammeSettingsDBRepository $settings_repo
__construct(ilPRGAssignmentDBRepository $repo, ilPrgCronJobAdapter $adapter, ilObjStudyProgramme $prg)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Assignments are relations of users to a PRG; They hold progress-information for (sub-)nodes of the PR...