ILIAS  release_8 Revision v8.24
ilStudyProgrammeAssignmentActionsTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21require_once(__DIR__ . "/../../../../../libs/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);
38 $this->settings_repo->update($settings);
39 }
40
41 $this->messages = new ilPRGMessageCollection();
42 $this->events = new ProgrammeEventsMock();
43
44 $udf = $this->getMockBuilder(ilUserDefinedData::class)
45 ->disableOriginalConstructor()
46 ->getMock();
47 $user_info = new ilPRGUserInformation(
48 $udf,
49 'some OrgU',
50 'firstname',
51 'lasttname',
52 'login',
53 true,
54 'f.lastname@example.com',
55 'f',
56 'Prof. Dr.',
57 );
58
59 $this->ass = (new ilPRGAssignment(42, 7))
60 ->withUserInformation($user_info)
61 ->withProgressTree(
64 )
65 );
66 }
67
68 protected function getProgressesWithDefaultStatus(int $status): ilPRGProgress
69 {
70 /*
71 └── 1
72 ├── 11
73 │ ├── 111
74 │ └── 112
75 ├── 12
76 └── 13
77 */
78 $pgs112 = (new ilPRGProgress(112, $status))->withAmountOfPoints(4);
79 $pgs111 = (new ilPRGProgress(111, $status))->withAmountOfPoints(5);
80 $pgs11 = (new ilPRGProgress(11, $status))->setSubnodes([$pgs111, $pgs112])->withAmountOfPoints(8);
81 $pgs12 = new ilPRGProgress(12, $status);
82 $pgs13 = new ilPRGProgress(13, $status);
83 $pgs1 = (new ilPRGProgress(1, $status))->setSubnodes([$pgs11, $pgs12, $pgs13]);
84 return $pgs1;
85 }
86
87
88 public function testPRGAssignmentActionsInitDates(): void
89 {
90 $today = (new \DateTimeImmutable())->format('Ymd');
91 $ass = $this->ass->initAssignmentDates();
92 foreach ([1, 11, 12, 13, 111, 112] as $pgs_id) {
93 $this->assertEquals(
94 $today,
95 $ass->getProgressForNode($pgs_id)->getAssignmentDate()->format('Ymd')
96 );
97 }
98 }
99
101 {
102 $ass = $this->ass->markRelevant($this->settings_repo, 111, 7, $this->messages);
103
104 $this->assertEquals(
106 $ass->getProgressForNode(111)->getStatus()
107 );
108 $this->assertEquals(
110 $ass->getProgressForNode(11)->getStatus()
111 );
112 $this->assertEquals(
114 $ass->getProgressForNode(12)->getStatus()
115 );
116
118 $ass = $this->ass
119 ->markNotRelevant($this->settings_repo, 12, 7, $messages)
120 ->markNotRelevant($this->settings_repo, 111, 7, $messages);
121
122 $this->assertTrue($messages->hasErrors());
123 $this->assertEquals(
125 $ass->getProgressForNode(12)->getStatus()
126 );
127 $this->assertEquals(
129 $ass->getProgressForNode(111)->getStatus()
130 );
131 }
132
134 {
135 $ass = $this->ass->withProgressTree(
137 );
138
139 $ass = $ass
140 ->markAccredited($this->settings_repo, $this->events, 111, 7, $this->messages)
141 ->markAccredited($this->settings_repo, $this->events, 112, 7, $this->messages)
142 ->markAccredited($this->settings_repo, $this->events, 13, 7, $this->messages);
143 $this->assertEquals(
145 $ass->getProgressForNode(111)->getStatus()
146 );
147 $this->assertEquals(
149 $ass->getProgressForNode(112)->getStatus()
150 );
151 $this->assertEquals(
153 $ass->getProgressForNode(11)->getStatus()
154 );
155 $this->assertEquals(5 + 4, $ass->getProgressForNode(11)->getCurrentAmountOfPoints());
156 $this->assertEquals(
158 $ass->getProgressForNode(13)->getStatus()
159 );
160
161 $ass = $ass
162 ->unmarkAccredited($this->settings_repo, 112, 7, $this->messages)
163 ->unmarkAccredited($this->settings_repo, 111, 7, $this->messages)
164 ->unmarkAccredited($this->settings_repo, 13, 7, $this->messages);
165
166 $this->assertEquals(
168 $ass->getProgressForNode(112)->getStatus()
169 );
170 $this->assertEquals(0, $ass->getProgressForNode(11)->getCurrentAmountOfPoints());
171 $this->assertEquals(
172 ilPRGProgress::STATUS_COMPLETED, //completion may not be revoked manually
173 $ass->getProgressForNode(13)->getStatus()
174 );
175 $this->assertEquals(
176 ilPRGProgress::STATUS_IN_PROGRESS, //completion may be revoked automatically
177 $ass->getProgressForNode(11)->getStatus()
178 );
179 }
180
182 {
183 $today = new DateTimeImmutable();
184 $yesterday = $today->sub(new DateInterval('P1D'));
185
187 $pgs12 = $pgss->getSubnode('13')->withDeadline($today);
188 $pgs13 = $pgss->getSubnode('13')->withDeadline($yesterday);
189 $pgss = $pgss
190 ->withSubnode($pgs12)
191 ->withSubnode($pgs13);
192
193 $ass = $this->ass
194 ->withProgressTree($pgss)
195 ->succeed($this->settings_repo, 12, 777)
196 ->succeed($this->settings_repo, 13, 777);
197
198 $this->assertEquals(
200 $ass->getProgressForNode(12)->getStatus()
201 );
202 $this->assertEquals(
204 $ass->getProgressForNode(13)->getStatus()
205 );
206
207 $ass = $ass
208 ->changeProgressDeadline(
209 $this->settings_repo,
210 11,
211 7,
212 $this->messages,
213 $yesterday
214 )
215 ->changeProgressDeadline(
216 $this->settings_repo,
217 13,
218 7,
219 $this->messages,
220 $today
221 );
222
223 $this->assertEquals(
225 $ass->getProgressForNode(11)->getStatus()
226 );
227 $this->assertEquals(
229 $ass->getProgressForNode(13)->getStatus()
230 );
231 }
232
234 {
235 $ass = $this->ass->changeAmountOfPoints(
236 $this->settings_repo,
237 111,
238 7,
239 $this->messages,
240 1987
241 );
242
243 $this->assertEquals(5, $ass->getProgressForNode(111)->getAmountOfPoints());
244 $ass = $this->ass
245 ->markRelevant($this->settings_repo, 111, 7, $this->messages)
246 ->changeAmountOfPoints(
247 $this->settings_repo,
248 111,
249 7,
250 $this->messages,
251 1987
252 );
253 $this->assertEquals(1987, $ass->getProgressForNode(111)->getAmountOfPoints());
254 }
255}
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)
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...
withAmountOfPoints(int $points)
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200