ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.test_012_DataInput.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 = '012_DataInput/';
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_WorkflowWithSimpleDataInputShouldOutputAccordingly()
44  {
45  $test_name = 'DataInput_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 $this->getTestOutputFilename($test_name);
60  $process = new $test_name;
61  $process->setInstanceVarById('DataInput_1', 'YaddaYadda');
62  $process->startWorkflow();
63  $all_triggered = true;
64  foreach ($process->getNodes() as $node) {
66  foreach ($node->getDetectors() as $detector) {
68  if (!$detector->getActivated()) {
69  $all_triggered = false;
70  }
71  }
72  foreach ($node->getEmitters() as $emitter) {
74  if (!$emitter->getActivated()) {
75  $all_triggered = false;
76  }
77  }
78  }
79  $this->assertEquals('YaddaYadda', $process->getInstanceVarById('DataInput_1'), 'Inputvar was not kept.');
80  $this->assertTrue($all_triggered, 'Not all nodes were triggered.');
81 
82  unlink($this->getTestOutputFilename($test_name));
83  }
84 
85  public function test_WorkflowWithDataInputPropertiesShouldOutputAccordingly()
86  {
87  $test_name = 'DataInput_WithProperties';
88  $xml = file_get_contents($this->getTestInputFilename($test_name));
89  $parser = new ilBPMN2Parser();
90  $parse_result = $parser->parseBPMN2XML($xml);
91 
92  file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
93  $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
94 
95  $this->assertTrue(substr($return, 0, 25) == 'No syntax errors detected', 'Lint of output code failed.');
96 
97  $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
98  $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
99 
100  require_once $this->getTestOutputFilename($test_name);
102  $process = new $test_name;
103  $process->setInstanceVarById('DataInput_1', 'YaddaYadda');
104  $process->startWorkflow();
105  $all_triggered = true;
106  foreach ($process->getNodes() as $node) {
108  foreach ($node->getDetectors() as $detector) {
110  if (!$detector->getActivated()) {
111  $all_triggered = false;
112  }
113  }
114  foreach ($node->getEmitters() as $emitter) {
116  if (!$emitter->getActivated()) {
117  $all_triggered = false;
118  }
119  }
120  }
121  $this->assertEquals('YaddaYadda', $process->getInstanceVarById('DataInput_1'), 'Inputvar was not kept.');
122  $this->assertTrue($all_triggered, 'Not all nodes were triggered.');
123 
124  unlink($this->getTestOutputFilename($test_name));
125  }
126 
127  public function test_WorkflowWithRepositoryObjectSelectorShouldOutputAccordingly()
128  {
129  $test_name = 'DataInput_RepositoryObjectSelector';
130  $xml = file_get_contents($this->getTestInputFilename($test_name));
131  $parser = new ilBPMN2Parser();
132  $parse_result = $parser->parseBPMN2XML($xml);
133 
134  file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
135  $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
136 
137  $this->assertTrue(substr($return, 0, 25) == 'No syntax errors detected', 'Lint of output code failed.');
138 
139  $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
140  $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
141 
142  require_once $this->getTestOutputFilename($test_name);
144  $process = new $test_name;
145  $process->setInstanceVarById('DataInput_1', 'YaddaYadda');
146  $process->startWorkflow();
147  $all_triggered = true;
148  foreach ($process->getNodes() as $node) {
150  foreach ($node->getDetectors() as $detector) {
152  if (!$detector->getActivated()) {
153  $all_triggered = false;
154  }
155  }
156  foreach ($node->getEmitters() as $emitter) {
158  if (!$emitter->getActivated()) {
159  $all_triggered = false;
160  }
161  }
162  }
163  $this->assertEquals('YaddaYadda', $process->getInstanceVarById('DataInput_1'), 'Inputvar was not kept.');
164  $this->assertTrue($all_triggered, 'Not all nodes were triggered.');
165 
166  unlink($this->getTestOutputFilename($test_name));
167  }
168 }
Class ilWorkflowEngineBaseTest.
$parse_result
Definition: BPMN2Parser.php:25
$xml
Definition: metadata.php:240
$parser
Definition: BPMN2Parser.php:23
Class ilBPMN2Parser.