ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.test_007_IntermediateCatchEvent.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/WorkflowEngine/test/ilWorkflowEngineBaseTest.php';
5 
13 {
14  #region Helper
15  public $base_path = './Services/WorkflowEngine/test/parser/';
16  public $suite_path = '007_IntermediateCatchEvent/';
17 
18  public function getTestInputFilename($test_name)
19  {
20  return $this->base_path . $this->suite_path . $test_name . '.bpmn2';
21  }
22 
23  public function getTestOutputFilename($test_name)
24  {
25  return $this->base_path . $this->suite_path . $test_name . '_output.php';
26  }
27 
28  public function getTestGoldsampleFilename($test_name)
29  {
30  return $this->base_path . $this->suite_path . $test_name . '_goldsample.php';
31  }
32 
33  public function setUp() : void
34  {
35  chdir(dirname(__FILE__));
36  chdir('../../../../../');
37 
38  parent::setUp();
39 
40  require_once './Services/WorkflowEngine/classes/parser/class.ilBPMN2Parser.php';
41  }
42 
43  public function test_WorkflowWithSimpleIntermediateMessageEventShouldOutputAccordingly()
44  {
45  $test_name = 'IntermediateCatchEvent_Message_Simple';
46  $xml = file_get_contents($this->getTestInputFilename($test_name));
47  $parser = new ilBPMN2Parser();
48  $parse_result = $parser->parseBPMN2XML($xml);
49 
50  file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
51  $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
52 
53  $this->assertTrue(substr($return, 0, 25) == 'No syntax errors detected', 'Lint of output code failed.');
54 
55  $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
56  $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
57 
58  $ildb_mock = $this->getMockBuilder(ilDBInterface::class)->getMock();
59  $ildb_mock->expects($this->any())->method('quote')->will($this->returnCallback(''));
60  $i = 0;
61  $ildb_mock->expects($this->any())->method('nextId')->will($this->returnValue($i++));
62  $ildb_mock->expects($this->any())->method('insert')->will($this->returnValue(true));
63 
64  global $ilDB;
65  $ilDB = $ildb_mock;
66  $GLOBALS['ilDB'] = $ildb_mock;
67 
68  require_once $this->getTestOutputFilename($test_name);
70  $process = new $test_name;
71  $process->startWorkflow();
72  $all_triggered = true;
73  foreach ($process->getNodes() as $node) {
75  foreach ($node->getDetectors() as $detector) {
77  if (!$detector->getActivated()) {
78  $all_triggered = false;
79  }
80  }
81  foreach ($node->getEmitters() as $emitter) {
83  if (!$emitter->getActivated()) {
84  $all_triggered = false;
85  }
86  }
87  }
88  $this->assertFalse($all_triggered, 'All nodes were triggered (but should not since the event was not handled.');
89 
90  $process->handleEvent(
91  array(
92  'Course',
93  'UserWasAssigned',
94  'usr',
95  0,
96  'crs',
97  0
98  )
99  );
100 
101  $all_triggered = true;
102  foreach ($process->getNodes() as $node) {
104  foreach ($node->getDetectors() as $detector) {
106  if (!$detector->getActivated()) {
107  $all_triggered = false;
108  }
109  }
110  foreach ($node->getEmitters() as $emitter) {
112  if (!$emitter->getActivated()) {
113  $all_triggered = false;
114  }
115  }
116  }
117  $this->assertTrue($all_triggered, 'Not all nodes were triggered.');
118 
119  unlink($this->getTestOutputFilename($test_name));
120  }
121 
122  public function test_WorkflowWithSimpleIntermediateSignalEventShouldOutputAccordingly()
123  {
124  $test_name = 'IntermediateCatchEvent_Signal_Simple';
125  $xml = file_get_contents($this->getTestInputFilename($test_name));
126  $parser = new ilBPMN2Parser();
127  $parse_result = $parser->parseBPMN2XML($xml);
128 
129  file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
130  $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
131 
132  $this->assertTrue(substr($return, 0, 25) == 'No syntax errors detected', 'Lint of output code failed.');
133 
134  $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
135  $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
136 
137  $ildb_mock = $this->getMockBuilder(ilDBInterface::class)->getMock();
138  $ildb_mock->expects($this->any())->method('quote')->will($this->returnCallback(''));
139  $i = 0;
140  $ildb_mock->expects($this->any())->method('nextId')->will($this->returnValue($i++));
141  $ildb_mock->expects($this->any())->method('insert')->will($this->returnValue(true));
142 
143  global $ilDB;
144  $ilDB = $ildb_mock;
145  $GLOBALS['ilDB'] = $ildb_mock;
146 
147  require_once $this->getTestOutputFilename($test_name);
149  $process = new $test_name;
150  $process->startWorkflow();
151  $all_triggered = true;
152  foreach ($process->getNodes() as $node) {
154  foreach ($node->getDetectors() as $detector) {
156  if (!$detector->getActivated()) {
157  $all_triggered = false;
158  }
159  }
160  foreach ($node->getEmitters() as $emitter) {
162  if (!$emitter->getActivated()) {
163  $all_triggered = false;
164  }
165  }
166  }
167  $this->assertFalse($all_triggered, 'All nodes were triggered (but should not since the event was not handled.');
168 
169  $process->handleEvent(
170  array(
171  'Course',
172  'UserLeft',
173  'usr',
174  0,
175  'crs',
176  0
177  )
178  );
179 
180  $all_triggered = true;
181  foreach ($process->getNodes() as $node) {
183  foreach ($node->getDetectors() as $detector) {
185  if (!$detector->getActivated()) {
186  $all_triggered = false;
187  }
188  }
189  foreach ($node->getEmitters() as $emitter) {
191  if (!$emitter->getActivated()) {
192  $all_triggered = false;
193  }
194  }
195  }
196  $this->assertTrue($all_triggered, 'Not all nodes were triggered.');
197 
198  unlink($this->getTestOutputFilename($test_name));
199  }
200 
201  public function test_WorkflowWithSimpleIntermediateTimerEventShouldOutputAccordingly()
202  {
203  $test_name = 'IntermediateCatchEvent_Timer_Simple';
204  $xml = file_get_contents($this->getTestInputFilename($test_name));
205  $parser = new ilBPMN2Parser();
206  $parse_result = $parser->parseBPMN2XML($xml);
207 
208  file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
209  $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
210 
211  $this->assertTrue(substr($return, 0, 25) == 'No syntax errors detected', 'Lint of output code failed.');
212 
213  $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
214  $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
215 
216  $ildb_mock = $this->getMockBuilder(ilDBInterface::class)->getMock();
217  $ildb_mock->expects($this->any())->method('quote')->will($this->returnCallback(''));
218  $i = 0;
219  $ildb_mock->expects($this->any())->method('nextId')->will($this->returnValue($i++));
220  $ildb_mock->expects($this->any())->method('insert')->will($this->returnValue(true));
221 
222  global $ilDB;
223  $ilDB = $ildb_mock;
224  $GLOBALS['ilDB'] = $ildb_mock;
225 
226  require_once $this->getTestOutputFilename($test_name);
228  $process = new $test_name;
229  $process->startWorkflow();
230  $all_triggered = true;
231  foreach ($process->getNodes() as $node) {
233  foreach ($node->getDetectors() as $detector) {
235  if (!$detector->getActivated()) {
236  $all_triggered = false;
237  }
238  }
239  foreach ($node->getEmitters() as $emitter) {
241  if (!$emitter->getActivated()) {
242  $all_triggered = false;
243  }
244  }
245  }
246  $this->assertFalse($all_triggered, 'All nodes were triggered (but should not since the event was not handled.');
247 
248  $process->handleEvent(
249  array(
250  'time_passed',
251  'time_passed',
252  'none',
253  0,
254  'none',
255  0
256  )
257  );
258 
259  $all_triggered = true;
260  foreach ($process->getNodes() as $node) {
262  foreach ($node->getDetectors() as $detector) {
264  if (!$detector->getActivated()) {
265  $all_triggered = false;
266  }
267  }
268  foreach ($node->getEmitters() as $emitter) {
270  if (!$emitter->getActivated()) {
271  $all_triggered = false;
272  }
273  }
274  }
275  $this->assertTrue($all_triggered, 'Not all nodes were triggered.');
276 
277  unlink($this->getTestOutputFilename($test_name));
278  }
279 }
Class ilWorkflowEngineBaseTest.
$parse_result
Definition: BPMN2Parser.php:25
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$xml
Definition: metadata.php:332
$parser
Definition: BPMN2Parser.php:23
global $ilDB
Class ilBPMN2Parser.
$i
Definition: metadata.php:24