ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.test_011_EventBasedGateway.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 = '011_EventBasedGateway/';
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_WorkflowWithSimpleEventGatewayShouldOutputAccordingly()
40 {
41 $this->markTestIncomplete(
42 '$ilDB throws notices during test.'
43 );
44
45 $test_name = 'EventBasedGateway_Blanko_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 global $ilDB;
67 $ilDB = $ildb_mock;
68 $GLOBALS['ilDB'] = $ildb_mock;
69
70 require_once $this->getTestOutputFilename($test_name);
71 $process = new $test_name;
72 $this->assertFalse($process->isActive());
73
74 $process->startWorkflow();
75 $this->assertTrue($process->isActive());
76 $all_triggered = true;
77 foreach($process->getNodes() as $node)
78 {
80 foreach($node->getDetectors() as $detector)
81 {
83 if(!$detector->getActivated())
84 {
85 $all_triggered = false;
86 }
87 }
88 foreach($node->getEmitters() as $emitter)
89 {
91 if(!$emitter->getActivated())
92 {
93 $all_triggered = false;
94 }
95 }
96 }
97 $this->assertFalse($all_triggered, 'All nodes were triggered.');
98 $this->assertTrue($process->isActive());
99 $process->handleEvent(
100 array(
101 'Course',
102 'UserWasAssigned',
103 'usr',
104 0,
105 'crs',
106 0
107 )
108 );
109
110 $all_triggered = true;
111 foreach($process->getNodes() as $node)
112 {
114 foreach($node->getDetectors() as $detector)
115 {
117 if(!$detector->getActivated())
118 {
119 $all_triggered = false;
120 }
121 }
122 foreach($node->getEmitters() as $emitter)
123 {
125 if(!$emitter->getActivated())
126 {
127 $all_triggered = false;
128 }
129 }
130 }
131 $this->assertFalse($all_triggered, 'All nodes were triggered.');
132 $all_inactive = true;
133 foreach($process->getNodes() as $node)
134 {
135 if($node->isActive())
136 {
137 $all_inactive = false;
138 }
139 }
140 $this->assertTrue($all_inactive, 'Not all nodes are inactive.');
141 $this->assertFalse($process->isActive(), 'Process should be inactive after processing the event. It is not.');
142 unlink($this->getTestOutputFilename($test_name));
143 // This test was indeed a harsh mistress.
144 }
145
146}
$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