ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilBasicNodeTest.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
16 {
17  public function setUp()
18  {
19  include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
20  //ilUnitUtil::performInitialisation();
21 
22  // Empty workflow.
23  require_once './Services/WorkflowEngine/classes/workflows/class.ilEmptyWorkflow.php';
24  $this->workflow = new ilEmptyWorkflow();
25  }
26 
27  public function tearDown()
28  {
29  global $ilSetting;
30  if ($ilSetting != NULL)
31  {
32  $ilSetting->delete('IL_PHPUNIT_TEST_TIME');
33  $ilSetting->delete('IL_PHPUNIT_TEST_MICROTIME');
34  }
35  }
36 
37  public function testConstructorValidContext()
38  {
39  // Act
40  $node = new ilBasicNode($this->workflow);
41 
42  // Assert
43  // No exception - good
44  $this->assertTrue(
45  true,
46  'Construction failed with valid context passed to constructor.'
47  );
48  }
49 
50  public function testGetContext()
51  {
52  // Arrange
53  $node = new ilBasicNode($this->workflow);
54 
55  // Act
56  $actual = $node->getContext();
57 
58  // Assert
59  if ($actual === $this->workflow)
60  {
61  $this->assertEquals($actual, $this->workflow);
62  } else {
63  $this->assertTrue(false, 'Context not identical.');
64  }
65  }
66 
67  public function testIsActiveAndActivate()
68  {
69  // Arrange
70  $node = new ilBasicNode($this->workflow);
71  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
72  $detector = new ilSimpleDetector($node);
73  $node->addDetector($detector);
74 
75  // Act
76  $node->activate();
77 
78  // Assert
79  $actual = $node->isActive();
80  $this->assertTrue($actual);
81  }
82 
83  public function testDeactivate()
84  {
85  // Arrange
86  $node = new ilBasicNode($this->workflow);
87  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
88  $detector = new ilSimpleDetector($node);
89  $node->addDetector($detector);
90 
91  // Act
92  $node->activate();
93  $was_activated = $node->isActive();
94  $node->deactivate();
95  $was_deactivated = !$node->isActive();
96 
97  // Assert
98  $this->assertEquals($was_activated, $was_deactivated);
99  }
100 
102  {
103  // Arrange
104  $node = new ilBasicNode($this->workflow);
105  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
106  $detector = new ilSimpleDetector($node);
107  $node->addDetector($detector);
108 
109  // Act
110  $detector->trigger(array());
111  $preconditions = $node->checkTransitionPreconditions();
112 
113  // Assert
114  $this->assertTrue($preconditions);
115  }
116 
118  {
119  // Arrange
120  $node = new ilBasicNode($this->workflow);
121  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
122  $detector = new ilSimpleDetector($node);
123  $node->addDetector($detector);
124 
125 
126  // Act
127  $preconditions = $node->checkTransitionPreconditions();
128 
129  // Assert
130  $this->assertFalse($preconditions);
131  }
132 
133  public function testAttemptTransitionValid()
134  {
135  // Arrange
136  $node = new ilBasicNode($this->workflow);
137  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
138  $detector = new ilSimpleDetector($node);
139  $node->addDetector($detector);
140 
141  // Act
142  $detector->trigger(array());
143  $result = $node->attemptTransition();
144 
145  // Assert
146  $this->assertTrue($result);
147  }
148 
150  {
151  // Arrange
152  $node = new ilBasicNode($this->workflow);
153  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
154  $detector = new ilSimpleDetector($node);
155  $node->addDetector($detector);
156 
157  // Act
158  $result = $node->attemptTransition();
159 
160  // Assert
161  $this->assertFalse($result);
162  }
163 
164  public function testExecuteTransition()
165  { // This is test #100 of the WorkflowEngine, written on 9th of May, 2012
166  // @ 14:15
167 
168  // Arrange
169  $node = new ilBasicNode($this->workflow);
170  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
171  $detector = new ilSimpleDetector($node);
172  $node->addDetector($detector);
173  $node->activate();
174 
175  // Act
176  $node->executeTransition();
177  $state = $node->isActive();
178 
179  // Assert
180  $this->assertFalse($state);
181  }
182 
184  {
185  // Arrange
186  $node = new ilBasicNode($this->workflow);
187  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
188  $detector = new ilSimpleDetector($node);
189  $node->addDetector($detector);
190 
191  require_once './Services/WorkflowEngine/classes/activities/class.ilLoggingActivity.php';
192  $activity = new ilLoggingActivity($node);
193  $activity->setLogFile('ilTransitionLog.txt');
194  $activity->setLogLevel('MESSAGE');
195  $activity->setLogMessage('TEST');
196  $node->addActivity($activity);
197 
198  // Act
199  $node->activate();
200  $node->executeTransition();
201 
202  // Assert
203  $expected = ' :: MESSAGE :: TEST';
204  $fp = fopen('ilTransitionLog.txt', r);
205  $line = fgets($fp);
206  $actual = substr($line, 25, strlen($line)-27);
207  @unlink('ilTransitionLog.txt'); // TODO: Use vfsStream
208  $this->assertEquals(
209  $actual,
210  $expected
211  );
212  }
213 
215  {
216  // Arrange
217  $node = new ilBasicNode($this->workflow);
218  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
219  $detector = new ilSimpleDetector($node);
220  $node->addDetector($detector);
221 
222  require_once './Services/WorkflowEngine/classes/emitters/class.ilActivationEmitter.php';
223  $t_node = new ilBasicNode($this->workflow);
224  $t_detector = new ilSimpleDetector($t_node);
225  $t_node->addDetector($t_detector);
226  $foo_detector = new ilSimpleDetector($t_node);
227  $t_node->addDetector($foo_detector);
228  // again a foo_detector to keep the t_node from transitting
229 
230  $emitter = new ilActivationEmitter($node);
231  $emitter->setTargetDetector($t_detector);
232  $node->addEmitter($emitter);
233 
234  // Act
235  $node->activate();
236  $node->executeTransition();
237 
238  // Assert
239  $this->assertTrue($t_node->isActive());
240  }
241 
242  public function testAddDetector()
243  {
244  // Arrange
245  $node = new ilBasicNode($this->workflow);
246  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
247  $detector = new ilSimpleDetector($node);
248 
249  // Act
250  $node->addDetector($detector);
251  $detectors = $node->getDetectors();
252 
253  // Assert
254  $this->assertEquals($detector, $detectors[0]);
255  }
256 
257  public function testAddEmitter()
258  {
259  // Arrange
260  $node = new ilBasicNode($this->workflow);
261  require_once './Services/WorkflowEngine/classes/emitters/class.ilSimpleEmitter.php';
262  $emitter = new ilSimpleEmitter($node);
263 
264  // Act
265  $node->addEmitter($emitter);
266  $emitters = $node->getEmitters();
267 
268  // Assert
269  $this->assertEquals($emitter, $emitters[0]);
270  }
271 
272  public function testAddActivity()
273  {
274  // Arrange
275  $node = new ilBasicNode($this->workflow);
276  require_once './Services/WorkflowEngine/classes/activities/class.ilLoggingActivity.php';
277  $activity = new ilLoggingActivity($node);
278 
279  // Act
280  $node->addActivity($activity);
281  $activities = $node->getActivities();
282 
283  // Assert
284  $this->assertEquals($activity, $activities[0]);
285  }
286 
288  {
289  // Arrange
290  $node = new ilBasicNode($this->workflow);
291 
292  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
293  $detector = new ilSimpleDetector($node);
294  $node->addDetector($detector);
295 
296  // Note: Order is important. Setting detector state prior to activation
297  // will be voided.
298  $node->activate();
299  $detector->setDetectorState(true);
300  /* Setting the detector to true will actually be reported
301  * with notifyDetectorSatisfaction.
302  * To isolate this call, we need to reset the node back
303  * to active prior to evaluating if it successfully executes
304  * the transition and sets itself to inactive.
305  */
306 
307  // Act
308  $node->notifyDetectorSatisfaction($detector);
309 
310  // Assert
311  $this->assertFalse($node->isActive());
312  }
313 
315  {
316  // Arrange
317  $node = new ilBasicNode($this->workflow);
318  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
319  $detector = new ilSimpleDetector($node);
320  $node->addDetector($detector);
321 
322  // Act
323  $node->activate();
324 
325  // Assert
326  $this->assertFalse($node->isForwardConditionNode(), 'Forward condition should be false by default.');
327  $node->setIsForwardConditionNode(true);
328  $this->assertTrue($node->isForwardConditionNode(), 'Forward condition node state not properly stored.');
329  }
330 
331 }
testExecuteActivitiesViaExecuteTransition()
testCheckTransitionPreconditionsValid()
ilBasicNodeTest is part of the petri net based workflow engine.
$result
PhpIncludeInspection
PhpIncludeInspection
testExecuteEmitterViaExecuteTransition()
testCheckTransitionPreconditionsInvalid()
PhpIncludeInspection
Create styles array
The data for the language used.
global $ilSetting
Definition: privfeed.php:17
PhpIncludeInspection
PhpIncludeInspection