ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
11{
12 #region Helper
13 public $base_path = './Services/WorkflowEngine/test/parser/';
14 public $suite_path = '003_ParallelGateway/';
15
16 public function getTestInputFilename($test_name)
17 {
18 return $this->base_path . $this->suite_path . $test_name . '.bpmn2';
19 }
20
21 public function getTestOutputFilename($test_name)
22 {
23 return $this->base_path . $this->suite_path . $test_name . '_output.php';
24 }
25
26 public function getTestGoldsampleFilename($test_name)
27 {
28 return $this->base_path . $this->suite_path . $test_name . '_goldsample.php';
29 }
30
31 public function setUp()
32 {
33 chdir( dirname( __FILE__ ) );
34 chdir( '../../../../../' );
35
36 require_once './Services/WorkflowEngine/classes/parser/class.ilBPMN2Parser.php';
37 }
38
39 public function test_WorkflowWithSimpleParallelGatewayShouldOutputAccordingly()
40 {
41 $test_name = 'ParallelGateway_Simple';
42 $xml = file_get_contents($this->getTestInputFilename($test_name));
43 $parser = new ilBPMN2Parser();
44 $parse_result = $parser->parseBPMN2XML($xml);
45
46 file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
47 $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
48
49 $this->assertTrue(substr($return,0,25) == 'No syntax errors detected', 'Lint of output code failed.');
50
51 $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
52 $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
53
54 require_once $this->getTestOutputFilename($test_name);
56 $process = new $test_name;
57 $this->assertFalse($process->isActive());
58
59 /*
60 * The workflow consists of a start node, a parallel gateway and three end nodes.
61 * In order for this to work properly, the following is supposed to happen:
62 * 1. Upon start of the workflow, the start node is activated and control flow forwards to the parallel gateway.
63 * 2. All three outgoing flows forward to the end nodes.
64 * Effectively, the workflow should be immediately inactive after start with all emitter-detector-pairs
65 * being active for a short moment we can't capture from here.
66 */
67 $process->startWorkflow();
68 $this->assertTrue($process->isActive());
69
70 $all_triggered = true;
71 foreach($process->getNodes() as $node)
72 {
74 foreach($node->getDetectors() as $detector)
75 {
77 if(!$detector->getActivated())
78 {
79 $all_triggered = false;
80 }
81 }
82 foreach($node->getEmitters() as $emitter)
83 {
85 if(!$emitter->getActivated())
86 {
87 $all_triggered = false;
88 }
89 }
90 }
91 $this->assertTrue($all_triggered, 'Not all nodes were triggered immediately on activation.');
92 unlink($this->getTestOutputFilename($test_name));
93 }
94
95 public function test_WorkflowWithJoiningParallelGatewayShouldOutputAccordingly()
96 {
97 $test_name = 'ParallelGateway_Joining';
98 $xml = file_get_contents($this->getTestInputFilename($test_name));
99 $parser = new ilBPMN2Parser();
100 $parse_result = $parser->parseBPMN2XML($xml);
101
102 file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
103 $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
104
105 $this->assertTrue(substr($return,0,25) == 'No syntax errors detected', 'Lint of output code failed.');
106
107 $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
108 $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
109
110 require_once $this->getTestOutputFilename($test_name);
111 $process = new $test_name;
112 $this->assertFalse($process->isActive());
113
114 $process->startWorkflow();
115 $all_triggered = true;
116 foreach($process->getNodes() as $node)
117 {
119 foreach($node->getDetectors() as $detector)
120 {
122 if(!$detector->getActivated())
123 {
124 $all_triggered = false;
125 }
126 }
127 foreach($node->getEmitters() as $emitter)
128 {
130 if(!$emitter->getActivated())
131 {
132 $all_triggered = false;
133 }
134 }
135 }
136 $this->assertTrue($all_triggered);
137 unlink($this->getTestOutputFilename($test_name));
138 }
139
140 public function test_WorkflowWithForkingParallelGatewayShouldOutputAccordingly()
141 {
142 $test_name = 'ParallelGateway_Forking';
143 $xml = file_get_contents($this->getTestInputFilename($test_name));
144 $parser = new ilBPMN2Parser();
145 $parse_result = $parser->parseBPMN2XML($xml);
146
147 file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
148 $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
149
150 $this->assertTrue(substr($return,0,25) == 'No syntax errors detected', 'Lint of output code failed.');
151
152 $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
153 $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
154
155 require_once $this->getTestOutputFilename($test_name);
156 $process = new $test_name;
157 $this->assertFalse($process->isActive());
158
159 $process->startWorkflow();
160 $all_triggered = true;
161 foreach($process->getNodes() as $node)
162 {
164 foreach($node->getDetectors() as $detector)
165 {
167 if(!$detector->getActivated())
168 {
169 $all_triggered = false;
170 }
171 }
172 foreach($node->getEmitters() as $emitter)
173 {
175 if(!$emitter->getActivated())
176 {
177 $all_triggered = false;
178 }
179 }
180 }
181 $this->assertTrue($all_triggered);
182
183 unlink($this->getTestOutputFilename($test_name));
184 }
185}
$parser
Definition: BPMN2Parser.php:24
$parse_result
Definition: BPMN2Parser.php:26
An exception for terminatinating execution or to throw for unit testing.