ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
41 $ilSetting->delete( 'IL_PHPUNIT_TEST_TIME' );
42 $ilSetting->delete( 'IL_PHPUNIT_TEST_MICROTIME' );
43 }
44 }
45
47 {
48 // Act
49 $detector = new ilCounterDetector($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
60 {
61 // Arrange
62 $detector = new ilCounterDetector($this->node);
63 $expected = 4711;
64
65 // Act
66 $detector->setExpectedTriggerEvents($expected);
67 $actual = $detector->getExpectedTriggerEvents();
68
69 // Assert
70 $this->assertEquals($actual, $expected);
71 }
72
74 {
75 // Arrange
76 $detector = new ilCounterDetector($this->node);
77 $expected = 4711;
78
79 // Act
80 $detector->setActualTriggerEvents($expected);
81 $actual = $detector->getActualTriggerEvents();
82
83 // Assert
84 $this->assertEquals($actual, $expected);
85 }
86
87 public function testTriggerUnsatisfy()
88 {
89 // Arrange
90 $detector = new ilCounterDetector($this->node);
91 $expected = 2;
92 $detector->setExpectedTriggerEvents($expected);
93
94 // Act
95 $detector->trigger(null);
96
97 // Assert
98 $valid_state = true;
99 if ($detector->getActualTriggerEvents() != 1)
100 {
101 $valid_state = false;
102 }
103
104 if($detector->getExpectedTriggerEvents() != $expected)
105 {
106 $valid_state = false;
107 }
108
109 if ($detector->getDetectorState())
110 {
111 $valid_state = false;
112 }
113
114 $this->assertTrue($valid_state, 'Detector state invalid.');
115 }
116
117 public function testTriggerSatisfy()
118 {
119 // Arrange
120 $detector = new ilCounterDetector($this->node);
121 $expected = 2;
122 $detector->setExpectedTriggerEvents($expected);
123
124 // Act
125 $detector->trigger(null);
126 $detector->trigger(null);
127
128 // Assert
129 $valid_state = true;
130
131 if ($detector->getActualTriggerEvents() != 2)
132 {
133 $valid_state = false;
134 }
135
136 if($detector->getExpectedTriggerEvents() != $expected)
137 {
138 $valid_state = false;
139 }
140
141 if (!$detector->getDetectorState())
142 {
143 $valid_state = false;
144 }
145
146 $this->assertTrue($valid_state, 'Detector state invalid.');
147 }
148
149 public function testTriggerOversatisfy()
150 {
151 // Arrange
152 $detector = new ilCounterDetector($this->node);
153 $expected = 2;
154 $detector->setExpectedTriggerEvents($expected);
155
156 // Act & Assert
157 $this->assertTrue($detector->trigger(null));
158 $this->assertTrue($detector->trigger(null));
159 $this->assertFalse($detector->trigger(null));
160 }
161
162 public function testGetContext()
163 {
164 // Arrange
165 $detector = new ilCounterDetector($this->node);
166
167 // Act
168 $actual = $detector->getContext();
169
170 // Assert
171 if ($actual === $this->node)
172 {
173 $this->assertEquals($actual, $this->node);
174 } else {
175 $this->assertTrue(false, 'Context not identical.');
176 }
177 }
178}
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