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