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