ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilCounterDetectorTest.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/detectors/class.ilCounterDetector.php';
34 }
35
36 public function tearDown()
37 {
38 global $ilSetting;
39 if ($ilSetting != null) {
40 $ilSetting->delete('IL_PHPUNIT_TEST_TIME');
41 $ilSetting->delete('IL_PHPUNIT_TEST_MICROTIME');
42 }
43 }
44
46 {
47 // Act
48 $detector = new ilCounterDetector($this->node);
49
50 // Assert
51 // No exception - good
52 $this->assertTrue(
53 true,
54 'Construction failed with valid context passed to constructor.'
55 );
56 }
57
59 {
60 // Arrange
61 $detector = new ilCounterDetector($this->node);
62 $expected = 4711;
63
64 // Act
65 $detector->setExpectedTriggerEvents($expected);
66 $actual = $detector->getExpectedTriggerEvents();
67
68 // Assert
69 $this->assertEquals($actual, $expected);
70 }
71
73 {
74 // Arrange
75 $detector = new ilCounterDetector($this->node);
76 $expected = 4711;
77
78 // Act
79 $detector->setActualTriggerEvents($expected);
80 $actual = $detector->getActualTriggerEvents();
81
82 // Assert
83 $this->assertEquals($actual, $expected);
84 }
85
86 public function testTriggerUnsatisfy()
87 {
88 // Arrange
89 $detector = new ilCounterDetector($this->node);
90 $expected = 2;
91 $detector->setExpectedTriggerEvents($expected);
92
93 // Act
94 $detector->trigger(null);
95
96 // Assert
97 $valid_state = true;
98 if ($detector->getActualTriggerEvents() != 1) {
99 $valid_state = false;
100 }
101
102 if ($detector->getExpectedTriggerEvents() != $expected) {
103 $valid_state = false;
104 }
105
106 if ($detector->getDetectorState()) {
107 $valid_state = false;
108 }
109
110 $this->assertTrue($valid_state, 'Detector state invalid.');
111 }
112
113 public function testTriggerSatisfy()
114 {
115 // Arrange
116 $detector = new ilCounterDetector($this->node);
117 $expected = 2;
118 $detector->setExpectedTriggerEvents($expected);
119
120 // Act
121 $detector->trigger(null);
122 $detector->trigger(null);
123
124 // Assert
125 $valid_state = true;
126
127 if ($detector->getActualTriggerEvents() != 2) {
128 $valid_state = false;
129 }
130
131 if ($detector->getExpectedTriggerEvents() != $expected) {
132 $valid_state = false;
133 }
134
135 if (!$detector->getDetectorState()) {
136 $valid_state = false;
137 }
138
139 $this->assertTrue($valid_state, 'Detector state invalid.');
140 }
141
142 public function testTriggerOversatisfy()
143 {
144 // Arrange
145 $detector = new ilCounterDetector($this->node);
146 $expected = 2;
147 $detector->setExpectedTriggerEvents($expected);
148
149 // Act & Assert
150 $this->assertTrue($detector->trigger(null));
151 $this->assertTrue($detector->trigger(null));
152 $this->assertFalse($detector->trigger(null));
153 }
154
155 public function testGetContext()
156 {
157 // Arrange
158 $detector = new ilCounterDetector($this->node);
159
160 // Act
161 $actual = $detector->getContext();
162
163 // Assert
164 if ($actual === $this->node) {
165 $this->assertEquals($actual, $this->node);
166 } else {
167 $this->assertTrue(false, 'Context not identical.');
168 }
169 }
170}
An exception for terminatinating execution or to throw for unit testing.
@noinspection PhpIncludeInspection
ilCounterDetectorTest is part of the petri net based workflow engine.
@noinspection PhpIncludeInspection
@noinspection PhpIncludeInspection
global $ilSetting
Definition: privfeed.php:17