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