ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilEventRaisingActivityTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4use org\bovigo\vfs;
5
17{
19 public $test_dir;
20
21 public function setUp()
22 {
23 chdir( dirname ( __FILE__ ) );
24 chdir('../../../../');
25
26 try
27 {
28 include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
29 //ilUnitUtil::performInitialisation();
30 }
31 catch ( Exception $exception )
32 {
33 if (!defined('IL_PHPUNIT_TEST'))
34 {
35 define('IL_PHPUNIT_TEST', FALSE);
36 }
37 }
38
39 // Empty workflow.
40 require_once './Services/WorkflowEngine/classes/workflows/class.ilEmptyWorkflow.php';
41 $this->workflow = new ilEmptyWorkflow();
42
43 // Basic node
44 require_once './Services/WorkflowEngine/classes/nodes/class.ilBasicNode.php';
45 $this->node = new ilBasicNode($this->workflow);
46
47 // Wiring up so the node is attached to the workflow.
48 $this->workflow->addNode($this->node);
49
50 require_once './Services/WorkflowEngine/classes/activities/class.ilEventRaisingActivity.php';
51
52 $this->test_dir = vfs\vfsStream::setup('example');
53 }
54
55 public function tearDown()
56 {
57 global $ilSetting;
58 if ($ilSetting != NULL)
59 {
60 //$ilSetting->delete('IL_PHPUNIT_TEST_TIME');
61 //$ilSetting->delete('IL_PHPUNIT_TEST_MICROTIME');
62 }
63 }
64
66 {
67 // Act
68 $activity = new ilEventRaisingActivity($this->node);
69
70 // Assert
71 // No exception - good
72 $this->assertTrue(
73 true,
74 'Construction failed with valid context passed to constructor.'
75 );
76 }
77
79 {
80 // Arrange
81 $activity = new ilEventRaisingActivity($this->node);
82 $expected = 'HokusPokus';
83
84 // Act
85 $activity->setEventName($expected);
86 $actual = $activity->getEventName();
87
88 $this->assertEquals(
89 $actual,
90 $expected,
91 'Retrieved EventName differs from input value.'
92 );
93 }
94
96 {
97 // Arrange
98 $activity = new ilEventRaisingActivity($this->node);
99 $expected = 'HokusPokus';
100
101 // Act
102 $activity->setEventType($expected);
103 $actual = $activity->getEventType();
104
105 $this->assertEquals(
106 $actual,
107 $expected,
108 'Retrieved EventType differs from input value.'
109 );
110 }
111
112 public function testGetContext()
113 {
114 // Arrange
115 $activity = new ilEventRaisingActivity($this->node);
116
117 // Act
118 $actual = $activity->getContext();
119
120 // Assert
121 if ($actual === $this->node)
122 {
123 $this->assertEquals($actual, $this->node);
124 } else {
125 $this->assertTrue(false, 'Context not identical.');
126 }
127 }
128
130 {
131 // Arrange
132 $activity = new ilEventRaisingActivity($this->node);
133 $key = 'Key';
134 $value = 123;
135 $expected[] = array('key' => $key, 'value' => $value);
136 $expected[] = array('key' => 'context', 'value' => $activity);
137
138 // Act
139 $activity->addFixedParam($key, $value);
140 $params = $activity->getParamsArray();
141
142 // Assert
143 $this->assertEquals($expected, $params);
144 }
145
147 {
148 // Arrange
149 $activity = new ilEventRaisingActivity($this->node);
150 $key1 = 'Key1';
151 $value1 = 123;
152 $key2 = 'Key2';
153 $value2 = 234;
154 $key3 = 'Key3';
155 $value3 = 345;
156 $expected[] = array('key' => $key1, 'value' => $value1);
157 $expected[] = array('key' => $key2, 'value' => $value2);
158 $expected[] = array('key' => $key3, 'value' => $value3);
159 $expected[] = array('key' => 'context', 'value' => $activity);
160
161 // Act
162 $activity->addFixedParam($key1, $value1);
163 $activity->addFixedParam($key2, $value2);
164 $activity->addFixedParam($key3, $value3);
165 $params = $activity->getParamsArray();
166
167 // Assert
168 $this->assertEquals($expected, $params);
169 }
170
171 public function testExecute()
172 {
173 $this->markTestIncomplete('Needs further investigation. $ilDB->quote vs. mock.');
174 // Arrange
175 $activity = new ilEventRaisingActivity($this->node);
176 $activity->setEventName('EVTName');
177 $activity->setEventType('EVTType');
178 $key = 'Key';
179 $value = 123;
180 $expected[] = array('key' => $key, 'value' => $value);
181 $expected[] = array('key' => 'context', 'value' => $activity);
182
183 $activity->addFixedParam($key, $value);
184
185 $appHandlerMock = $this->getMockBuilder('ilAppEventHandler', 'getParamsArray')
186 ->setMethods(array('raise'))
187 ->getMock();
188
189 $appHandlerMock->expects($this->once())
190 ->method('raise')
191 ->with(
192 $this->equalTo('EVTType'),
193 $this->equalTo('EVTName'),
194 $this->equalTo($expected)
195 );
196 $GLOBALS['ilAppEventHandler'] = $appHandlerMock;
197 $activity->execute();
198 }
199}
An exception for terminatinating execution or to throw for unit testing.
@noinspection PhpIncludeInspection
@noinspection PhpIncludeInspection
ilEventRaisingActivityTest is part of the workflow engine.
$test_dir
vfsStream Test Directory, see setup.
@noinspection PhpIncludeInspection
$params
Definition: example_049.php:96
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27
global $ilSetting
Definition: privfeed.php:17