ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilStudyProgrammeCronRiskyToFailTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
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;
52 
53  protected function setUp(): void
54  {
55  $this->events = new ProgrammeEventsMock();
56  $this->settings_repo = $this->getMockBuilder(ilStudyProgrammeSettingsDBRepository::class)
57  ->disableOriginalConstructor()
58  ->onlyMethods(['getProgrammeIdsWithRiskyToFailSettings'])
59  ->getMock();
60 
61  $this->adapter = $this->getMockBuilder(ilPrgRiskyToFail::class)
62  ->setConstructorArgs([$this->settings_repo, $this->events])
63  ->getMock();
64 
65  $this->real_adapter = new ilPrgRiskyToFail($this->settings_repo, $this->events);
66 
67  $this->assignment_repo = $this->getMockBuilder(ilPRGAssignmentDBRepository::class)
68  ->disableOriginalConstructor()
69  ->onlyMethods(['getRiskyToFail', 'storeRiskyToFailSentFor'])
70  ->getMock();
71 
72  $this->job = new ilPrgUserRiskyToFailCronJobMock($this->assignment_repo, $this->adapter);
73  }
74 
76  {
77  $this->adapter
78  ->expects($this->once())
79  ->method('getRelevantProgrammeIds')
80  ->willReturn([]);
81  $this->assignment_repo
82  ->expects($this->never())
83  ->method('getRiskyToFail');
84  $this->assignment_repo
85  ->expects($this->never())
86  ->method('storeRiskyToFailSentFor');
87  $this->adapter
88  ->expects($this->never())
89  ->method('actOnSingleAssignment');
90  $this->job->run();
91  }
92 
93  public function testRiskyToFailForRelevantProgrammes(): void
94  {
96  $ass1 = (new ilPRGAssignment(42, 7))
97  ->withProgressTree($pgs1);
98  $ass2 = (new ilPRGAssignment(43, 8))
99  ->withProgressTree($pgs1);
100 
101  $this->adapter
102  ->expects($this->once())
103  ->method('getRelevantProgrammeIds')
104  ->willReturn([
105  1=>3
106  ]);
107  $this->assignment_repo
108  ->expects($this->once())
109  ->method('getRiskyToFail')
110  ->willReturn([$ass1, $ass2]);
111 
112  $this->assignment_repo
113  ->expects($this->exactly(2))
114  ->method('storeRiskyToFailSentFor');
115 
116  $this->adapter
117  ->expects($this->exactly(2))
118  ->method('actOnSingleAssignment');
119 
120  $this->job->run();
121  }
122 
123  public function testRiskyToFailEvents(): void
124  {
126  $ass1 = (new ilPRGAssignment(42, 7))->withProgressTree($pgs1);
127  $ass2 = (new ilPRGAssignment(43, 8))->withProgressTree($pgs1);
128 
129  $this->settings_repo
130  ->expects($this->once())
131  ->method('getProgrammeIdsWithRiskyToFailSettings')
132  ->willReturn([
133  42=>3,
134  43=>3
135  ]);
136 
137  $this->assignment_repo
138  ->expects($this->once())
139  ->method('getRiskyToFail')
140  ->willReturn([$ass1, $ass2]);
141 
142  $job = new ilPrgUserRiskyToFailCronJobMock($this->assignment_repo, $this->real_adapter);
143  $job->run();
144 
145  $this->assertEquals(2, count($job->logs));
146  $expected_events = [
147  ['userRiskyToFail', ["ass_id" => 42, 'root_prg_id' => 11]],
148  ['userRiskyToFail', ["ass_id" => 43, 'root_prg_id' => 11]]
149  ];
150  $this->assertEquals($expected_events, $this->events->raised);
151  }
152 }
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...
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...
ilStudyProgrammeSettingsDBRepository $settings_repo
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilPRGAssignmentDBRepository $repo, ilPrgCronJobAdapter $adapter)
Assignments are relations of users to a PRG; They hold progress-information for (sub-)nodes of the PR...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...