ILIAS  trunk Revision v11.0_alpha-1843-g9e1fad99175
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilPrgRestartAssignmentsCronJobTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
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 
54 {
60  protected ProgrammeEventsMock $events;
62 
63  protected function setUp(): void
64  {
65  $this->events = new ProgrammeEventsMock();
66 
67  $this->settings_repo = $this->getMockBuilder(ilStudyProgrammeSettingsDBRepository::class)
68  ->disableOriginalConstructor()
69  ->onlyMethods(['getProgrammeIdsWithReassignmentForExpiringValidity'])
70  ->getMock();
71 
72  $this->adapter = $this->getMockBuilder(ilPrgRestart::class)
73  ->setConstructorArgs([$this->settings_repo, $this->events])
74  ->getMock();
75 
76  $this->real_adapter = new ilPrgRestart($this->settings_repo, $this->events);
77 
78  $this->assignment_repo = $this->getMockBuilder(ilPRGAssignmentDBRepository::class)
79  ->disableOriginalConstructor()
80  ->onlyMethods(['getAboutToExpire', 'store'])
81  ->getMock();
82 
83  $this->prg = $this->getMockBuilder(ilObjStudyProgramme::class)
84  ->disableOriginalConstructor()
85  ->onlyMethods(['getApplicableMembershipSourceForUser', 'getSettings', 'assignUser', 'getRefIdFor'])
86  ->getMock();
87 
88  $this->job = new ilPrgRestartAssignmentsCronJobMock($this->assignment_repo, $this->adapter, $this->prg);
89  }
90 
92  {
93  $this->adapter
94  ->expects($this->once())
95  ->method('getRelevantProgrammeIds')
96  ->willReturn([]);
97  $this->assignment_repo
98  ->expects($this->never())
99  ->method('getAboutToExpire');
100  $this->assignment_repo
101  ->expects($this->never())
102  ->method('store');
103  $this->adapter
104  ->expects($this->never())
105  ->method('actOnSingleAssignment');
106  $this->job->run();
107  }
108 
110  {
112  $ass1 = (new ilPRGAssignment(42, 7))
113  ->withProgressTree($pgs1)
114  ->withManuallyAssigned(false);//will not be restarted
115  $ass2 = (new ilPRGAssignment(43, 8))
116  ->withProgressTree($pgs1)
117  ->withManuallyAssigned(true);
118  $this->adapter
119  ->expects($this->once())
120  ->method('getRelevantProgrammeIds')
121  ->willReturn([
122  1 => 3
123  ]);
124  $this->assignment_repo
125  ->expects($this->once())
126  ->method('getAboutToExpire')
127  ->willReturn([$ass1, $ass2]);
128 
129  $this->assignment_repo
130  ->expects($this->exactly(1))
131  ->method('store');
132 
133  $validity_settings = $this->getMockBuilder(ilStudyProgrammeValidityOfAchievedQualificationSettings::class)
134  ->disableOriginalConstructor()
135  ->onlyMethods(['getRestartRecheck'])
136  ->getMock();
137 
138  $validity_settings
139  ->expects($this->exactly(2))
140  ->method('getRestartRecheck')
141  ->willReturn(true);
142 
143  $settings = $this->getMockBuilder(ilStudyProgrammeSettings::class)
144  ->disableOriginalConstructor()
145  ->onlyMethods(['getValidityOfQualificationSettings'])
146  ->getMock();
147  $settings
148  ->expects($this->exactly(2))
149  ->method('getValidityOfQualificationSettings')
150  ->willReturn($validity_settings);
151 
152  $this->prg
153  ->expects($this->exactly(2))
154  ->method('getSettings')
155  ->willReturn($settings);
156 
157  $this->prg
158  ->expects($this->exactly(1))
159  ->method('getApplicableMembershipSourceForUser')
160  ->willReturn(null);
161 
162  $this->prg
163  ->expects($this->exactly(1))
164  ->method('assignUser')
165  ->willReturn($ass1);
166 
167 
168  $this->adapter
169  ->expects($this->exactly(1))
170  ->method('actOnSingleAssignment');
171 
172  $this->job->run();
173  }
174 
175  public function testRestartAssignmentsEvents(): void
176  {
178  $ass1 = (new ilPRGAssignment(42, 7))->withProgressTree($pgs1);
179  $ass2 = (new ilPRGAssignment(43, 8))->withProgressTree($pgs1)
180  ->withManuallyAssigned(true);
181 
182  $this->settings_repo
183  ->expects($this->once())
184  ->method('getProgrammeIdsWithReassignmentForExpiringValidity')
185  ->willReturn([
186  42 => 3,
187  43 => 3
188  ]);
189 
190  $this->assignment_repo
191  ->expects($this->once())
192  ->method('getAboutToExpire')
193  ->willReturn([$ass1, $ass2]);
194  $this->prg
195  ->expects($this->exactly(2))
196  ->method('assignUser')
197  ->will($this->onConsecutiveCalls($ass1, $ass2));
198 
199  $job = new ilPrgRestartAssignmentsCronJobMock($this->assignment_repo, $this->real_adapter, $this->prg);
200  $job->run();
201 
202  $this->assertEquals(2, count($job->logs));
203  $expected_events = [
204  ['userReAssigned', ["ass_id" => 42, 'root_prg_id' => 11]],
205  ['userReAssigned', ["ass_id" => 43, 'root_prg_id' => 11]]
206  ];
207  $this->assertEquals($expected_events, $this->events->raised);
208  }
209 }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
A Progress is the status of a user on a single node of an assignment; it is unique by assignment_id:u...
Re-assign users (according to restart-date).
ilStudyProgrammeSettingsDBRepository $settings_repo
__construct(ilPRGAssignmentDBRepository $repo, ilPrgCronJobAdapter $adapter, ilObjStudyProgramme $prg)
Assignments are relations of users to a PRG; They hold progress-information for (sub-)nodes of the PR...
Assignments are relations of users to a PRG; They hold progress-information for (sub-)nodes of the PR...