ILIAS  release_7 Revision v7.30-3-g800a261c036
ilStudyProgrammeEventsTest.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2009 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24use PHPUnit\Framework\TestCase;
25
26require_once(__DIR__ . "/mocks.php");
27
36class ilStudyProgrammeEventsTest extends TestCase
37{
38 protected $backupGlobals = false;
39
40 protected function setUp() : void
41 {
42 require_once("./Modules/StudyProgramme/classes/class.ilObjStudyProgramme.php");
43 PHPUnit\Framework\Error\Deprecated::$enabled = false;
44
45 global $DIC;
46 if (!$DIC) {
47 include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
48 ilUnitUtil::performInitialisation();
49 }
50
52 $this->root_obj_id = $this->root->getId();
53 $this->root_ref_id = $this->root->getRefId();
54 $this->root->putInTree(ROOT_FOLDER_ID);
55 $this->root->setStatus(ilStudyProgrammeSettings::STATUS_ACTIVE);
56 $this->root->object_factory = new ilObjectFactoryWrapperMock();
57
59 $this->node->object_factory = new ilObjectFactoryWrapperMock();
60 $this->root->addNode($this->node);
61
62 $this->leaf = new ilStudyProgrammeLeafMock();
63 $this->node->addLeaf($this->leaf);
64 $this->node->setStatus(ilStudyProgrammeSettings::STATUS_ACTIVE);
65
66 $this->users = array();
67
68 require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeEvents.php");
69 $this->event_handler_mock = new ilAppEventHandlerMock();
70 ilStudyProgrammeDIC::dic()['ilStudyProgrammeEvents']->app_event_handler = $this->event_handler_mock;
71 }
72
73 protected function newUser()
74 {
75 $user = new ilObjUser();
76 $user->create();
77 $this->users[] = $user;
78 return $user;
79 }
80
81 protected function tearDown() : void
82 {
83 foreach ($this->users as $user) {
84 $user->delete();
85 }
86 if ($this->root) {
87 $this->root->delete();
88 }
89 }
90
91 public function testAssignUser()
92 {
93 $user = $this->newUser();
94 $ass = $this->root->assignUser($user->getId(), 6);
95
96 $this->assertCount(1, $this->event_handler_mock->events);
97 $event = array_pop($this->event_handler_mock->events);
98
99 $this->assertEquals("Modules/StudyProgramme", $event["component"]);
100 $this->assertEquals("userAssigned", $event["event"]);
101 $this->assertEquals($this->root->getId(), $event["parameters"]["root_prg_id"]);
102 $this->assertEquals($user->getId(), $event["parameters"]["usr_id"]);
103 $this->assertEquals($ass->getId(), $event["parameters"]["ass_id"]);
104 }
105
106 public function testDeassignUser()
107 {
108 $user = $this->newUser();
109 $ass = $this->root->assignUser($user->getId(), 6);
110 $this->event_handler_mock->events = array();
111
112 $ass->deassign();
113
114 $this->assertCount(1, $this->event_handler_mock->events);
115
116 $event = array_pop($this->event_handler_mock->events);
117 $this->assertEquals("Modules/StudyProgramme", $event["component"]);
118 $this->assertEquals("userDeassigned", $event["event"]);
119 $this->assertEquals($this->root->getId(), $event["parameters"]["root_prg_id"]);
120 $this->assertEquals($user->getId(), $event["parameters"]["usr_id"]);
121 $this->assertEquals($ass->getId(), $event["parameters"]["ass_id"]);
122 }
123
125 {
126 $user = $this->newUser();
127 $ass = $this->root->assignUser($user->getId(), 6);
128 $this->event_handler_mock->events = array();
129
130 $this->leaf->markCompletedFor($user->getId());
131
132 $this->assertCount(2, $this->event_handler_mock->events);
133
134 $event = array_shift($this->event_handler_mock->events);
135 $this->assertEquals("Modules/StudyProgramme", $event["component"]);
136 $this->assertEquals("userSuccessful", $event["event"]);
137 $this->assertEquals($this->root->getId(), $event["parameters"]["root_prg_id"]);
138 $this->assertEquals($this->node->getId(), $event["parameters"]["prg_id"]);
139 $this->assertEquals($user->getId(), $event["parameters"]["usr_id"]);
140 $this->assertEquals($ass->getId(), $event["parameters"]["ass_id"]);
141
142 $event = array_shift($this->event_handler_mock->events);
143 $this->assertEquals("Modules/StudyProgramme", $event["component"]);
144 $this->assertEquals("userSuccessful", $event["event"]);
145 $this->assertEquals($this->root->getId(), $event["parameters"]["root_prg_id"]);
146 $this->assertEquals($this->root->getId(), $event["parameters"]["prg_id"]);
147 $this->assertEquals($user->getId(), $event["parameters"]["usr_id"]);
148 $this->assertEquals($ass->getId(), $event["parameters"]["ass_id"]);
149 }
150
152 {
153 $user = $this->newUser();
154 $ass = $this->root->assignUser($user->getId(), 6);
155 $this->event_handler_mock->events = array();
156
157 $progress = $this->node->getProgressForAssignment($ass->getId());
158 $progress->markAccredited(6);
159
160 $this->assertCount(2, $this->event_handler_mock->events);
161
162 $event = array_shift($this->event_handler_mock->events);
163 $this->assertEquals("Modules/StudyProgramme", $event["component"]);
164 $this->assertEquals("userSuccessful", $event["event"]);
165 $this->assertEquals($this->root->getId(), $event["parameters"]["root_prg_id"]);
166 $this->assertEquals($this->node->getId(), $event["parameters"]["prg_id"]);
167 $this->assertEquals($user->getId(), $event["parameters"]["usr_id"]);
168 $this->assertEquals($ass->getId(), $event["parameters"]["ass_id"]);
169
170 $event = array_shift($this->event_handler_mock->events);
171 $this->assertEquals("Modules/StudyProgramme", $event["component"]);
172 $this->assertEquals("userSuccessful", $event["event"]);
173 $this->assertEquals($this->root->getId(), $event["parameters"]["root_prg_id"]);
174 $this->assertEquals($this->root->getId(), $event["parameters"]["prg_id"]);
175 $this->assertEquals($user->getId(), $event["parameters"]["usr_id"]);
176 $this->assertEquals($ass->getId(), $event["parameters"]["ass_id"]);
177 }
178}
An exception for terminatinating execution or to throw for unit testing.
Mock for ilAppEventHandler.
Definition: mocks.php:83
static createInstance()
Create an instance of ilObjStudyProgramme, put in cache.
Mock for object factory.
Definition: mocks.php:69
TestCase for the ilObjStudyProgramme @group needsInstalledILIAS.
Mock classes for tests.
Definition: mocks.php:21
const ROOT_FOLDER_ID
Definition: constants.php:30
global $DIC
Definition: goto.php:24