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