ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilStudyProgrammeAssignmentActionsTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once(__DIR__ . "/../../../../../../vendor/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../prg_mocks.php");
23
24
25class ilStudyProgrammeAssignmentActionsTest extends \PHPUnit\Framework\TestCase
26{
31
32 public function setUp(): void
33 {
34 $this->settings_repo = new SettingsRepoMock();
35 foreach ([1, 11, 12, 13, 111, 112] as $pgs_id) {
36 $settings = new SettingsMock($pgs_id);
37 $settings->setLPMode(ilStudyProgrammeSettings::MODE_POINTS);
38 $this->settings_repo->update($settings);
39 }
40
41 $this->messages = new ilPRGMessageCollection();
42 $this->events = new ProgrammeEventsMock();
43
44 $user_info = new ilPRGUserInformation([
45 'firstname' => 'firstname',
46 'lastname' => 'lasttname',
47 'login' => 'login',
48 'active' => true,
49 'email' => 'f.lastname@example.com',
50 'gender' => 'f',
51 'title' => 'Prof. Dr.',
52 'org_units' => 'some OrgU',
53 ]);
54
55 $this->ass = (new ilPRGAssignment(42, 7))
56 ->withUserInformation($user_info)
57 ->withProgressTree(
60 )
61 );
62 }
63
64 protected function getProgressesWithDefaultStatus(int $status): ilPRGProgress
65 {
66 /*
67 └── 1
68 ├── 11
69 │ ├── 111
70 │ └── 112
71 ├── 12
72 └── 13
73 */
74 $pgs112 = (new ilPRGProgress(112, $status))->withAmountOfPoints(4);
75 $pgs111 = (new ilPRGProgress(111, $status))->withAmountOfPoints(5);
76 $pgs11 = (new ilPRGProgress(11, $status))->setSubnodes([$pgs111, $pgs112])->withAmountOfPoints(8);
77 $pgs12 = new ilPRGProgress(12, $status);
78 $pgs13 = new ilPRGProgress(13, $status);
79 $pgs1 = (new ilPRGProgress(1, $status))->setSubnodes([$pgs11, $pgs12, $pgs13]);
80 return $pgs1;
81 }
82
83
84 public function testPRGAssignmentActionsInitDates(): void
85 {
86 $today = (new \DateTimeImmutable())->format('Ymd');
87 $ass = $this->ass->initAssignmentDates();
88 foreach ([1, 11, 12, 13, 111, 112] as $pgs_id) {
89 $this->assertEquals(
90 $today,
91 $ass->getProgressForNode($pgs_id)->getAssignmentDate()->format('Ymd')
92 );
93 }
94 }
95
97 {
98 $ass = $this->ass->markRelevant($this->settings_repo, 111, 7, $this->messages);
99
100 $this->assertEquals(
102 $ass->getProgressForNode(111)->getStatus()
103 );
104 $this->assertEquals(
106 $ass->getProgressForNode(11)->getStatus()
107 );
108 $this->assertEquals(
110 $ass->getProgressForNode(12)->getStatus()
111 );
112
114 $ass = $this->ass
115 ->markNotRelevant($this->settings_repo, 12, 7, $messages)
116 ->markNotRelevant($this->settings_repo, 111, 7, $messages);
117
118 $this->assertTrue($messages->hasErrors());
119 $this->assertEquals(
121 $ass->getProgressForNode(12)->getStatus()
122 );
123 $this->assertEquals(
125 $ass->getProgressForNode(111)->getStatus()
126 );
127 }
128
130 {
131 $ass = $this->ass->withProgressTree(
133 );
134
135 $ass = $ass
136 ->markAccredited($this->settings_repo, $this->events, 111, 7, $this->messages)
137 ->markAccredited($this->settings_repo, $this->events, 112, 7, $this->messages)
138 ->markAccredited($this->settings_repo, $this->events, 13, 7, $this->messages);
139 $this->assertEquals(
141 $ass->getProgressForNode(111)->getStatus()
142 );
143 $this->assertEquals(
145 $ass->getProgressForNode(112)->getStatus()
146 );
147 $this->assertEquals(
149 $ass->getProgressForNode(11)->getStatus()
150 );
151 $this->assertEquals(5 + 4, $ass->getProgressForNode(11)->getCurrentAmountOfPoints());
152 $this->assertEquals(
154 $ass->getProgressForNode(13)->getStatus()
155 );
156
157 $ass = $ass
158 ->unmarkAccredited($this->settings_repo, 112, 7, $this->messages)
159 ->unmarkAccredited($this->settings_repo, 111, 7, $this->messages)
160 ->unmarkAccredited($this->settings_repo, 13, 7, $this->messages);
161
162 $this->assertEquals(
164 $ass->getProgressForNode(112)->getStatus()
165 );
166 $this->assertEquals(0, $ass->getProgressForNode(11)->getCurrentAmountOfPoints());
167 $this->assertEquals(
168 ilPRGProgress::STATUS_COMPLETED, //completion may not be revoked manually
169 $ass->getProgressForNode(13)->getStatus()
170 );
171 $this->assertEquals(
172 ilPRGProgress::STATUS_IN_PROGRESS, //completion may be revoked automatically
173 $ass->getProgressForNode(11)->getStatus()
174 );
175 }
176
178 {
179 $today = new DateTimeImmutable();
180 $yesterday = $today->sub(new DateInterval('P1D'));
181
183 $pgs12 = $pgss->getSubnode('13')->withDeadline($today);
184 $pgs13 = $pgss->getSubnode('13')->withDeadline($yesterday);
185 $pgss = $pgss
186 ->withSubnode($pgs12)
187 ->withSubnode($pgs13);
188
189 $ass = $this->ass
190 ->withProgressTree($pgss)
191 ->succeed($this->settings_repo, 12, 777)
192 ->succeed($this->settings_repo, 13, 777);
193
194 $this->assertEquals(
196 $ass->getProgressForNode(12)->getStatus()
197 );
198 $this->assertEquals(
200 $ass->getProgressForNode(13)->getStatus()
201 );
202
203 $ass = $ass
204 ->changeProgressDeadline(
205 $this->settings_repo,
206 11,
207 7,
208 $this->messages,
209 $yesterday
210 )
211 ->changeProgressDeadline(
212 $this->settings_repo,
213 13,
214 7,
215 $this->messages,
216 $today
217 );
218
219 $this->assertEquals(
221 $ass->getProgressForNode(11)->getStatus()
222 );
223 $this->assertEquals(
225 $ass->getProgressForNode(13)->getStatus()
226 );
227 }
228
230 {
231 $ass = $this->ass->changeAmountOfPoints(
232 $this->settings_repo,
233 111,
234 7,
235 $this->messages,
236 1987
237 );
238
239 $this->assertEquals(5, $ass->getProgressForNode(111)->getAmountOfPoints());
240 $ass = $this->ass
241 ->markRelevant($this->settings_repo, 111, 7, $this->messages)
242 ->changeAmountOfPoints(
243 $this->settings_repo,
244 111,
245 7,
246 $this->messages,
247 1987
248 );
249 $this->assertEquals(1987, $ass->getProgressForNode(111)->getAmountOfPoints());
250 }
251}
Assignments are relations of users to a PRG; They hold progress-information for (sub-)nodes of the PR...
withProgressTree(ilPRGProgress $progress)
getProgressForNode(int $node_id)
Holds information about multi-actions, mainly in context of member-assignemnts and status changes.
A Progress is the status of a user on a single node of an assignment; it is unique by assignment_id:u...
withAmountOfPoints(int $points)
Additional information about a user, used in context of assignments.
Covers the persistence of settings belonging to a study programme (SP).