ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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()
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  $this->markTestIncomplete(
46  '$ilDB throws notices during test.'
47  );
48 
49  $test_name = 'IntermediateCatchEvent_Message_Simple';
50  $xml = file_get_contents($this->getTestInputFilename($test_name));
51  $parser = new ilBPMN2Parser();
52  $parse_result = $parser->parseBPMN2XML($xml);
53 
54  file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
55  $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
56 
57  $this->assertTrue(substr($return, 0, 25) == 'No syntax errors detected', 'Lint of output code failed.');
58 
59  $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
60  $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
61 
62  require_once './Services/Database/classes/class.ilDB.php';
63  $ildb_mock = $this->createMock('ilDBMySQL', array('nextId','quote','exec', 'insert'), array(), '', false, false);
64  $ildb_mock->expects($this->any())->method('quote')->will($this->returnCallback(''));
65  $i = 0;
66  $ildb_mock->expects($this->any())->method('nextId')->will($this->returnValue($i++));
67  $ildb_mock->expects($this->any())->method('exec')->will($this->returnValue(true));
68  $ildb_mock->expects($this->any())->method('insert')->will($this->returnValue(true));
69 
70  // $ildb_mock->expects( $this->exactly(2) )
71  // ->method( 'fetchAssoc' )
72  // ->with( $this->equalTo('Test') )
73  // ->will( $this->onConsecutiveCalls(array('answer_id' => 123, 'depth' => 456), false ) );
74 
75  global $ilDB;
76  $ilDB = $ildb_mock;
77  $GLOBALS['ilDB'] = $ildb_mock;
78 
79  require_once $this->getTestOutputFilename($test_name);
81  $process = new $test_name;
82  $process->startWorkflow();
83  $all_triggered = true;
84  foreach ($process->getNodes() as $node) {
86  foreach ($node->getDetectors() as $detector) {
88  if (!$detector->getActivated()) {
89  $all_triggered = false;
90  }
91  }
92  foreach ($node->getEmitters() as $emitter) {
94  if (!$emitter->getActivated()) {
95  $all_triggered = false;
96  }
97  }
98  }
99  $this->assertFalse($all_triggered, 'All nodes were triggered (but should not since the event was not handled.');
100 
101  $process->handleEvent(
102  array(
103  'Course',
104  'UserWasAssigned',
105  'usr',
106  0,
107  'crs',
108  0
109  )
110  );
111 
112  $all_triggered = true;
113  foreach ($process->getNodes() as $node) {
115  foreach ($node->getDetectors() as $detector) {
117  if (!$detector->getActivated()) {
118  $all_triggered = false;
119  }
120  }
121  foreach ($node->getEmitters() as $emitter) {
123  if (!$emitter->getActivated()) {
124  $all_triggered = false;
125  }
126  }
127  }
128  $this->assertTrue($all_triggered, 'Not all nodes were triggered.');
129 
130  unlink($this->getTestOutputFilename($test_name));
131  }
132 
133  public function test_WorkflowWithSimpleIntermediateSignalEventShouldOutputAccordingly()
134  {
135  $this->markTestIncomplete(
136  '$ilDB throws notices during test.'
137  );
138 
139  $test_name = 'IntermediateCatchEvent_Signal_Simple';
140  $xml = file_get_contents($this->getTestInputFilename($test_name));
141  $parser = new ilBPMN2Parser();
142  $parse_result = $parser->parseBPMN2XML($xml);
143 
144  file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
145  $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
146 
147  $this->assertTrue(substr($return, 0, 25) == 'No syntax errors detected', 'Lint of output code failed.');
148 
149  $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
150  $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
151 
152  require_once './Services/Database/classes/class.ilDB.php';
153  $ildb_mock = $this->createMock('ilDBMySQL', array('nextId','quote','exec', 'insert'), array(), '', false, false);
154  $ildb_mock->expects($this->any())->method('quote')->will($this->returnCallback(''));
155  $id = 0;
156  $ildb_mock->expects($this->any())->method('nextId')->will($this->returnValue($i++));
157  $ildb_mock->expects($this->any())->method('exec')->will($this->returnValue(true));
158  $ildb_mock->expects($this->any())->method('insert')->will($this->returnValue(true));
159 
160  // $ildb_mock->expects( $this->exactly(2) )
161  // ->method( 'fetchAssoc' )
162  // ->with( $this->equalTo('Test') )
163  // ->will( $this->onConsecutiveCalls(array('answer_id' => 123, 'depth' => 456), false ) );
164 
165  global $ilDB;
166  $ilDB = $ildb_mock;
167  $GLOBALS['ilDB'] = $ildb_mock;
168 
169  require_once $this->getTestOutputFilename($test_name);
171  $process = new $test_name;
172  $process->startWorkflow();
173  $all_triggered = true;
174  foreach ($process->getNodes() as $node) {
176  foreach ($node->getDetectors() as $detector) {
178  if (!$detector->getActivated()) {
179  $all_triggered = false;
180  }
181  }
182  foreach ($node->getEmitters() as $emitter) {
184  if (!$emitter->getActivated()) {
185  $all_triggered = false;
186  }
187  }
188  }
189  $this->assertFalse($all_triggered, 'All nodes were triggered (but should not since the event was not handled.');
190 
191  $process->handleEvent(
192  array(
193  'Course',
194  'UserLeft',
195  'usr',
196  0,
197  'crs',
198  0
199  )
200  );
201 
202  $all_triggered = true;
203  foreach ($process->getNodes() as $node) {
205  foreach ($node->getDetectors() as $detector) {
207  if (!$detector->getActivated()) {
208  $all_triggered = false;
209  }
210  }
211  foreach ($node->getEmitters() as $emitter) {
213  if (!$emitter->getActivated()) {
214  $all_triggered = false;
215  }
216  }
217  }
218  $this->assertTrue($all_triggered, 'Not all nodes were triggered.');
219 
220  unlink($this->getTestOutputFilename($test_name));
221  }
222 
223  public function test_WorkflowWithSimpleIntermediateTimerEventShouldOutputAccordingly()
224  {
225  $this->markTestIncomplete(
226  '$ilDB throws notices during test.'
227  );
228  $test_name = 'IntermediateCatchEvent_Timer_Simple';
229  $xml = file_get_contents($this->getTestInputFilename($test_name));
230  $parser = new ilBPMN2Parser();
231  $parse_result = $parser->parseBPMN2XML($xml);
232 
233  file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
234  $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
235 
236  $this->assertTrue(substr($return, 0, 25) == 'No syntax errors detected', 'Lint of output code failed.');
237 
238  $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
239  $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
240 
241  require_once './Services/Database/classes/class.ilDB.php';
242  $ildb_mock = $this->createMock('ilDBMySQL', array('nextId','quote','exec', 'insert'), array(), '', false, false);
243  $ildb_mock->expects($this->any())->method('quote')->will($this->returnCallback(''));
244  $id = 0;
245  $ildb_mock->expects($this->any())->method('nextId')->will($this->returnValue($i++));
246  $ildb_mock->expects($this->any())->method('exec')->will($this->returnValue(true));
247  $ildb_mock->expects($this->any())->method('insert')->will($this->returnValue(true));
248 
249  // $ildb_mock->expects( $this->exactly(2) )
250  // ->method( 'fetchAssoc' )
251  // ->with( $this->equalTo('Test') )
252  // ->will( $this->onConsecutiveCalls(array('answer_id' => 123, 'depth' => 456), false ) );
253 
254  global $ilDB;
255  $ilDB = $ildb_mock;
256  $GLOBALS['ilDB'] = $ildb_mock;
257 
258  require_once $this->getTestOutputFilename($test_name);
260  $process = new $test_name;
261  $process->startWorkflow();
262  $all_triggered = true;
263  foreach ($process->getNodes() as $node) {
265  foreach ($node->getDetectors() as $detector) {
267  if (!$detector->getActivated()) {
268  $all_triggered = false;
269  }
270  }
271  foreach ($node->getEmitters() as $emitter) {
273  if (!$emitter->getActivated()) {
274  $all_triggered = false;
275  }
276  }
277  }
278  $this->assertFalse($all_triggered, 'All nodes were triggered (but should not since the event was not handled.');
279 
280  $process->handleEvent(
281  array(
282  'time_passed',
283  'time_passed',
284  'none',
285  0,
286  'none',
287  0
288  )
289  );
290 
291  $all_triggered = true;
292  foreach ($process->getNodes() as $node) {
294  foreach ($node->getDetectors() as $detector) {
296  if (!$detector->getActivated()) {
297  $all_triggered = false;
298  }
299  }
300  foreach ($node->getEmitters() as $emitter) {
302  if (!$emitter->getActivated()) {
303  $all_triggered = false;
304  }
305  }
306  }
307  $this->assertTrue($all_triggered, 'Not all nodes were triggered.');
308 
309  unlink($this->getTestOutputFilename($test_name));
310  }
311 }
Class ilWorkflowEngineBaseTest.
if(!array_key_exists('StateId', $_REQUEST)) $id
$parse_result
Definition: BPMN2Parser.php:25
$parser
Definition: BPMN2Parser.php:23
global $ilDB
$i
Definition: disco.tpl.php:19
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
Class ilBPMN2Parser.