ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
6 
18 {
20  public $test_dir;
21 
22  public function setUp() : void
23  {
24  chdir(dirname(__FILE__));
25  chdir('../../../../');
26 
27  try {
28  include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
29  //ilUnitUtil::performInitialisation();
30  } catch (Exception $exception) {
31  if (!defined('IL_PHPUNIT_TEST')) {
32  define('IL_PHPUNIT_TEST', false);
33  }
34  }
35 
36  // Empty workflow.
37  require_once './Services/WorkflowEngine/classes/workflows/class.ilEmptyWorkflow.php';
38  $this->workflow = new ilEmptyWorkflow();
39 
40  // Basic node
41  require_once './Services/WorkflowEngine/classes/nodes/class.ilBasicNode.php';
42  $this->node = new ilBasicNode($this->workflow);
43 
44  // Wiring up so the node is attached to the workflow.
45  $this->workflow->addNode($this->node);
46 
47  require_once './Services/WorkflowEngine/classes/activities/class.ilEventRaisingActivity.php';
48 
49  $this->test_dir = vfs\vfsStream::setup('example');
50  }
51 
52  public function tearDown() : void
53  {
54  global $ilSetting;
55  if ($ilSetting != null) {
56  //$ilSetting->delete('IL_PHPUNIT_TEST_TIME');
57  //$ilSetting->delete('IL_PHPUNIT_TEST_MICROTIME');
58  }
59  }
60 
61  public function testConstructorValidContext()
62  {
63  // Act
64  $activity = new ilEventRaisingActivity($this->node);
65 
66  // Assert
67  // No exception - good
68  $this->assertTrue(
69  true,
70  'Construction failed with valid context passed to constructor.'
71  );
72  }
73 
75  {
76  // Arrange
77  $activity = new ilEventRaisingActivity($this->node);
78  $expected = 'HokusPokus';
79 
80  // Act
81  $activity->setEventName($expected);
82  $actual = $activity->getEventName();
83 
84  $this->assertEquals(
85  $actual,
86  $expected,
87  'Retrieved EventName differs from input value.'
88  );
89  }
90 
92  {
93  // Arrange
94  $activity = new ilEventRaisingActivity($this->node);
95  $expected = 'HokusPokus';
96 
97  // Act
98  $activity->setEventType($expected);
99  $actual = $activity->getEventType();
100 
101  $this->assertEquals(
102  $actual,
103  $expected,
104  'Retrieved EventType differs from input value.'
105  );
106  }
107 
108  public function testGetContext()
109  {
110  // Arrange
111  $activity = new ilEventRaisingActivity($this->node);
112 
113  // Act
114  $actual = $activity->getContext();
115 
116  // Assert
117  if ($actual === $this->node) {
118  $this->assertEquals($actual, $this->node);
119  } else {
120  $this->assertTrue(false, 'Context not identical.');
121  }
122  }
123 
125  {
126  // Arrange
127  $activity = new ilEventRaisingActivity($this->node);
128  $key = 'Key';
129  $value = 123;
130  $expected[] = array('key' => $key, 'value' => $value);
131  $expected[] = array('key' => 'context', 'value' => $activity);
132 
133  // Act
134  $activity->addFixedParam($key, $value);
135  $params = $activity->getParamsArray();
136 
137  // Assert
138  $this->assertEquals($expected, $params);
139  }
140 
142  {
143  // Arrange
144  $activity = new ilEventRaisingActivity($this->node);
145  $key1 = 'Key1';
146  $value1 = 123;
147  $key2 = 'Key2';
148  $value2 = 234;
149  $key3 = 'Key3';
150  $value3 = 345;
151  $expected[] = array('key' => $key1, 'value' => $value1);
152  $expected[] = array('key' => $key2, 'value' => $value2);
153  $expected[] = array('key' => $key3, 'value' => $value3);
154  $expected[] = array('key' => 'context', 'value' => $activity);
155 
156  // Act
157  $activity->addFixedParam($key1, $value1);
158  $activity->addFixedParam($key2, $value2);
159  $activity->addFixedParam($key3, $value3);
160  $params = $activity->getParamsArray();
161 
162  // Assert
163  $this->assertEquals($expected, $params);
164  }
165 }
PhpIncludeInspection
$test_dir
vfsStream Test Directory, see setup.
global $ilSetting
Definition: privfeed.php:17
PhpIncludeInspection
ilEventRaisingActivityTest is part of the workflow engine.