ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilStudyProgrammeCronAboutToExpireTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
25 {
26  public array $logs = [];
27 
28  public function __construct(
31  ) {
32  $this->assignment_repo = $repo;
33  $this->adapter = $adapter;
34  }
35  protected function getNow(): DateTimeImmutable
36  {
37  return \DateTimeImmutable::createFromFormat('Ymd', '20221224');
38  }
39 
40  protected function log(string $msg): void
41  {
42  $this->logs[] = $msg;
43  }
44 }
45 
47 {
51  protected ProgrammeEventsMock $events;
54 
55  protected function setUp(): void
56  {
57  $this->events = new ProgrammeEventsMock();
58  $this->settings_repo = $this->getMockBuilder(ilStudyProgrammeSettingsDBRepository::class)
59  ->disableOriginalConstructor()
60  ->onlyMethods(['getProgrammeIdsWithMailsForExpiringValidity'])
61  ->getMock();
62 
63  $this->adapter = $this->getMockBuilder(ilPrgNotRestarted::class)
64  ->setConstructorArgs([$this->settings_repo, $this->events])
65  ->getMock();
66 
67  $this->real_adapter = new ilPrgNotRestarted($this->settings_repo, $this->events);
68 
69  $this->assignment_repo = $this->getMockBuilder(ilPRGAssignmentDBRepository::class)
70  ->disableOriginalConstructor()
71  ->onlyMethods(['getAboutToExpire', 'storeExpiryInfoSentFor'])
72  ->getMock();
73 
74  $this->job = new ilPrgUserNotRestartedCronJobMock($this->assignment_repo, $this->adapter);
75  }
76 
78  {
79  $this->adapter
80  ->expects($this->once())
81  ->method('getRelevantProgrammeIds')
82  ->willReturn([]);
83  $this->assignment_repo
84  ->expects($this->never())
85  ->method('getAboutToExpire');
86  $this->assignment_repo
87  ->expects($this->never())
88  ->method('storeExpiryInfoSentFor');
89  $this->adapter
90  ->expects($this->never())
91  ->method('actOnSingleAssignment');
92  $this->job->run();
93  }
94 
96  {
98  $ass1 = (new ilPRGAssignment(42, 7))
99  ->withProgressTree($pgs1);
100  $ass2 = (new ilPRGAssignment(43, 8))
101  ->withProgressTree($pgs1);
102 
103  $this->adapter
104  ->expects($this->once())
105  ->method('getRelevantProgrammeIds')
106  ->willReturn([
107  1 => 3
108  ]);
109  $this->assignment_repo
110  ->expects($this->once())
111  ->method('getAboutToExpire')
112  ->willReturn([$ass1, $ass2]);
113 
114  $this->assignment_repo
115  ->expects($this->exactly(2))
116  ->method('storeExpiryInfoSentFor');
117 
118  $this->adapter
119  ->expects($this->exactly(2))
120  ->method('actOnSingleAssignment');
121 
122  $this->job->run();
123  }
124 
125  public function testAboutToExpireEvents(): void
126  {
128  $ass1 = (new ilPRGAssignment(42, 7))->withProgressTree($pgs1);
129  $ass2 = (new ilPRGAssignment(43, 8))->withProgressTree($pgs1);
130 
131  $this->settings_repo
132  ->expects($this->once())
133  ->method('getProgrammeIdsWithMailsForExpiringValidity')
134  ->willReturn([
135  42 => 3,
136  43 => 3
137  ]);
138 
139  $this->assignment_repo
140  ->expects($this->once())
141  ->method('getAboutToExpire')
142  ->willReturn([$ass1, $ass2]);
143 
144  $job = new ilPrgUserNotRestartedCronJobMock($this->assignment_repo, $this->real_adapter);
145  $job->run();
146 
147  $this->assertEquals(2, count($job->logs));
148  $expected_events = [
149  ['informUserToRestart', ["ass_id" => 42, 'root_prg_id' => 11]],
150  ['informUserToRestart', ["ass_id" => 43, 'root_prg_id' => 11]]
151  ];
152  $this->assertEquals($expected_events, $this->events->raised);
153  }
154 }
__construct(ilPRGAssignmentDBRepository $repo, ilPrgCronJobAdapter $adapter)
Inform a user, that her qualification is about to expire.
A Progress is the status of a user on a single node of an assignment; it is unique by assignment_id:u...
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...