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