ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilActivationEmitterTest.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 // Basic node
27 require_once './Services/WorkflowEngine/classes/nodes/class.ilBasicNode.php';
28 $this->node = new ilBasicNode($this->workflow);
29
30 // Wiring up so the node is attached to the workflow.
31 $this->workflow->addNode($this->node);
32
33 require_once './Services/WorkflowEngine/classes/emitters/class.ilActivationEmitter.php';
34 }
35
36 public function tearDown()
37 {
38 global $ilSetting;
39 if ($ilSetting != NULL)
40 {
41 $ilSetting->delete('IL_PHPUNIT_TEST_TIME');
42 $ilSetting->delete('IL_PHPUNIT_TEST_MICROTIME');
43 }
44 }
45
47 {
48 // Act
49 $emitter = new ilActivationEmitter($this->node);
50
51 // Assert
52 // No exception - good
53 $this->assertTrue(
54 true,
55 'Construction failed with valid context passed to constructor.'
56 );
57 }
58
59 public function testGetContext()
60 {
61 // Arrange
62 $emitter = new ilActivationEmitter($this->node);
63
64 // Act
65 $actual = $emitter->getContext();
66
67 // Assert
68 if ($actual === $this->node)
69 {
70 $this->assertEquals($actual, $this->node);
71 } else {
72 $this->assertTrue(false, 'Context not identical.');
73 }
74 }
75
76 public function testSetGetTargetDetector()
77 {
78 // Arrange
79 require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
80 $target_node = new ilBasicNode($this->workflow);
81 $target_detector = new ilSimpleDetector($target_node);
82 $target_node->addDetector($target_detector);
83
84 $emitter = new ilActivationEmitter($this->node);
85
86 // Act
87 $emitter->setTargetDetector($target_detector);
88
89 // Assert
90 $actual = $emitter->getTargetDetector();
91 $this->assertEquals($target_detector, $actual);
92 }
93
94 public function testEmitValidState()
95 {
96 // Arrange
97 require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
98 $target_node = new ilBasicNode($this->workflow);
99 $target_detector = new ilSimpleDetector($target_node);
100 $target_node->addDetector($target_detector);
101
102 // Blocking detector to keep node from transitting and resetting state.
103 $foo_detector = new ilSimpleDetector($target_node);
104 $target_node->addDetector($foo_detector);
105
106 $emitter = new ilActivationEmitter($this->node);
107 $emitter->setTargetDetector($target_detector);
108
109 // Act
110 $emitter->emit();
111 // Assert
112 $actual = $target_detector->getDetectorState();
113 $this->assertTrue($actual);
114 }
115
117 {
118 // Arrange
119 require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
120 $target_node = new ilBasicNode($this->workflow);
121 $target_detector = new ilSimpleDetector($target_node);
122 $foo_detector = new ilSimpleDetector($target_node);
123 $target_node->addDetector($foo_detector);
124 $target_node->addDetector($target_detector);
125
126 /* We want to see if the target node gets activated. To achieve
127 * that, we need a second detector, so the node won't transit
128 * and deactivate on receiving the emit to $target_detector.
129 * Thought you wondered.
130 */
131
132 $emitter = new ilActivationEmitter($this->node);
133 $emitter->setTargetDetector($target_detector);
134
135 // Act
136 $emitter->emit();
137 // Assert
138 $actual = $target_node->isActive();
139 $this->assertTrue($actual);
140 }
141}
An exception for terminatinating execution or to throw for unit testing.
ilActivationEmitterTest is part of the petri net based workflow engine.
@noinspection PhpIncludeInspection
@noinspection PhpIncludeInspection
@noinspection PhpIncludeInspection
@noinspection PhpIncludeInspection
global $ilSetting
Definition: privfeed.php:17