ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
11{
12 #region Helper
13 public $base_path = './Services/WorkflowEngine/test/parser/';
14 public $suite_path = '007_IntermediateCatchEvent/';
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_WorkflowWithSimpleIntermediateMessageEventShouldOutputAccordingly()
40 {
41 $this->markTestIncomplete(
42 '$ilDB throws notices during test.'
43 );
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 require_once './Services/Database/classes/class.ilDB.php';
59 $ildb_mock = $this->getMock('ilDBMySQL', array('nextId','quote','exec', 'insert'), array(), '', false, false);
60 $ildb_mock->expects( $this->any() )->method('quote')->will( $this->returnCallback(''));
61 $i = 0;
62 $ildb_mock->expects( $this->any() )->method( 'nextId' )->will( $this->returnValue($i++) );
63 $ildb_mock->expects( $this->any() )->method( 'exec' )->will( $this->returnValue(true) );
64 $ildb_mock->expects( $this->any() )->method( 'insert' )->will( $this->returnValue(true) );
65
66// $ildb_mock->expects( $this->exactly(2) )
67// ->method( 'fetchAssoc' )
68// ->with( $this->equalTo('Test') )
69// ->will( $this->onConsecutiveCalls(array('answer_id' => 123, 'depth' => 456), false ) );
70
71 global $ilDB;
72 $ilDB = $ildb_mock;
73 $GLOBALS['ilDB'] = $ildb_mock;
74
75 require_once $this->getTestOutputFilename($test_name);
77 $process = new $test_name;
78 $process->startWorkflow();
79 $all_triggered = true;
80 foreach($process->getNodes() as $node)
81 {
83 foreach($node->getDetectors() as $detector)
84 {
86 if(!$detector->getActivated())
87 {
88 $all_triggered = false;
89 }
90 }
91 foreach($node->getEmitters() as $emitter)
92 {
94 if(!$emitter->getActivated())
95 {
96 $all_triggered = false;
97 }
98 }
99 }
100 $this->assertFalse($all_triggered, 'All nodes were triggered (but should not since the event was not handled.');
101
102 $process->handleEvent(
103 array(
104 'Course',
105 'UserWasAssigned',
106 'usr',
107 0,
108 'crs',
109 0
110 )
111 );
112
113 $all_triggered = true;
114 foreach($process->getNodes() as $node)
115 {
117 foreach($node->getDetectors() as $detector)
118 {
120 if(!$detector->getActivated())
121 {
122 $all_triggered = false;
123 }
124 }
125 foreach($node->getEmitters() as $emitter)
126 {
128 if(!$emitter->getActivated())
129 {
130 $all_triggered = false;
131 }
132 }
133 }
134 $this->assertTrue($all_triggered, 'Not all nodes were triggered.');
135
136 unlink($this->getTestOutputFilename($test_name));
137 }
138
139 public function test_WorkflowWithSimpleIntermediateSignalEventShouldOutputAccordingly()
140 {
141 $this->markTestIncomplete(
142 '$ilDB throws notices during test.'
143 );
144
145 $test_name = 'IntermediateCatchEvent_Signal_Simple';
146 $xml = file_get_contents($this->getTestInputFilename($test_name));
147 $parser = new ilBPMN2Parser();
148 $parse_result = $parser->parseBPMN2XML($xml);
149
150 file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
151 $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
152
153 $this->assertTrue(substr($return,0,25) == 'No syntax errors detected', 'Lint of output code failed.');
154
155 $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
156 $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
157
158 require_once './Services/Database/classes/class.ilDB.php';
159 $ildb_mock = $this->getMock('ilDBMySQL', array('nextId','quote','exec', 'insert'), array(), '', false, false);
160 $ildb_mock->expects( $this->any() )->method('quote')->will( $this->returnCallback(''));
161 $id = 0;
162 $ildb_mock->expects( $this->any() )->method( 'nextId' )->will( $this->returnValue($i++) );
163 $ildb_mock->expects( $this->any() )->method( 'exec' )->will( $this->returnValue(true) );
164 $ildb_mock->expects( $this->any() )->method( 'insert' )->will( $this->returnValue(true) );
165
166// $ildb_mock->expects( $this->exactly(2) )
167// ->method( 'fetchAssoc' )
168// ->with( $this->equalTo('Test') )
169// ->will( $this->onConsecutiveCalls(array('answer_id' => 123, 'depth' => 456), false ) );
170
171 global $ilDB;
172 $ilDB = $ildb_mock;
173 $GLOBALS['ilDB'] = $ildb_mock;
174
175 require_once $this->getTestOutputFilename($test_name);
177 $process = new $test_name;
178 $process->startWorkflow();
179 $all_triggered = true;
180 foreach($process->getNodes() as $node)
181 {
183 foreach($node->getDetectors() as $detector)
184 {
186 if(!$detector->getActivated())
187 {
188 $all_triggered = false;
189 }
190 }
191 foreach($node->getEmitters() as $emitter)
192 {
194 if(!$emitter->getActivated())
195 {
196 $all_triggered = false;
197 }
198 }
199 }
200 $this->assertFalse($all_triggered, 'All nodes were triggered (but should not since the event was not handled.');
201
202 $process->handleEvent(
203 array(
204 'Course',
205 'UserLeft',
206 'usr',
207 0,
208 'crs',
209 0
210 )
211 );
212
213 $all_triggered = true;
214 foreach($process->getNodes() as $node)
215 {
217 foreach($node->getDetectors() as $detector)
218 {
220 if(!$detector->getActivated())
221 {
222 $all_triggered = false;
223 }
224 }
225 foreach($node->getEmitters() as $emitter)
226 {
228 if(!$emitter->getActivated())
229 {
230 $all_triggered = false;
231 }
232 }
233 }
234 $this->assertTrue($all_triggered, 'Not all nodes were triggered.');
235
236 unlink($this->getTestOutputFilename($test_name));
237 }
238
239 public function test_WorkflowWithSimpleIntermediateTimerEventShouldOutputAccordingly()
240 {
241 $this->markTestIncomplete(
242 '$ilDB throws notices during test.'
243 );
244 $test_name = 'IntermediateCatchEvent_Timer_Simple';
245 $xml = file_get_contents($this->getTestInputFilename($test_name));
246 $parser = new ilBPMN2Parser();
247 $parse_result = $parser->parseBPMN2XML($xml);
248
249 file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
250 $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
251
252 $this->assertTrue(substr($return,0,25) == 'No syntax errors detected', 'Lint of output code failed.');
253
254 $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
255 $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
256
257 require_once './Services/Database/classes/class.ilDB.php';
258 $ildb_mock = $this->getMock('ilDBMySQL', array('nextId','quote','exec', 'insert'), array(), '', false, false);
259 $ildb_mock->expects( $this->any() )->method('quote')->will( $this->returnCallback(''));
260 $id = 0;
261 $ildb_mock->expects( $this->any() )->method( 'nextId' )->will( $this->returnValue($i++) );
262 $ildb_mock->expects( $this->any() )->method( 'exec' )->will( $this->returnValue(true) );
263 $ildb_mock->expects( $this->any() )->method( 'insert' )->will( $this->returnValue(true) );
264
265// $ildb_mock->expects( $this->exactly(2) )
266// ->method( 'fetchAssoc' )
267// ->with( $this->equalTo('Test') )
268// ->will( $this->onConsecutiveCalls(array('answer_id' => 123, 'depth' => 456), false ) );
269
270 global $ilDB;
271 $ilDB = $ildb_mock;
272 $GLOBALS['ilDB'] = $ildb_mock;
273
274 require_once $this->getTestOutputFilename($test_name);
276 $process = new $test_name;
277 $process->startWorkflow();
278 $all_triggered = true;
279 foreach($process->getNodes() as $node)
280 {
282 foreach($node->getDetectors() as $detector)
283 {
285 if(!$detector->getActivated())
286 {
287 $all_triggered = false;
288 }
289 }
290 foreach($node->getEmitters() as $emitter)
291 {
293 if(!$emitter->getActivated())
294 {
295 $all_triggered = false;
296 }
297 }
298 }
299 $this->assertFalse($all_triggered, 'All nodes were triggered (but should not since the event was not handled.');
300
301 $process->handleEvent(
302 array(
303 'time_passed',
304 'time_passed',
305 'none',
306 0,
307 'none',
308 0
309 )
310 );
311
312 $all_triggered = true;
313 foreach($process->getNodes() as $node)
314 {
316 foreach($node->getDetectors() as $detector)
317 {
319 if(!$detector->getActivated())
320 {
321 $all_triggered = false;
322 }
323 }
324 foreach($node->getEmitters() as $emitter)
325 {
327 if(!$emitter->getActivated())
328 {
329 $all_triggered = false;
330 }
331 }
332 }
333 $this->assertTrue($all_triggered, 'Not all nodes were triggered.');
334
335 unlink($this->getTestOutputFilename($test_name));
336 }
337}
$parser
Definition: BPMN2Parser.php:24
$parse_result
Definition: BPMN2Parser.php:26
An exception for terminatinating execution or to throw for unit testing.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $ilDB