ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.test_006_Task.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 = '006_Task/';
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_WorkflowWithSimpleTaskShouldOutputAccordingly()
40  {
41  $test_name = 'Task_Simple';
42  $xml = file_get_contents($this->getTestInputFilename($test_name));
43  $parser = new ilBPMN2Parser();
44  $parse_result = $parser->parseBPMN2XML($xml);
45 
46  file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
47  $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
48 
49  $this->assertTrue(substr($return,0,25) == 'No syntax errors detected', 'Lint of output code failed.');
50 
51  $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
52  $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
53 
54  require_once $this->getTestOutputFilename($test_name);
55  $process = new $test_name;
56  $this->assertFalse($process->isActive());
57 
58  $process->startWorkflow();
59  $all_triggered = true;
60  foreach($process->getNodes() as $node)
61  {
63  foreach($node->getDetectors() as $detector)
64  {
66  if(!$detector->getActivated())
67  {
68  $all_triggered = false;
69  }
70  }
71  foreach($node->getEmitters() as $emitter)
72  {
74  if(!$emitter->getActivated())
75  {
76  $all_triggered = false;
77  }
78  }
79  }
80  $this->assertTrue($all_triggered);
81  unlink($this->getTestOutputFilename($test_name));
82  }
83 
84  public function test_WorkflowWithSimpleCallActivityShouldOutputAccordingly()
85  {
86  $test_name = 'Task_CallActivity_Simple';
87  $xml = file_get_contents($this->getTestInputFilename($test_name));
88  $parser = new ilBPMN2Parser();
89  $parse_result = $parser->parseBPMN2XML($xml);
90 
91  file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
92  $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
93 
94  $this->assertTrue(substr($return,0,25) == 'No syntax errors detected', 'Lint of output code failed.');
95 
96  $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
97  $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
98 
99  require_once $this->getTestOutputFilename($test_name);
100  $process = new $test_name;
101  self::$wasTriggered = false;
102  $process->startWorkflow();
103  $all_triggered = true;
104  foreach($process->getNodes() as $node)
105  {
107  foreach($node->getDetectors() as $detector)
108  {
110  if(!$detector->getActivated())
111  {
112  $all_triggered = false;
113  }
114  }
115  foreach($node->getEmitters() as $emitter)
116  {
118  if(!$emitter->getActivated())
119  {
120  $all_triggered = false;
121  }
122  }
123  }
124  $this->assertTrue($all_triggered, 'Not all nodes were triggered.');
125  $this->assertTrue(self::$wasTriggered, 'Static method call was not called.');
126  unlink($this->getTestOutputFilename($test_name));
127  }
128 
129  public static $wasTriggered; // See test above.
130 
131  public static function triggerMe($context = "", $params = "") // See test above.
132  {
133  self::$wasTriggered = true;
134  }
135 
136  public function test_WorkflowWithManualTaskShouldOutputAccordingly()
137  {
138  $test_name = 'Task_ManualTask_Simple';
139  $xml = file_get_contents($this->getTestInputFilename($test_name));
140  $parser = new ilBPMN2Parser();
141  $parse_result = $parser->parseBPMN2XML($xml);
142 
143  file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
144  $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
145 
146  $this->assertTrue(substr($return,0,25) == 'No syntax errors detected', 'Lint of output code failed.');
147 
148  $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
149  $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
150 
151  require_once $this->getTestOutputFilename($test_name);
152  $process = new $test_name;
153  $process->startWorkflow();
154  $all_triggered = true;
155  foreach($process->getNodes() as $node)
156  {
158  foreach($node->getDetectors() as $detector)
159  {
161  if(!$detector->getActivated())
162  {
163  $all_triggered = false;
164  }
165  }
166  foreach($node->getEmitters() as $emitter)
167  {
169  if(!$emitter->getActivated())
170  {
171  $all_triggered = false;
172  }
173  }
174  }
175  $this->assertTrue($all_triggered);
176 
177  unlink($this->getTestOutputFilename($test_name));
178  }
179 
180  public function test_WorkflowWithScriptTaskShouldOutputAccordingly()
181  {
182  $test_name = 'Task_ScriptTask_Simple';
183  $xml = file_get_contents($this->getTestInputFilename($test_name));
184  $parser = new ilBPMN2Parser();
185  $parse_result = $parser->parseBPMN2XML($xml);
186 
187  file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
188  $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
189 
190  $this->assertTrue(substr($return,0,25) == 'No syntax errors detected', 'Lint of output code failed.');
191 
192  $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
193  $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
194 
195  require_once $this->getTestOutputFilename($test_name);
196  self::$wasTriggered = false;
197  $process = new $test_name;
198  $process->startWorkflow();
199  $all_triggered = true;
200  foreach($process->getNodes() as $node)
201  {
203  foreach($node->getDetectors() as $detector)
204  {
206  if(!$detector->getActivated())
207  {
208  $all_triggered = false;
209  }
210  }
211  foreach($node->getEmitters() as $emitter)
212  {
214  if(!$emitter->getActivated())
215  {
216  $all_triggered = false;
217  }
218  }
219  }
220  $this->assertTrue($all_triggered, 'Not all nodes were triggered.');
221  $this->assertTrue(self::$wasTriggered, 'Static method call was not called.');
222 
223  unlink($this->getTestOutputFilename($test_name));
224  }
225 
227  public static $callParams;
228  public static $retval = array(1,2,3,4,5);
229 
230  public static function requestList($context, $params)
231  {
232  self::$wasListRequestTriggered = true;
233  self::$callParams = $params;
234  return array('DataObjectReference_1' => self::$retval);
235  }
236 
237  public function test_ReadLearnersFromCourseShouldOutputAccordingly()
238  {
239  $test_name = 'Task_ReadLearnersFromCourse';
240  $xml = file_get_contents($this->getTestInputFilename($test_name));
241  $parser = new ilBPMN2Parser();
242  $parse_result = $parser->parseBPMN2XML($xml);
243 
244  file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
245  $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
246 
247  $this->assertTrue(substr($return,0,25) == 'No syntax errors detected', 'Lint of output code failed.');
248 
249  $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
250  $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
251 
252  require_once $this->getTestOutputFilename($test_name);
253  self::$wasListRequestTriggered = false;
254  $process = new $test_name;
255 
256  $process->setInstanceVarById('DataInput_1', 123456789);
257  $this->assertEquals(123456789, $process->getInstanceVarById('DataInput_1'));
258  $process->startWorkflow();
259  $all_triggered = true;
260  foreach($process->getNodes() as $node)
261  {
263  foreach($node->getDetectors() as $detector)
264  {
266  if(!$detector->getActivated())
267  {
268  $all_triggered = false;
269  }
270  }
271  foreach($node->getEmitters() as $emitter)
272  {
274  if(!$emitter->getActivated())
275  {
276  $all_triggered = false;
277  }
278  }
279  }
280  $this->assertTrue($all_triggered, 'Not all nodes were triggered.');
281  $this->assertTrue(self::$wasListRequestTriggered, 'Static method call was not called.');
282  $this->assertEquals(self::$retval, $process->getInstanceVarById('DataObject_1'));
283 
284  unlink($this->getTestOutputFilename($test_name));
285  }
286 
287 }
$parse_result
Definition: BPMN2Parser.php:26
getTestGoldsampleFilename($test_name)
static triggerMe($context="", $params="")
static requestList($context, $params)
Create styles array
The data for the language used.
$parser
Definition: BPMN2Parser.php:24
getTestInputFilename($test_name)
getTestOutputFilename($test_name)
$params
Definition: example_049.php:96
Class ilBPMN2Parser.