ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
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 = '006_Task/';
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_WorkflowWithSimpleTaskShouldOutputAccordingly()
44  {
45  $test_name = 'Task_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);
59  $process = new $test_name;
60  $this->assertFalse($process->isActive());
61 
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->assertTrue($all_triggered);
80  unlink($this->getTestOutputFilename($test_name));
81  }
82 
83  public function test_WorkflowWithSimpleCallActivityShouldOutputAccordingly()
84  {
85  $test_name = 'Task_CallActivity_Simple';
86  $xml = file_get_contents($this->getTestInputFilename($test_name));
87  $parser = new ilBPMN2Parser();
88  $parse_result = $parser->parseBPMN2XML($xml);
89 
90  file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
91  $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
92 
93  $this->assertTrue(substr($return, 0, 25) == 'No syntax errors detected', 'Lint of output code failed.');
94 
95  $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
96  $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
97 
98  require_once $this->getTestOutputFilename($test_name);
99  $process = new $test_name;
100  self::$wasTriggered = false;
101  $process->startWorkflow();
102  $all_triggered = true;
103  foreach ($process->getNodes() as $node) {
105  foreach ($node->getDetectors() as $detector) {
107  if (!$detector->getActivated()) {
108  $all_triggered = false;
109  }
110  }
111  foreach ($node->getEmitters() as $emitter) {
113  if (!$emitter->getActivated()) {
114  $all_triggered = false;
115  }
116  }
117  }
118  $this->assertTrue($all_triggered, 'Not all nodes were triggered.');
119  $this->assertTrue(self::$wasTriggered, 'Static method call was not called.');
120  unlink($this->getTestOutputFilename($test_name));
121  }
122 
123  public static $wasTriggered; // See test above.
124 
125  public static function triggerMe($context = "", $params = "") // See test above.
126  {
127  self::$wasTriggered = true;
128  }
129 
130  public function test_WorkflowWithManualTaskShouldOutputAccordingly()
131  {
132  $test_name = 'Task_ManualTask_Simple';
133  $xml = file_get_contents($this->getTestInputFilename($test_name));
134  $parser = new ilBPMN2Parser();
135  $parse_result = $parser->parseBPMN2XML($xml);
136 
137  file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
138  $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
139 
140  $this->assertTrue(substr($return, 0, 25) == 'No syntax errors detected', 'Lint of output code failed.');
141 
142  $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
143  $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
144 
145  require_once $this->getTestOutputFilename($test_name);
146  $process = new $test_name;
147  $process->startWorkflow();
148  $all_triggered = true;
149  foreach ($process->getNodes() as $node) {
151  foreach ($node->getDetectors() as $detector) {
153  if (!$detector->getActivated()) {
154  $all_triggered = false;
155  }
156  }
157  foreach ($node->getEmitters() as $emitter) {
159  if (!$emitter->getActivated()) {
160  $all_triggered = false;
161  }
162  }
163  }
164  $this->assertTrue($all_triggered);
165 
166  unlink($this->getTestOutputFilename($test_name));
167  }
168 
169  public function test_WorkflowWithScriptTaskShouldOutputAccordingly()
170  {
171  $test_name = 'Task_ScriptTask_Simple';
172  $xml = file_get_contents($this->getTestInputFilename($test_name));
173  $parser = new ilBPMN2Parser();
174  $parse_result = $parser->parseBPMN2XML($xml);
175 
176  file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
177  $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
178 
179  $this->assertTrue(substr($return, 0, 25) == 'No syntax errors detected', 'Lint of output code failed.');
180 
181  $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
182  $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
183 
184  require_once $this->getTestOutputFilename($test_name);
185  self::$wasTriggered = false;
186  $process = new $test_name;
187  $process->startWorkflow();
188  $all_triggered = true;
189  foreach ($process->getNodes() as $node) {
191  foreach ($node->getDetectors() as $detector) {
193  if (!$detector->getActivated()) {
194  $all_triggered = false;
195  }
196  }
197  foreach ($node->getEmitters() as $emitter) {
199  if (!$emitter->getActivated()) {
200  $all_triggered = false;
201  }
202  }
203  }
204  $this->assertTrue($all_triggered, 'Not all nodes were triggered.');
205  $this->assertTrue(self::$wasTriggered, 'Static method call was not called.');
206 
207  unlink($this->getTestOutputFilename($test_name));
208  }
209 
211  public static $callParams;
212  public static $retval = array(1,2,3,4,5);
213 
214  public static function requestList($context, $params)
215  {
216  self::$wasListRequestTriggered = true;
217  self::$callParams = $params;
218  return array('DataObjectReference_1' => self::$retval);
219  }
220 
221  public function test_ReadLearnersFromCourseShouldOutputAccordingly()
222  {
223  $test_name = 'Task_ReadLearnersFromCourse';
224  $xml = file_get_contents($this->getTestInputFilename($test_name));
225  $parser = new ilBPMN2Parser();
226  $parse_result = $parser->parseBPMN2XML($xml);
227 
228  file_put_contents($this->getTestOutputFilename($test_name), $parse_result);
229  $return = exec('php -l ' . $this->getTestOutputFilename($test_name));
230 
231  $this->assertTrue(substr($return, 0, 25) == 'No syntax errors detected', 'Lint of output code failed.');
232 
233  $goldsample = file_get_contents($this->getTestGoldsampleFilename($test_name));
234  $this->assertEquals($goldsample, $parse_result, 'Output does not match goldsample.');
235 
236  require_once $this->getTestOutputFilename($test_name);
237  self::$wasListRequestTriggered = false;
238  $process = new $test_name;
239 
240  $process->setInstanceVarById('DataInput_1', 123456789);
241  $this->assertEquals(123456789, $process->getInstanceVarById('DataInput_1'));
242  $process->startWorkflow();
243  $all_triggered = true;
244  foreach ($process->getNodes() as $node) {
246  foreach ($node->getDetectors() as $detector) {
248  if (!$detector->getActivated()) {
249  $all_triggered = false;
250  }
251  }
252  foreach ($node->getEmitters() as $emitter) {
254  if (!$emitter->getActivated()) {
255  $all_triggered = false;
256  }
257  }
258  }
259  $this->assertTrue($all_triggered, 'Not all nodes were triggered.');
260  $this->assertTrue(self::$wasListRequestTriggered, 'Static method call was not called.');
261  $this->assertEquals(self::$retval, $process->getInstanceVarById('DataObject_1'));
262 
263  unlink($this->getTestOutputFilename($test_name));
264  }
265 }
$params
Definition: disable.php:11
Class ilWorkflowEngineBaseTest.
$parse_result
Definition: BPMN2Parser.php:25
$xml
Definition: metadata.php:240
getTestGoldsampleFilename($test_name)
static triggerMe($context="", $params="")
static requestList($context, $params)
Create styles array
The data for the language used.
$parser
Definition: BPMN2Parser.php:23
getTestInputFilename($test_name)
getTestOutputFilename($test_name)
Class ilBPMN2Parser.