ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilBasicNodeTest Class Reference

ilBasicNodeTest is part of the petri net based workflow engine. More...

+ Inheritance diagram for ilBasicNodeTest:
+ Collaboration diagram for ilBasicNodeTest:

Public Member Functions

 setUp ()
 
 tearDown ()
 
 testConstructorValidContext ()
 
 testGetContext ()
 
 testIsActiveAndActivate ()
 
 testDeactivate ()
 
 testCheckTransitionPreconditionsValid ()
 
 testCheckTransitionPreconditionsInvalid ()
 
 testAttemptTransitionValid ()
 
 testAttemptTransitionInvalid ()
 
 testExecuteTransition ()
 
 testExecuteActivitiesViaExecuteTransition ()
 
 testExecuteEmitterViaExecuteTransition ()
 
 testAddDetector ()
 
 testAddEmitter ()
 
 testAddActivity ()
 
 testNotifyDetectorSatisfaction ()
 
 testSetGetIsForwardConditionNode ()
 

Detailed Description

ilBasicNodeTest is part of the petri net based workflow engine.

This class holds all tests for the class nodes/class.ilBasicNode

Author
Maximilian Becker mbeck.nosp@m.er@d.nosp@m.ataba.nosp@m.y.de
Version
$Id$

/

Definition at line 15 of file ilBasicNodeTest.php.

Member Function Documentation

◆ setUp()

ilBasicNodeTest::setUp ( )

Definition at line 17 of file ilBasicNodeTest.php.

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  }
PhpIncludeInspection

◆ tearDown()

ilBasicNodeTest::tearDown ( )

Definition at line 27 of file ilBasicNodeTest.php.

References $ilSetting.

28  {
29  global $ilSetting;
30  if ($ilSetting != null) {
31  $ilSetting->delete('IL_PHPUNIT_TEST_TIME');
32  $ilSetting->delete('IL_PHPUNIT_TEST_MICROTIME');
33  }
34  }
global $ilSetting
Definition: privfeed.php:17

◆ testAddActivity()

ilBasicNodeTest::testAddActivity ( )

Definition at line 270 of file ilBasicNodeTest.php.

271  {
272  // Arrange
273  $node = new ilBasicNode($this->workflow);
274  require_once './Services/WorkflowEngine/classes/activities/class.ilLoggingActivity.php';
275  $activity = new ilLoggingActivity($node);
276 
277  // Act
278  $node->addActivity($activity);
279  $activities = $node->getActivities();
280 
281  // Assert
282  $this->assertEquals($activity, $activities[0]);
283  }
PhpIncludeInspection
PhpIncludeInspection

◆ testAddDetector()

ilBasicNodeTest::testAddDetector ( )

Definition at line 240 of file ilBasicNodeTest.php.

241  {
242  // Arrange
243  $node = new ilBasicNode($this->workflow);
244  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
245  $detector = new ilSimpleDetector($node);
246 
247  // Act
248  $node->addDetector($detector);
249  $detectors = $node->getDetectors();
250 
251  // Assert
252  $this->assertEquals($detector, $detectors[0]);
253  }
PhpIncludeInspection
PhpIncludeInspection

◆ testAddEmitter()

ilBasicNodeTest::testAddEmitter ( )

Definition at line 255 of file ilBasicNodeTest.php.

256  {
257  // Arrange
258  $node = new ilBasicNode($this->workflow);
259  require_once './Services/WorkflowEngine/classes/emitters/class.ilSimpleEmitter.php';
260  $emitter = new ilSimpleEmitter($node);
261 
262  // Act
263  $node->addEmitter($emitter);
264  $emitters = $node->getEmitters();
265 
266  // Assert
267  $this->assertEquals($emitter, $emitters[0]);
268  }
PhpIncludeInspection
PhpIncludeInspection

◆ testAttemptTransitionInvalid()

ilBasicNodeTest::testAttemptTransitionInvalid ( )

Definition at line 147 of file ilBasicNodeTest.php.

References $result.

148  {
149  // Arrange
150  $node = new ilBasicNode($this->workflow);
151  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
152  $detector = new ilSimpleDetector($node);
153  $node->addDetector($detector);
154 
155  // Act
156  $result = $node->attemptTransition();
157 
158  // Assert
159  $this->assertFalse($result);
160  }
$result
PhpIncludeInspection
PhpIncludeInspection

◆ testAttemptTransitionValid()

ilBasicNodeTest::testAttemptTransitionValid ( )

Definition at line 131 of file ilBasicNodeTest.php.

References $result.

132  {
133  // Arrange
134  $node = new ilBasicNode($this->workflow);
135  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
136  $detector = new ilSimpleDetector($node);
137  $node->addDetector($detector);
138 
139  // Act
140  $detector->trigger(array());
141  $result = $node->attemptTransition();
142 
143  // Assert
144  $this->assertTrue($result);
145  }
$result
PhpIncludeInspection
PhpIncludeInspection

◆ testCheckTransitionPreconditionsInvalid()

ilBasicNodeTest::testCheckTransitionPreconditionsInvalid ( )

Definition at line 115 of file ilBasicNodeTest.php.

116  {
117  // Arrange
118  $node = new ilBasicNode($this->workflow);
119  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
120  $detector = new ilSimpleDetector($node);
121  $node->addDetector($detector);
122 
123 
124  // Act
125  $preconditions = $node->checkTransitionPreconditions();
126 
127  // Assert
128  $this->assertFalse($preconditions);
129  }
PhpIncludeInspection
PhpIncludeInspection

◆ testCheckTransitionPreconditionsValid()

ilBasicNodeTest::testCheckTransitionPreconditionsValid ( )

Definition at line 99 of file ilBasicNodeTest.php.

100  {
101  // Arrange
102  $node = new ilBasicNode($this->workflow);
103  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
104  $detector = new ilSimpleDetector($node);
105  $node->addDetector($detector);
106 
107  // Act
108  $detector->trigger(array());
109  $preconditions = $node->checkTransitionPreconditions();
110 
111  // Assert
112  $this->assertTrue($preconditions);
113  }
PhpIncludeInspection
PhpIncludeInspection

◆ testConstructorValidContext()

ilBasicNodeTest::testConstructorValidContext ( )

Definition at line 36 of file ilBasicNodeTest.php.

37  {
38  // Act
39  $node = new ilBasicNode($this->workflow);
40 
41  // Assert
42  // No exception - good
43  $this->assertTrue(
44  true,
45  'Construction failed with valid context passed to constructor.'
46  );
47  }
PhpIncludeInspection

◆ testDeactivate()

ilBasicNodeTest::testDeactivate ( )

Definition at line 81 of file ilBasicNodeTest.php.

82  {
83  // Arrange
84  $node = new ilBasicNode($this->workflow);
85  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
86  $detector = new ilSimpleDetector($node);
87  $node->addDetector($detector);
88 
89  // Act
90  $node->activate();
91  $was_activated = $node->isActive();
92  $node->deactivate();
93  $was_deactivated = !$node->isActive();
94 
95  // Assert
96  $this->assertEquals($was_activated, $was_deactivated);
97  }
PhpIncludeInspection
PhpIncludeInspection

◆ testExecuteActivitiesViaExecuteTransition()

ilBasicNodeTest::testExecuteActivitiesViaExecuteTransition ( )

Definition at line 181 of file ilBasicNodeTest.php.

182  {
183  // Arrange
184  $node = new ilBasicNode($this->workflow);
185  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
186  $detector = new ilSimpleDetector($node);
187  $node->addDetector($detector);
188 
189  require_once './Services/WorkflowEngine/classes/activities/class.ilLoggingActivity.php';
190  $activity = new ilLoggingActivity($node);
191  $activity->setLogFile('ilTransitionLog.txt');
192  $activity->setLogLevel('MESSAGE');
193  $activity->setLogMessage('TEST');
194  $node->addActivity($activity);
195 
196  // Act
197  $node->activate();
198  $node->executeTransition();
199 
200  // Assert
201  $expected = ' :: MESSAGE :: TEST';
202  $fp = fopen('ilTransitionLog.txt', 'r');
203  $line = fgets($fp);
204  $actual = substr($line, 25, strlen($line) - 27);
205  @unlink('ilTransitionLog.txt'); // TODO: Use vfsStream
206  $this->assertEquals(
207  $actual,
208  $expected
209  );
210  }
PhpIncludeInspection
PhpIncludeInspection
PhpIncludeInspection

◆ testExecuteEmitterViaExecuteTransition()

ilBasicNodeTest::testExecuteEmitterViaExecuteTransition ( )

Definition at line 212 of file ilBasicNodeTest.php.

213  {
214  // Arrange
215  $node = new ilBasicNode($this->workflow);
216  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
217  $detector = new ilSimpleDetector($node);
218  $node->addDetector($detector);
219 
220  require_once './Services/WorkflowEngine/classes/emitters/class.ilActivationEmitter.php';
221  $t_node = new ilBasicNode($this->workflow);
222  $t_detector = new ilSimpleDetector($t_node);
223  $t_node->addDetector($t_detector);
224  $foo_detector = new ilSimpleDetector($t_node);
225  $t_node->addDetector($foo_detector);
226  // again a foo_detector to keep the t_node from transitting
227 
228  $emitter = new ilActivationEmitter($node);
229  $emitter->setTargetDetector($t_detector);
230  $node->addEmitter($emitter);
231 
232  // Act
233  $node->activate();
234  $node->executeTransition();
235 
236  // Assert
237  $this->assertTrue($t_node->isActive());
238  }
PhpIncludeInspection
PhpIncludeInspection

◆ testExecuteTransition()

ilBasicNodeTest::testExecuteTransition ( )

Definition at line 162 of file ilBasicNodeTest.php.

References $state.

163  { // This is test #100 of the WorkflowEngine, written on 9th of May, 2012
164  // @ 14:15
165 
166  // Arrange
167  $node = new ilBasicNode($this->workflow);
168  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
169  $detector = new ilSimpleDetector($node);
170  $node->addDetector($detector);
171  $node->activate();
172 
173  // Act
174  $node->executeTransition();
175  $state = $node->isActive();
176 
177  // Assert
178  $this->assertFalse($state);
179  }
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
PhpIncludeInspection
PhpIncludeInspection

◆ testGetContext()

ilBasicNodeTest::testGetContext ( )

Definition at line 49 of file ilBasicNodeTest.php.

50  {
51  // Arrange
52  $node = new ilBasicNode($this->workflow);
53 
54  // Act
55  $actual = $node->getContext();
56 
57  // Assert
58  if ($actual === $this->workflow) {
59  $this->assertEquals($actual, $this->workflow);
60  } else {
61  $this->assertTrue(false, 'Context not identical.');
62  }
63  }
PhpIncludeInspection

◆ testIsActiveAndActivate()

ilBasicNodeTest::testIsActiveAndActivate ( )

Definition at line 65 of file ilBasicNodeTest.php.

66  {
67  // Arrange
68  $node = new ilBasicNode($this->workflow);
69  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
70  $detector = new ilSimpleDetector($node);
71  $node->addDetector($detector);
72 
73  // Act
74  $node->activate();
75 
76  // Assert
77  $actual = $node->isActive();
78  $this->assertTrue($actual);
79  }
PhpIncludeInspection
PhpIncludeInspection

◆ testNotifyDetectorSatisfaction()

ilBasicNodeTest::testNotifyDetectorSatisfaction ( )

Definition at line 285 of file ilBasicNodeTest.php.

286  {
287  // Arrange
288  $node = new ilBasicNode($this->workflow);
289 
290  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
291  $detector = new ilSimpleDetector($node);
292  $node->addDetector($detector);
293 
294  // Note: Order is important. Setting detector state prior to activation
295  // will be voided.
296  $node->activate();
297  $detector->setDetectorState(true);
298  /* Setting the detector to true will actually be reported
299  * with notifyDetectorSatisfaction.
300  * To isolate this call, we need to reset the node back
301  * to active prior to evaluating if it successfully executes
302  * the transition and sets itself to inactive.
303  */
304 
305  // Act
306  $node->notifyDetectorSatisfaction($detector);
307 
308  // Assert
309  $this->assertFalse($node->isActive());
310  }
PhpIncludeInspection
PhpIncludeInspection

◆ testSetGetIsForwardConditionNode()

ilBasicNodeTest::testSetGetIsForwardConditionNode ( )

Definition at line 312 of file ilBasicNodeTest.php.

313  {
314  // Arrange
315  $node = new ilBasicNode($this->workflow);
316  require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
317  $detector = new ilSimpleDetector($node);
318  $node->addDetector($detector);
319 
320  // Act
321  $node->activate();
322 
323  // Assert
324  $this->assertFalse($node->isForwardConditionNode(), 'Forward condition should be false by default.');
325  $node->setIsForwardConditionNode(true);
326  $this->assertTrue($node->isForwardConditionNode(), 'Forward condition node state not properly stored.');
327  }
PhpIncludeInspection
PhpIncludeInspection

The documentation for this class was generated from the following file: