ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilStudyProgrammeLPTest.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2015 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
5 require_once(__DIR__ . "/mocks.php");
6 
16 {
17  protected $backupGlobals = false;
18 
19  protected function setUp()
20  {
21  PHPUnit_Framework_Error_Deprecated::$enabled = false;
22 
23  require_once("./Modules/StudyProgramme/classes/class.ilObjStudyProgramme.php");
24 
25  include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
26  ilUnitUtil::performInitialisation();
27 
29  $this->root->putInTree(ROOT_FOLDER_ID);
30  $this->root->object_factory = new ilObjectFactoryWrapperMock();
31 
32  $this->node1 = ilObjStudyProgramme::createInstance();
33  $this->node2 = ilObjStudyProgramme::createInstance();
34 
35  $this->leaf1 = new ilStudyProgrammeLeafMock();
36  $this->leaf2 = new ilStudyProgrammeLeafMock();
37 
38  $this->root->addNode($this->node1);
39  $this->root->addNode($this->node2);
40  $this->node1->addLeaf($this->leaf1);
41  $this->node2->addLeaf($this->leaf2);
42 
43  global $DIC;
44  $tree = $DIC['tree'];
45  $this->tree = $tree;
46 
47  global $DIC;
48  $ilUser = $DIC['ilUser'];
49  $this->user = $ilUser;
50  }
51 
52  protected function tearDown()
53  {
54  if ($this->root) {
55  $this->root->delete();
56  }
57  }
58 
59  protected function newUser()
60  {
61  $user = new ilObjUser();
62  $user->create();
63  return $user;
64  }
65 
66  protected function setAllNodesActive()
67  {
68  $this->root->setStatus(ilStudyProgramme::STATUS_ACTIVE)->update();
69  $this->node1->setStatus(ilStudyProgramme::STATUS_ACTIVE)->update();
70  $this->node2->setStatus(ilStudyProgramme::STATUS_ACTIVE)->update();
71  }
72 
73  protected function assignNewUserToRoot()
74  {
75  $user = $this->newUser();
76  return array($this->root->assignUser($user->getId()), $user);
77  }
78 
79  public function testInitialLPActive()
80  {
81  $this->setAllNodesActive();
82  $tmp = $this->assignNewUserToRoot();
83  $ass = $tmp[0];
84  $user = $tmp[1];
85 
86  require_once("Services/Tracking/classes/class.ilLPStatusWrapper.php");
87  require_once("Services/Tracking/classes/class.ilLPStatus.php");
88  $this->assertEquals(
90  ilLPStatusWrapper::_determineStatus($this->root->getId(), $user->getId())
91  );
92  $this->assertEquals(
94  ilLPStatusWrapper::_determineStatus($this->node1->getId(), $user->getId())
95  );
96  $this->assertEquals(
98  ilLPStatusWrapper::_determineStatus($this->node2->getId(), $user->getId())
99  );
100  }
101 
102  public function testInitialLPDraft()
103  {
104  $this->root->setStatus(ilStudyProgramme::STATUS_ACTIVE)->update();
105  $this->node1->setStatus(ilStudyProgramme::STATUS_ACTIVE)->update();
106  $this->node2->setStatus(ilStudyProgramme::STATUS_DRAFT)->update();
107 
108  $tmp = $this->assignNewUserToRoot();
109  $user = $tmp[1];
110  $ass = $tmp[0];
111 
112  require_once("Services/Tracking/classes/class.ilLPStatusWrapper.php");
113  require_once("Services/Tracking/classes/class.ilLPStatus.php");
114  $this->assertEquals(
116  ilLPStatusWrapper::_determineStatus($this->root->getId(), $user->getId())
117  );
118  $this->assertEquals(
120  ilLPStatusWrapper::_determineStatus($this->node1->getId(), $user->getId())
121  );
122  $this->assertEquals(
124  ilLPStatusWrapper::_determineStatus($this->node2->getId(), $user->getId())
125  );
126  }
127 
128  public function testInitialProgressOutdated()
129  {
130  $this->root->setStatus(ilStudyProgramme::STATUS_ACTIVE)->update();
131  $this->node1->setStatus(ilStudyProgramme::STATUS_ACTIVE)->update();
132  $this->node2->setStatus(ilStudyProgramme::STATUS_OUTDATED)->update();
133 
134  $tmp = $this->assignNewUserToRoot();
135  $user = $tmp[1];
136  $ass = $tmp[0];
137 
138  require_once("Services/Tracking/classes/class.ilLPStatusWrapper.php");
139  require_once("Services/Tracking/classes/class.ilLPStatus.php");
140  $this->assertEquals(
142  ilLPStatusWrapper::_determineStatus($this->root->getId(), $user->getId())
143  );
144  $this->assertEquals(
146  ilLPStatusWrapper::_determineStatus($this->node1->getId(), $user->getId())
147  );
148  $this->assertEquals(
150  ilLPStatusWrapper::_determineStatus($this->node2->getId(), $user->getId())
151  );
152  }
153 
154  public function testMarkAccredited()
155  {
156  $this->setAllNodesActive();
157  $tmp = $this->assignNewUserToRoot();
158  $ass = $tmp[0];
159  $user = $tmp[1];
160 
161  $user2 = $this->newUser();
162  $USER_ID = $user2->getId();
163 
164  $node2_progress = array_shift($this->node2->getProgressesOf($user->getId()));
165  $node2_progress->markAccredited($USER_ID);
166 
167  require_once("Services/Tracking/classes/class.ilLPStatusWrapper.php");
168  require_once("Services/Tracking/classes/class.ilLPStatus.php");
169  $this->assertEquals(
171  ilLPStatusWrapper::_determineStatus($this->root->getId(), $user->getId())
172  );
173  $this->assertEquals(
175  ilLPStatusWrapper::_determineStatus($this->node1->getId(), $user->getId())
176  );
177  $this->assertEquals(
179  ilLPStatusWrapper::_determineStatus($this->node2->getId(), $user->getId())
180  );
181  }
182 
183  public function testUnmarkAccredited()
184  {
185  $this->setAllNodesActive();
186  $tmp = $this->assignNewUserToRoot();
187  $ass = $tmp[0];
188  $user = $tmp[1];
189 
190  $user2 = $this->newUser();
191  $USER_ID = $user2->getId();
192 
193  $node2_progress = array_shift($this->node2->getProgressesOf($user->getId()));
194  $node2_progress->markAccredited($USER_ID);
195 
196  $this->assertEquals(
198  ilLPStatusWrapper::_determineStatus($this->node2->getId(), $user->getId())
199  );
200 
201  $node2_progress->unmarkAccredited();
202 
203  $this->assertEquals(
205  ilLPStatusWrapper::_determineStatus($this->root->getId(), $user->getId())
206  );
207  $this->assertEquals(
209  ilLPStatusWrapper::_determineStatus($this->node1->getId(), $user->getId())
210  );
211  $this->assertEquals(
213  ilLPStatusWrapper::_determineStatus($this->node2->getId(), $user->getId())
214  );
215  }
216 
217 
218  public function testMarkNotRelevant()
219  {
220  $this->setAllNodesActive();
221  $tmp = $this->assignNewUserToRoot();
222  $ass = $tmp[0];
223  $user = $tmp[1];
224 
225  $user2 = $this->newUser();
226  $USER_ID = $user2->getId();
227 
228  $node2_progress = array_shift($this->node2->getProgressesOf($user->getId()));
229  $node2_progress->markNotRelevant($USER_ID);
230 
231  $this->assertEquals(
233  ilLPStatusWrapper::_determineStatus($this->root->getId(), $user->getId())
234  );
235  $this->assertEquals(
237  ilLPStatusWrapper::_determineStatus($this->node1->getId(), $user->getId())
238  );
239  $this->assertEquals(
241  ilLPStatusWrapper::_determineStatus($this->node2->getId(), $user->getId())
242  );
243  }
244 
245  public function testMarkFailed()
246  {
247  $this->setAllNodesActive();
248  $tmp = $this->assignNewUserToRoot();
249  $ass = $tmp[0];
250  $user = $tmp[1];
251 
252  $user2 = $this->newUser();
253  $USER_ID = $user2->getId();
254 
255  $node2_progress = array_shift($this->node2->getProgressesOf($user->getId()));
256  $node2_progress->markFailed($USER_ID);
257 
258  $this->assertEquals(
260  ilLPStatusWrapper::_determineStatus($this->root->getId(), $user->getId())
261  );
262  $this->assertEquals(
264  ilLPStatusWrapper::_determineStatus($this->node1->getId(), $user->getId())
265  );
266  $this->assertEquals(
268  ilLPStatusWrapper::_determineStatus($this->node2->getId(), $user->getId())
269  );
270  }
271 
272  public function testMarkNotFailed()
273  {
274  $this->setAllNodesActive();
275  $tmp = $this->assignNewUserToRoot();
276  $ass = $tmp[0];
277  $user = $tmp[1];
278 
279  $user2 = $this->newUser();
280  $USER_ID = $user2->getId();
281 
282  $node2_progress = array_shift($this->node2->getProgressesOf($user->getId()));
283  $node2_progress->markFailed($USER_ID);
284 
285  $this->assertEquals(
287  ilLPStatusWrapper::_determineStatus($this->root->getId(), $user->getId())
288  );
289  $this->assertEquals(
291  ilLPStatusWrapper::_determineStatus($this->node1->getId(), $user->getId())
292  );
293  $this->assertEquals(
295  ilLPStatusWrapper::_determineStatus($this->node2->getId(), $user->getId())
296  );
297 
298  $node2_progress->markNotFailed($USER_ID);
299  $this->assertEquals(
301  ilLPStatusWrapper::_determineStatus($this->node2->getId(), $user->getId())
302  );
303  }
304 
305  // Neues Moduls: Wird dem Studierenden-Studierenden inkl. Kurse, Punkte als "Nicht relevant" hinzugefĆ¼gt.
306  public function testNewNodesAreNotRelevant()
307  {
308  $this->setAllNodesActive();
309  $tmp = $this->assignNewUserToRoot();
310  $ass = $tmp[0];
311  $user = $tmp[1];
312 
314  $this->root->addNode($node3);
315 
316  $node3_progress = array_shift($node3->getProgressesOf($user->getId()));
317  $this->assertNotNull($node3_progress);
318  $this->assertEquals(
320  ilLPStatusWrapper::_determineStatus($node3->getId(), $user->getId())
321  );
322  }
323 }
const LP_STATUS_COMPLETED_NUM
Mock classes for tests.
Definition: mocks.php:20
global $DIC
Definition: saml.php:7
const LP_STATUS_IN_PROGRESS_NUM
user()
Definition: user.php:4
$ilUser
Definition: imgupload.php:18
$user
Definition: migrateto20.php:57
const LP_STATUS_NOT_ATTEMPTED_NUM
static createInstance()
Create an instance of ilObjStudyProgramme, put in cache.
Mock for object factory.
Definition: mocks.php:68
static _determineStatus($a_obj_id, $a_usr_id)
Determine status.
const LP_STATUS_FAILED_NUM
TestCase for the learning progress of users at a programme.