ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
24require_once(__DIR__."/mocks.php");
25
35 protected $backupGlobals = FALSE;
36
37 protected function setUp() {
38 PHPUnit_Framework_Error_Deprecated::$enabled = FALSE;
39
40 require_once("./Modules/StudyProgramme/classes/class.ilObjStudyProgramme.php");
41
42 include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
43 ilUnitUtil::performInitialisation();
44
46 $this->root_obj_id = $this->root->getId();
47 $this->root_ref_id = $this->root->getRefId();
48 $this->root->putInTree(ROOT_FOLDER_ID);
49 $this->root->setStatus(ilStudyProgramme::STATUS_ACTIVE);
50 $this->root->object_factory = new ilObjectFactoryWrapperMock();
51
53 $this->node->object_factory = new ilObjectFactoryWrapperMock();
54 $this->root->addNode($this->node);
55
56 $this->leaf = new ilStudyProgrammeLeafMock();
57 $this->node->addLeaf($this->leaf);
58 $this->node->setStatus(ilStudyProgramme::STATUS_ACTIVE);
59
60 $this->users = array();
61
62 require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeEvents.php");
63 $this->event_handler_mock = new ilAppEventHandlerMock();
64 ilStudyProgrammeEvents::$app_event_handler = $this->event_handler_mock;
65 }
66
67 protected function newUser() {
68 $user = new ilObjUser();
69 $user->create();
70 $this->users[] = $user;
71 return $user;
72 }
73
74 protected function tearDown() {
75 foreach($this->users as $user) {
76 $user->delete();
77 }
78 if ($this->root) {
79 $this->root->delete();
80 }
81 }
82
83 public function testAssignUser() {
84 $user = $this->newUser();
85 $ass = $this->root->assignUser($user->getId());
86
87 $this->assertCount(1, $this->event_handler_mock->events);
88 $event = array_pop($this->event_handler_mock->events);
89
90 $this->assertEquals("Modules/StudyProgramme", $event["component"]);
91 $this->assertEquals("userAssigned", $event["event"]);
92 $this->assertEquals($this->root->getId(), $event["parameters"]["root_prg_id"]);
93 $this->assertEquals($user->getId(), $event["parameters"]["usr_id"]);
94 $this->assertEquals($ass->getId(), $event["parameters"]["ass_id"]);
95 }
96
97 public function testDeassignUser() {
98 $user = $this->newUser();
99 $ass = $this->root->assignUser($user->getId());
100 $this->event_handler_mock->events = array();
101
102 $ass->deassign();
103
104 $this->assertCount(1, $this->event_handler_mock->events);
105
106 $event = array_pop($this->event_handler_mock->events);
107 $this->assertEquals("Modules/StudyProgramme", $event["component"]);
108 $this->assertEquals("userDeassigned", $event["event"]);
109 $this->assertEquals($this->root->getId(), $event["parameters"]["root_prg_id"]);
110 $this->assertEquals($user->getId(), $event["parameters"]["usr_id"]);
111 $this->assertEquals($ass->getId(), $event["parameters"]["ass_id"]);
112 }
113
115 $user = $this->newUser();
116 $ass = $this->root->assignUser($user->getId());
117 $this->event_handler_mock->events = array();
118
119 $this->leaf->markCompletedFor($user->getId());
120
121 $this->assertCount(2, $this->event_handler_mock->events);
122
123 $event = array_shift($this->event_handler_mock->events);
124 $this->assertEquals("Modules/StudyProgramme", $event["component"]);
125 $this->assertEquals("userSuccessful", $event["event"]);
126 $this->assertEquals($this->root->getId(), $event["parameters"]["root_prg_id"]);
127 $this->assertEquals($this->node->getId(), $event["parameters"]["prg_id"]);
128 $this->assertEquals($user->getId(), $event["parameters"]["usr_id"]);
129 $this->assertEquals($ass->getId(), $event["parameters"]["ass_id"]);
130
131 $event = array_shift($this->event_handler_mock->events);
132 $this->assertEquals("Modules/StudyProgramme", $event["component"]);
133 $this->assertEquals("userSuccessful", $event["event"]);
134 $this->assertEquals($this->root->getId(), $event["parameters"]["root_prg_id"]);
135 $this->assertEquals($this->root->getId(), $event["parameters"]["prg_id"]);
136 $this->assertEquals($user->getId(), $event["parameters"]["usr_id"]);
137 $this->assertEquals($ass->getId(), $event["parameters"]["ass_id"]);
138 }
139
141 $user = $this->newUser();
142 $ass = $this->root->assignUser($user->getId());
143 $this->event_handler_mock->events = array();
144
145 $progress = $this->node->getProgressForAssignment($ass->getId());
146 $progress->markAccredited(6);
147
148 $this->assertCount(2, $this->event_handler_mock->events);
149
150 $event = array_shift($this->event_handler_mock->events);
151 $this->assertEquals("Modules/StudyProgramme", $event["component"]);
152 $this->assertEquals("userSuccessful", $event["event"]);
153 $this->assertEquals($this->root->getId(), $event["parameters"]["root_prg_id"]);
154 $this->assertEquals($this->node->getId(), $event["parameters"]["prg_id"]);
155 $this->assertEquals($user->getId(), $event["parameters"]["usr_id"]);
156 $this->assertEquals($ass->getId(), $event["parameters"]["ass_id"]);
157
158 $event = array_shift($this->event_handler_mock->events);
159 $this->assertEquals("Modules/StudyProgramme", $event["component"]);
160 $this->assertEquals("userSuccessful", $event["event"]);
161 $this->assertEquals($this->root->getId(), $event["parameters"]["root_prg_id"]);
162 $this->assertEquals($this->root->getId(), $event["parameters"]["prg_id"]);
163 $this->assertEquals($user->getId(), $event["parameters"]["usr_id"]);
164 $this->assertEquals($ass->getId(), $event["parameters"]["ass_id"]);
165 }
166}
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