ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilStudyProgrammeProgressCalculationTest.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
14{
15 protected $backupGlobals = false;
16
17 protected function setUp()
18 {
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 $this->root->setStatus(ilStudyProgramme::STATUS_ACTIVE)
30 ->update();
31
32 global $tree;
33 $this->tree = $tree;
34
35 global $ilUser;
36 $this->user = $ilUser;
37 }
38
39 protected function tearDown()
40 {
41 if ($this->root) {
42 $this->root->delete();
43 }
44 }
45
46 protected function newUser()
47 {
48 $user = new ilObjUser();
49 $user->create();
50 return $user;
51 }
52
53 protected function setUpNodes($top, $data)
54 {
55 if (!array_key_exists("points", $data)) {
56 throw new Exception("Expected to find 'points' in data array.");
57 }
58
59 $top->setPoints($data["points"]);
60
61 foreach ($data as $node_name => $data2) {
62 if ($node_name == "points") {
63 continue;
64 }
65 if (isset($this->$node_name)) {
66 throw new Exception("Node $node_name already exists.");
67 }
68
69 if ($data2 == null) {
70 $this->$node_name = new ilStudyProgrammeLeafMock();
71 $top->addLeaf($this->$node_name);
72 } else {
73 $this->$node_name = ilObjStudyProgramme::createInstance();
74 $this->$node_name->object_factory = new ilObjectFactoryWrapperMock();
75 $top->addNode($this->$node_name);
76 $this->setUpNodes($this->$node_name, $data2);
77 $this->$node_name->setStatus(ilStudyProgramme::STATUS_ACTIVE)
78 ->update();
79 }
80 }
81 }
82
83 public function testProgress1()
84 {
85 $this->setUpNodes($this->root, array( "points" => 200
86 , "node1" => array( "points" => 100
87 , "leaf11" => null
88 , "leaf12" => null
89 )
90 , "node2" => array( "points" => 100
91 , "leaf21" => null
92 , "leaf22" => null
93 )
94 ));
95
96 $user = $this->newUser();
97 $user_id = $user->getId();
98 $ass = $this->root->assignUser($user->getId());
99 $ass_id = $ass->getId();
100
101 $this->leaf11->markCompletedFor($user_id);
102 $this->leaf21->markCompletedFor($user_id);
103
104 $this->assertEquals(ilStudyProgrammeProgress::STATUS_COMPLETED, $this->root->getProgressForAssignment($ass_id)->getStatus());
105 $this->assertEquals(ilStudyProgrammeProgress::STATUS_COMPLETED, $this->node1->getProgressForAssignment($ass_id)->getStatus());
106 $this->assertEquals(ilStudyProgrammeProgress::STATUS_COMPLETED, $this->node2->getProgressForAssignment($ass_id)->getStatus());
107 }
108
109 public function testProgress2()
110 {
111 $this->setUpNodes($this->root, array( "points" => 200
112 , "node1" => array( "points" => 100
113 , "leaf11" => null
114 , "leaf12" => null
115 )
116 , "node2" => array( "points" => 100
117 , "leaf21" => null
118 , "leaf22" => null
119 )
120 ));
121
122 $user = $this->newUser();
123 $user_id = $user->getId();
124 $ass = $this->root->assignUser($user->getId());
125 $ass_id = $ass->getId();
126
127 $this->node1->getProgressForAssignment($ass_id)
128 ->markAccredited($this->user->getId());
129 $this->leaf21->markCompletedFor($user_id);
130
131 $this->assertEquals(ilStudyProgrammeProgress::STATUS_COMPLETED, $this->root->getProgressForAssignment($ass_id)->getStatus());
132 $this->assertEquals(ilStudyProgrammeProgress::STATUS_ACCREDITED, $this->node1->getProgressForAssignment($ass_id)->getStatus());
133 $this->assertEquals(ilStudyProgrammeProgress::STATUS_COMPLETED, $this->node2->getProgressForAssignment($ass_id)->getStatus());
134 }
135
136 public function testProgress3()
137 {
138 $this->setUpNodes($this->root, array( "points" => 200
139 , "node1" => array( "points" => 100
140 , "leaf11" => null
141 , "leaf12" => null
142 )
143 , "node2" => array( "points" => 100
144 , "leaf21" => null
145 , "leaf22" => null
146 )
147 ));
148
149 $user = $this->newUser();
150 $user_id = $user->getId();
151 $ass = $this->root->assignUser($user->getId());
152 $ass_id = $ass->getId();
153
154 $this->node1->getProgressForAssignment($ass_id)
155 ->markNotRelevant($this->user->getId());
156 $this->root->getProgressForAssignment($ass_id)
157 ->setRequiredAmountOfPoints(100, $this->user->getId());
158 $this->leaf21->markCompletedFor($user_id);
159
160 $this->assertEquals(ilStudyProgrammeProgress::STATUS_COMPLETED, $this->root->getProgressForAssignment($ass_id)->getStatus());
161 $this->assertEquals(ilStudyProgrammeProgress::STATUS_NOT_RELEVANT, $this->node1->getProgressForAssignment($ass_id)->getStatus());
162 $this->assertEquals(ilStudyProgrammeProgress::STATUS_COMPLETED, $this->node2->getProgressForAssignment($ass_id)->getStatus());
163 }
164
165 public function testProgress4()
166 {
167 $this->setUpNodes($this->root, array( "points" => 200
168 , "node1" => array( "points" => 100
169 , "leaf11" => null
170 , "leaf12" => null
171 )
172 , "node2" => array( "points" => 100
173 , "leaf21" => null
174 , "leaf22" => null
175 )
176 ));
177
178 $user = $this->newUser();
179 $user_id = $user->getId();
180 $ass = $this->root->assignUser($user->getId());
181 $ass_id = $ass->getId();
182
183 $this->node1->getProgressForAssignment($ass_id)
184 ->markNotRelevant($this->user->getId());
185 $this->leaf11->markCompletedFor($user_id);
186 $this->leaf21->markCompletedFor($user_id);
187
188 $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $this->root->getProgressForAssignment($ass_id)->getStatus());
189 $this->assertEquals(ilStudyProgrammeProgress::STATUS_NOT_RELEVANT, $this->node1->getProgressForAssignment($ass_id)->getStatus());
190 $this->assertEquals(ilStudyProgrammeProgress::STATUS_COMPLETED, $this->node2->getProgressForAssignment($ass_id)->getStatus());
191 }
192
194 {
195 $this->setUpNodes($this->root, array( "points" => 0
196 , "node1" => array( "points" => 100
197 , "leaf11" => null
198 , "leaf12" => null
199 )
200 , "node2" => array( "points" => 100
201 , "leaf21" => null
202 , "leaf22" => null
203 )
204 ));
205
206 $user = $this->newUser();
207 $user_id = $user->getId();
208 $ass = $this->root->assignUser($user->getId());
209 $ass_id = $ass->getId();
210
211 $this->assertEquals(ilStudyProgrammeProgress::STATUS_IN_PROGRESS, $this->root->getProgressForAssignment($ass_id)->getStatus());
212
213 $this->leaf11->markCompletedFor($user_id);
214
215 $this->assertEquals(ilStudyProgrammeProgress::STATUS_COMPLETED, $this->root->getProgressForAssignment($ass_id)->getStatus());
216 }
217}
static createInstance()
Create an instance of ilObjStudyProgramme, put in cache.
Mock for object factory.
Definition: mocks.php:66
Mock classes for tests.
Definition: mocks.php:21
TestCase for the assignment of users to a programme.
$data
global $ilUser
Definition: imgupload.php:15