ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
5require_once(__DIR__."/mocks.php");
6
16 protected $backupGlobals = FALSE;
17
18 protected function setUp() {
19 PHPUnit_Framework_Error_Deprecated::$enabled = FALSE;
20
21 require_once("./Modules/StudyProgramme/classes/class.ilObjStudyProgramme.php");
22
23 include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
24 ilUnitUtil::performInitialisation();
25
27 $this->root->putInTree(ROOT_FOLDER_ID);
28 $this->root->object_factory = new ilObjectFactoryWrapperMock();
29
32
33 $this->leaf1 = new ilStudyProgrammeLeafMock();
34 $this->leaf2 = new ilStudyProgrammeLeafMock();
35
36 $this->root->addNode($this->node1);
37 $this->root->addNode($this->node2);
38 $this->node1->addLeaf($this->leaf1);
39 $this->node2->addLeaf($this->leaf2);
40
41 global $DIC;
42 $tree = $DIC['tree'];
43 $this->tree = $tree;
44
45 global $DIC;
46 $ilUser = $DIC['ilUser'];
47 $this->user = $ilUser;
48 }
49
50 protected function tearDown() {
51 if ($this->root) {
52 $this->root->delete();
53 }
54 }
55
56 protected function newUser() {
57 $user = new ilObjUser();
58 $user->create();
59 return $user;
60 }
61
62 protected function setAllNodesActive() {
63 $this->root->setStatus(ilStudyProgramme::STATUS_ACTIVE)->update();
64 $this->node1->setStatus(ilStudyProgramme::STATUS_ACTIVE)->update();
65 $this->node2->setStatus(ilStudyProgramme::STATUS_ACTIVE)->update();
66 }
67
68 protected function assignNewUserToRoot() {
69 $user = $this->newUser();
70 return array($this->root->assignUser($user->getId()), $user);
71 }
72
73 public function testInitialLPActive() {
74 $this->setAllNodesActive();
75 $tmp = $this->assignNewUserToRoot();
76 $ass = $tmp[0];
77 $user = $tmp[1];
78
79 require_once("Services/Tracking/classes/class.ilLPStatusWrapper.php");
80 require_once("Services/Tracking/classes/class.ilLPStatus.php");
81 $this->assertEquals( ilLPStatus::LP_STATUS_IN_PROGRESS_NUM
82 , ilLPStatusWrapper::_determineStatus($this->root->getId(), $user->getId())
83 );
84 $this->assertEquals( ilLPStatus::LP_STATUS_IN_PROGRESS_NUM
85 , ilLPStatusWrapper::_determineStatus($this->node1->getId(), $user->getId())
86 );
87 $this->assertEquals( ilLPStatus::LP_STATUS_IN_PROGRESS_NUM
88 , ilLPStatusWrapper::_determineStatus($this->node2->getId(), $user->getId())
89 );
90 }
91
92 public function testInitialLPDraft() {
93 $this->root->setStatus(ilStudyProgramme::STATUS_ACTIVE)->update();
94 $this->node1->setStatus(ilStudyProgramme::STATUS_ACTIVE)->update();
95 $this->node2->setStatus(ilStudyProgramme::STATUS_DRAFT)->update();
96
97 $tmp = $this->assignNewUserToRoot();
98 $user = $tmp[1];
99 $ass = $tmp[0];
100
101 require_once("Services/Tracking/classes/class.ilLPStatusWrapper.php");
102 require_once("Services/Tracking/classes/class.ilLPStatus.php");
103 $this->assertEquals( ilLPStatus::LP_STATUS_IN_PROGRESS_NUM
104 , ilLPStatusWrapper::_determineStatus($this->root->getId(), $user->getId())
105 );
106 $this->assertEquals( ilLPStatus::LP_STATUS_IN_PROGRESS_NUM
107 , ilLPStatusWrapper::_determineStatus($this->node1->getId(), $user->getId())
108 );
109 $this->assertEquals( ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM
110 , ilLPStatusWrapper::_determineStatus($this->node2->getId(), $user->getId())
111 );
112 }
113
114 public function testInitialProgressOutdated() {
115 $this->root->setStatus(ilStudyProgramme::STATUS_ACTIVE)->update();
116 $this->node1->setStatus(ilStudyProgramme::STATUS_ACTIVE)->update();
117 $this->node2->setStatus(ilStudyProgramme::STATUS_OUTDATED)->update();
118
119 $tmp = $this->assignNewUserToRoot();
120 $user = $tmp[1];
121 $ass = $tmp[0];
122
123 require_once("Services/Tracking/classes/class.ilLPStatusWrapper.php");
124 require_once("Services/Tracking/classes/class.ilLPStatus.php");
125 $this->assertEquals( ilLPStatus::LP_STATUS_IN_PROGRESS_NUM
126 , ilLPStatusWrapper::_determineStatus($this->root->getId(), $user->getId())
127 );
128 $this->assertEquals( ilLPStatus::LP_STATUS_IN_PROGRESS_NUM
129 , ilLPStatusWrapper::_determineStatus($this->node1->getId(), $user->getId())
130 );
131 $this->assertEquals( ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM
132 , ilLPStatusWrapper::_determineStatus($this->node2->getId(), $user->getId())
133 );
134 }
135
136 public function testMarkAccredited() {
137 $this->setAllNodesActive();
138 $tmp = $this->assignNewUserToRoot();
139 $ass = $tmp[0];
140 $user = $tmp[1];
141
142 $user2 = $this->newUser();
143 $USER_ID = $user2->getId();
144
145 $node2_progress = array_shift($this->node2->getProgressesOf($user->getId()));
146 $node2_progress->markAccredited($USER_ID);
147
148 require_once("Services/Tracking/classes/class.ilLPStatusWrapper.php");
149 require_once("Services/Tracking/classes/class.ilLPStatus.php");
150 $this->assertEquals( ilLPStatus::LP_STATUS_COMPLETED_NUM
151 , ilLPStatusWrapper::_determineStatus($this->root->getId(), $user->getId())
152 );
153 $this->assertEquals( ilLPStatus::LP_STATUS_IN_PROGRESS_NUM
154 , ilLPStatusWrapper::_determineStatus($this->node1->getId(), $user->getId())
155 );
156 $this->assertEquals( ilLPStatus::LP_STATUS_COMPLETED_NUM
157 , ilLPStatusWrapper::_determineStatus($this->node2->getId(), $user->getId())
158 );
159 }
160
161 public function testUnmarkAccredited() {
162 $this->setAllNodesActive();
163 $tmp = $this->assignNewUserToRoot();
164 $ass = $tmp[0];
165 $user = $tmp[1];
166
167 $user2 = $this->newUser();
168 $USER_ID = $user2->getId();
169
170 $node2_progress = array_shift($this->node2->getProgressesOf($user->getId()));
171 $node2_progress->markAccredited($USER_ID);
172
173 $this->assertEquals( ilLPStatus::LP_STATUS_COMPLETED_NUM
174 , ilLPStatusWrapper::_determineStatus($this->node2->getId(), $user->getId())
175 );
176
177 $node2_progress->unmarkAccredited();
178
179 $this->assertEquals( ilLPStatus::LP_STATUS_IN_PROGRESS_NUM
180 , ilLPStatusWrapper::_determineStatus($this->root->getId(), $user->getId())
181 );
182 $this->assertEquals( ilLPStatus::LP_STATUS_IN_PROGRESS_NUM
183 , ilLPStatusWrapper::_determineStatus($this->node1->getId(), $user->getId())
184 );
185 $this->assertEquals( ilLPStatus::LP_STATUS_IN_PROGRESS_NUM
186 , ilLPStatusWrapper::_determineStatus($this->node2->getId(), $user->getId())
187 );
188 }
189
190
191 public function testMarkNotRelevant() {
192 $this->setAllNodesActive();
193 $tmp = $this->assignNewUserToRoot();
194 $ass = $tmp[0];
195 $user = $tmp[1];
196
197 $user2 = $this->newUser();
198 $USER_ID = $user2->getId();
199
200 $node2_progress = array_shift($this->node2->getProgressesOf($user->getId()));
201 $node2_progress->markNotRelevant($USER_ID);
202
203 $this->assertEquals( ilLPStatus::LP_STATUS_IN_PROGRESS_NUM
204 , ilLPStatusWrapper::_determineStatus($this->root->getId(), $user->getId())
205 );
206 $this->assertEquals( ilLPStatus::LP_STATUS_IN_PROGRESS_NUM
207 , ilLPStatusWrapper::_determineStatus($this->node1->getId(), $user->getId())
208 );
209 $this->assertEquals( ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM
210 , ilLPStatusWrapper::_determineStatus($this->node2->getId(), $user->getId())
211 );
212 }
213
214 // Neues Moduls: Wird dem Studierenden-Studierenden inkl. Kurse, Punkte als "Nicht relevant" hinzugefügt.
215 public function testNewNodesAreNotRelevant() {
216 $this->setAllNodesActive();
217 $tmp = $this->assignNewUserToRoot();
218 $ass = $tmp[0];
219 $user = $tmp[1];
220
222 $this->root->addNode($node3);
223
224 $node3_progress = array_shift($node3->getProgressesOf($user->getId()));
225 $this->assertNotNull($node3_progress);
226 $this->assertEquals( ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM
227 , ilLPStatusWrapper::_determineStatus($node3->getId(), $user->getId())
228 );
229 }
230}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
static _determineStatus($a_obj_id, $a_usr_id)
Determine status.
const LP_STATUS_COMPLETED_NUM
const LP_STATUS_IN_PROGRESS_NUM
const LP_STATUS_NOT_ATTEMPTED_NUM
static createInstance()
Create an instance of ilObjStudyProgramme, put in cache.
Mock for object factory.
Definition: mocks.php:69
TestCase for the learning progress of users at a programme.
Mock classes for tests.
Definition: mocks.php:21
global $DIC
$ilUser
Definition: imgupload.php:18