ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.test_003_ParallelGateway.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 = '003_ParallelGateway/';
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()
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_WorkflowWithSimpleParallelGatewayShouldOutputAccordingly()
44  {
45  $test_name = 'ParallelGateway_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  require_once $this->getTestOutputFilename($test_name);
60  $process = new $test_name;
61  $this->assertFalse($process->isActive());
62 
63  /*
64  * The workflow consists of a start node, a parallel gateway and three end nodes.
65  * In order for this to work properly, the following is supposed to happen:
66  * 1. Upon start of the workflow, the start node is activated and control flow forwards to the parallel gateway.
67  * 2. All three outgoing flows forward to the end nodes.
68  * Effectively, the workflow should be immediately inactive after start with all emitter-detector-pairs
69  * being active for a short moment we can't capture from here.
70  */
71  $process->startWorkflow();
72  $this->assertTrue($process->isActive());
73 
74  $all_triggered = true;
75  foreach ($process->getNodes() as $node) {
77  foreach ($node->getDetectors() as $detector) {
79  if (!$detector->getActivated()) {
80  $all_triggered = false;
81  }
82  }
83  foreach ($node->getEmitters() as $emitter) {
85  if (!$emitter->getActivated()) {
86  $all_triggered = false;
87  }
88  }
89  }
90  $this->assertTrue($all_triggered, 'Not all nodes were triggered immediately on activation.');
91  unlink($this->getTestOutputFilename($test_name));
92  }
93 
94  public function test_WorkflowWithJoiningParallelGatewayShouldOutputAccordingly()
95  {
96  $test_name = 'ParallelGateway_Joining';
97  $xml = file_get_contents($this->getTestInputFilename($test_name));
98  $parser = new ilBPMN2Parser();
99  $parse_result = $parser->parseBPMN2XML($xml);
100 
101  file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
102  $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
103 
104  $this->assertTrue(substr($return, 0, 25) == 'No syntax errors detected', 'Lint of output code failed.');
105 
106  $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
107  $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
108 
109  require_once $this->getTestOutputFilename($test_name);
110  $process = new $test_name;
111  $this->assertFalse($process->isActive());
112 
113  $process->startWorkflow();
114  $all_triggered = true;
115  foreach ($process->getNodes() as $node) {
117  foreach ($node->getDetectors() as $detector) {
119  if (!$detector->getActivated()) {
120  $all_triggered = false;
121  }
122  }
123  foreach ($node->getEmitters() as $emitter) {
125  if (!$emitter->getActivated()) {
126  $all_triggered = false;
127  }
128  }
129  }
130  $this->assertTrue($all_triggered);
131  unlink($this->getTestOutputFilename($test_name));
132  }
133 
134  public function test_WorkflowWithForkingParallelGatewayShouldOutputAccordingly()
135  {
136  $test_name = 'ParallelGateway_Forking';
137  $xml = file_get_contents($this->getTestInputFilename($test_name));
138  $parser = new ilBPMN2Parser();
139  $parse_result = $parser->parseBPMN2XML($xml);
140 
141  file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
142  $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
143 
144  $this->assertTrue(substr($return, 0, 25) == 'No syntax errors detected', 'Lint of output code failed.');
145 
146  $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
147  $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
148 
149  require_once $this->getTestOutputFilename($test_name);
150  $process = new $test_name;
151  $this->assertFalse($process->isActive());
152 
153  $process->startWorkflow();
154  $all_triggered = true;
155  foreach ($process->getNodes() as $node) {
157  foreach ($node->getDetectors() as $detector) {
159  if (!$detector->getActivated()) {
160  $all_triggered = false;
161  }
162  }
163  foreach ($node->getEmitters() as $emitter) {
165  if (!$emitter->getActivated()) {
166  $all_triggered = false;
167  }
168  }
169  }
170  $this->assertTrue($all_triggered);
171 
172  unlink($this->getTestOutputFilename($test_name));
173  }
174 }
Class ilWorkflowEngineBaseTest.
$parse_result
Definition: BPMN2Parser.php:25
$xml
Definition: metadata.php:240
$parser
Definition: BPMN2Parser.php:23
Class ilBPMN2Parser.