ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
4require_once 'Services/WorkflowEngine/test/ilWorkflowEngineBaseTest.php';
5
13{
14 #region Helper
15 public $base_path = './Services/WorkflowEngine/test/parser/';
16 public $suite_path = '011_EventBasedGateway/';
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_WorkflowWithSimpleEventGatewayShouldOutputAccordingly()
44 {
45 $this->markTestIncomplete(
46 '$ilDB throws notices during test.'
47 );
48
49 $test_name = 'EventBasedGateway_Blanko_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 global $ilDB;
71 $ilDB = $ildb_mock;
72 $GLOBALS['ilDB'] = $ildb_mock;
73
74 require_once $this->getTestOutputFilename($test_name);
75 $process = new $test_name;
76 $this->assertFalse($process->isActive());
77
78 $process->startWorkflow();
79 $this->assertTrue($process->isActive());
80 $all_triggered = true;
81 foreach ($process->getNodes() as $node) {
83 foreach ($node->getDetectors() as $detector) {
85 if (!$detector->getActivated()) {
86 $all_triggered = false;
87 }
88 }
89 foreach ($node->getEmitters() as $emitter) {
91 if (!$emitter->getActivated()) {
92 $all_triggered = false;
93 }
94 }
95 }
96 $this->assertFalse($all_triggered, 'All nodes were triggered.');
97 $this->assertTrue($process->isActive());
98 $process->handleEvent(
99 array(
100 'Course',
101 'UserWasAssigned',
102 'usr',
103 0,
104 'crs',
105 0
106 )
107 );
108
109 $all_triggered = true;
110 foreach ($process->getNodes() as $node) {
112 foreach ($node->getDetectors() as $detector) {
114 if (!$detector->getActivated()) {
115 $all_triggered = false;
116 }
117 }
118 foreach ($node->getEmitters() as $emitter) {
120 if (!$emitter->getActivated()) {
121 $all_triggered = false;
122 }
123 }
124 }
125 $this->assertFalse($all_triggered, 'All nodes were triggered.');
126 $all_inactive = true;
127 foreach ($process->getNodes() as $node) {
128 if ($node->isActive()) {
129 $all_inactive = false;
130 }
131 }
132 $this->assertTrue($all_inactive, 'Not all nodes are inactive.');
133 $this->assertFalse($process->isActive(), 'Process should be inactive after processing the event. It is not.');
134 unlink($this->getTestOutputFilename($test_name));
135 // This test was indeed a harsh mistress.
136 }
137}
$parser
Definition: BPMN2Parser.php:23
$parse_result
Definition: BPMN2Parser.php:25
An exception for terminatinating execution or to throw for unit testing.
Class ilWorkflowEngineBaseTest.
$i
Definition: disco.tpl.php:19
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$xml
Definition: metadata.php:240
global $ilDB