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

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

+ Inheritance diagram for ilTimerDetectorTest:
+ Collaboration diagram for ilTimerDetectorTest:

Public Member Functions

 setUp ()
 
 tearDown ()
 
 testConstructorValidContext ()
 
 testSetGetTimerStart ()
 
 testSetGetTimerLimit ()
 
 testTriggerEarly ()
 
 testTriggerValid ()
 
 testTriggerValidTwice ()
 
 testIsListeningWithTimeFrame ()
 
 testIsListeningWithoutTimeFrame ()
 
 testSetGetIllegalListeningTimeframe ()
 ilWorkflowInvalidArgumentException More...
 
 testIsListeningWithPastTimeFrame ()
 
 testIsListeningWithWildcardEndingTimeFrame ()
 
 testIsListeningWithWildcardBeginningTimeFrame ()
 
 testSetGetListeningTimeframe ()
 
 testSetGetDbId ()
 
 testHasDbIdSet ()
 
 testGetNonExistingDbId ()
 ilWorkflowObjectStateException More...
 
 testHasDbIdUnset ()
 
 testGetEvent ()
 
 testGetEventSubject ()
 
 testGetEventContext ()
 
 testGetContext ()
 

Detailed Description

ilTimerDetectorTest is part of the petri net based workflow engine.

This class holds all tests for the class detectors/class.ilTimerDetector

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

/

Definition at line 15 of file ilTimerDetectorTest.php.

Member Function Documentation

◆ setUp()

ilTimerDetectorTest::setUp ( )

Definition at line 17 of file ilTimerDetectorTest.php.

18  {
19  include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
20  //ilUnitUtil::performInitialisation();
21 
22  require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowUtils.php';
23 
24  // Empty workflow.
25  require_once './Services/WorkflowEngine/classes/workflows/class.ilEmptyWorkflow.php';
26  $this->workflow = new ilEmptyWorkflow();
27 
28  // Basic node
29  require_once './Services/WorkflowEngine/classes/nodes/class.ilBasicNode.php';
30  $this->node = new ilBasicNode($this->workflow);
31 
32  // Wiring up so the node is attached to the workflow.
33  $this->workflow->addNode($this->node);
34 
35  require_once './Services/WorkflowEngine/classes/detectors/class.ilTimerDetector.php';
36  }
PhpIncludeInspection
PhpIncludeInspection

◆ tearDown()

ilTimerDetectorTest::tearDown ( )

Definition at line 38 of file ilTimerDetectorTest.php.

References $ilSetting.

39  {
40  global $ilSetting;
41  if ($ilSetting != null) {
42  $ilSetting->delete('IL_PHPUNIT_TEST_TIME');
43  $ilSetting->delete('IL_PHPUNIT_TEST_MICROTIME');
44  }
45  }
global $ilSetting
Definition: privfeed.php:17

◆ testConstructorValidContext()

ilTimerDetectorTest::testConstructorValidContext ( )

Definition at line 47 of file ilTimerDetectorTest.php.

48  {
49  // Act
50  $detector = new ilTimerDetector($this->node);
51 
52  // Assert
53  // No exception - good
54  $this->assertTrue(
55  true,
56  'Construction failed with valid context passed to constructor.'
57  );
58  }
PhpIncludeInspection

◆ testGetContext()

ilTimerDetectorTest::testGetContext ( )

Definition at line 350 of file ilTimerDetectorTest.php.

351  {
352  // Arrange
353  $detector = new ilTimerDetector($this->node);
354 
355  // Act
356  $actual = $detector->getContext();
357 
358  // Assert
359  if ($actual === $this->node) {
360  $this->assertEquals($actual, $this->node);
361  } else {
362  $this->assertTrue(false, 'Context not identical.');
363  }
364  }
PhpIncludeInspection

◆ testGetEvent()

ilTimerDetectorTest::testGetEvent ( )

Definition at line 302 of file ilTimerDetectorTest.php.

303  {
304  // Arrange
305  $detector = new ilTimerDetector($this->node);
306  $exp_type = 'time_passed';
307  $exp_content = 'time_passed';
308 
309  // Act
310 
311  // Assert
312  $event = $detector->getEvent();
313  $act_type = $event['type'];
314  $act_content = $event['content'];
315  $this->assertEquals($exp_type . $exp_content, $act_type . $act_content);
316  }
PhpIncludeInspection

◆ testGetEventContext()

ilTimerDetectorTest::testGetEventContext ( )

Definition at line 334 of file ilTimerDetectorTest.php.

335  {
336  // Arrange
337  $detector = new ilTimerDetector($this->node);
338  $exp_type = 'none';
339  $exp_id = '0';
340 
341  // Act
342 
343  // Assert
344  $event = $detector->getEventContext();
345  $act_type = $event['type'];
346  $act_id = $event['identifier'];
347  $this->assertEquals($exp_type . $exp_id, $act_type . $act_id);
348  }
PhpIncludeInspection

◆ testGetEventSubject()

ilTimerDetectorTest::testGetEventSubject ( )

Definition at line 318 of file ilTimerDetectorTest.php.

319  {
320  // Arrange
321  $detector = new ilTimerDetector($this->node);
322  $exp_type = 'none';
323  $exp_id = '0';
324 
325  // Act
326 
327  // Assert
328  $event = $detector->getEventSubject();
329  $act_type = $event['type'];
330  $act_id = $event['identifier'];
331  $this->assertEquals($exp_type . $exp_id, $act_type . $act_id);
332  }
PhpIncludeInspection

◆ testGetNonExistingDbId()

ilTimerDetectorTest::testGetNonExistingDbId ( )

ilWorkflowObjectStateException

Definition at line 277 of file ilTimerDetectorTest.php.

278  {
279  // Arrange
280  $detector = new ilTimerDetector($this->node);
281  $expected = '1234';
282 
283  // Act
284  $actual = $detector->getDbId();
285 
286  // Assert
287  $this->assertEquals($expected, $actual);
288  }
PhpIncludeInspection

◆ testHasDbIdSet()

ilTimerDetectorTest::testHasDbIdSet ( )

Definition at line 260 of file ilTimerDetectorTest.php.

261  {
262  // Arrange
263  $detector = new ilTimerDetector($this->node);
264  $expected = '1234';
265 
266  // Act
267  $detector->setDbId($expected);
268  $actual = $detector->hasDbId();
269 
270  // Assert
271  $this->assertTrue($actual);
272  }
PhpIncludeInspection

◆ testHasDbIdUnset()

ilTimerDetectorTest::testHasDbIdUnset ( )

Definition at line 290 of file ilTimerDetectorTest.php.

291  {
292  // Arrange
293  $detector = new ilTimerDetector($this->node);
294 
295  // Act
296  $actual = $detector->hasDbId();
297 
298  // Assert
299  $this->assertFalse($actual);
300  }
PhpIncludeInspection

◆ testIsListeningWithoutTimeFrame()

ilTimerDetectorTest::testIsListeningWithoutTimeFrame ( )

Definition at line 154 of file ilTimerDetectorTest.php.

155  {
156  // Arrange
157  $detector = new ilTimerDetector($this->node);
158  $timer_start = ilWorkflowUtils::time() + 5 * 60; # +5 Minutes from here.
159  $timer_end = 0;
160 
161  // Act
162  $actual = $detector->isListening();
163 
164  // Assert
165  $this->assertTrue($actual, 'Detector should be listening.');
166  }
PhpIncludeInspection

◆ testIsListeningWithPastTimeFrame()

ilTimerDetectorTest::testIsListeningWithPastTimeFrame ( )

Definition at line 186 of file ilTimerDetectorTest.php.

187  {
188  // Arrange
189  $detector = new ilTimerDetector($this->node);
190  $timer_start = ilWorkflowUtils::time() - 5 * 60; # -5 Minutes from now.
191  $timer_end = ilWorkflowUtils::time() - 1 * 60; # -1 Minute from now.
192  $detector->setListeningTimeframe($timer_start, $timer_end);
193 
194  // Act
195  $actual = $detector->isListening();
196 
197  // Assert
198  $this->assertFalse($actual, 'Detector should not be listening.');
199  }
PhpIncludeInspection

◆ testIsListeningWithTimeFrame()

ilTimerDetectorTest::testIsListeningWithTimeFrame ( )

Definition at line 139 of file ilTimerDetectorTest.php.

140  {
141  // Arrange
142  $detector = new ilTimerDetector($this->node);
143  $timer_start = ilWorkflowUtils::time() + 5 * 60; # +5 Minutes from here.
144  $timer_end = 0;
145  $detector->setListeningTimeframe($timer_start, $timer_end);
146 
147  // Act
148  $actual = $detector->isListening();
149 
150  // Assert
151  $this->assertFalse($actual, 'Detector should not be listening.');
152  }
PhpIncludeInspection

◆ testIsListeningWithWildcardBeginningTimeFrame()

ilTimerDetectorTest::testIsListeningWithWildcardBeginningTimeFrame ( )

Definition at line 216 of file ilTimerDetectorTest.php.

217  {
218  // Arrange
219  $detector = new ilTimerDetector($this->node);
220  $timer_start = 0; # Wildcard.
221  $timer_end = ilWorkflowUtils::time() + 5 * 60; # +5 Minutes from now.
222  $detector->setListeningTimeframe($timer_start, $timer_end);
223 
224  // Act
225  $actual = $detector->isListening();
226 
227  // Assert
228  $this->assertTrue($actual, 'Detector should not be listening.');
229  }
PhpIncludeInspection

◆ testIsListeningWithWildcardEndingTimeFrame()

ilTimerDetectorTest::testIsListeningWithWildcardEndingTimeFrame ( )

Definition at line 201 of file ilTimerDetectorTest.php.

202  {
203  // Arrange
204  $detector = new ilTimerDetector($this->node);
205  $timer_start = ilWorkflowUtils::time() - 5 * 60; # -5 Minutes from now.
206  $timer_end = 0; # Wildcard.
207  $detector->setListeningTimeframe($timer_start, $timer_end);
208 
209  // Act
210  $actual = $detector->isListening();
211 
212  // Assert
213  $this->assertTrue($actual, 'Detector should not be listening.');
214  }
PhpIncludeInspection

◆ testSetGetDbId()

ilTimerDetectorTest::testSetGetDbId ( )

Definition at line 246 of file ilTimerDetectorTest.php.

247  {
248  // Arrange
249  $detector = new ilTimerDetector($this->node);
250  $expected = '1234';
251 
252  // Act
253  $detector->setDbId($expected);
254  $actual = $detector->getDbId();
255 
256  // Assert
257  $this->assertEquals($expected, $actual);
258  }
PhpIncludeInspection

◆ testSetGetIllegalListeningTimeframe()

ilTimerDetectorTest::testSetGetIllegalListeningTimeframe ( )

ilWorkflowInvalidArgumentException

Definition at line 171 of file ilTimerDetectorTest.php.

172  {
173  // Arrange
174  $detector = new ilTimerDetector($this->node);
175  $exp_start = 4712;
176  $exp_end = 4711;
177 
178  // Act
179  $detector->setListeningTimeframe($exp_start, $exp_end);
180  $act = $detector->getListeningTimeframe();
181 
182  // Assert
183  $this->assertEquals($exp_start . $exp_end, $act['listening_start'] . $act['listening_end']);
184  }
PhpIncludeInspection

◆ testSetGetListeningTimeframe()

ilTimerDetectorTest::testSetGetListeningTimeframe ( )

Definition at line 231 of file ilTimerDetectorTest.php.

232  {
233  // Arrange
234  $detector = new ilTimerDetector($this->node);
235  $exp_start = 4711; # +5 Minutes from here.
236  $exp_end = 4712;
237 
238  // Act
239  $detector->setListeningTimeframe($exp_start, $exp_end);
240  $act = $detector->getListeningTimeframe();
241 
242  // Assert
243  $this->assertEquals($exp_start . $exp_end, $act['listening_start'] . $act['listening_end']);
244  }
PhpIncludeInspection

◆ testSetGetTimerLimit()

ilTimerDetectorTest::testSetGetTimerLimit ( )

Definition at line 74 of file ilTimerDetectorTest.php.

75  {
76  // Arrange
77  $detector = new ilTimerDetector($this->node);
78  $expected = 5 * 60 * 60;
79 
80  // Act
81  $detector->setTimerLimit($expected);
82  $actual = $detector->getTimerLimit();
83 
84  // Assert
85  $this->assertEquals($actual, $expected);
86  }
PhpIncludeInspection

◆ testSetGetTimerStart()

ilTimerDetectorTest::testSetGetTimerStart ( )

Definition at line 60 of file ilTimerDetectorTest.php.

61  {
62  // Arrange
63  $detector = new ilTimerDetector($this->node);
64  $expected = ilWorkflowUtils::time();
65 
66  // Act
67  $detector->setTimerStart($expected);
68  $actual = $detector->getTimerStart();
69 
70  // Assert
71  $this->assertEquals($actual, $expected);
72  }
PhpIncludeInspection

◆ testTriggerEarly()

ilTimerDetectorTest::testTriggerEarly ( )

Definition at line 88 of file ilTimerDetectorTest.php.

89  {
90  // Arrange
91  $detector = new ilTimerDetector($this->node);
92  $timer_start = ilWorkflowUtils::time(); # +5 Minutes from here.
93  $timer_limit = 5 * 60;
94  $detector->setTimerStart($timer_start);
95  $detector->setTimerLimit($timer_limit);
96 
97  // Act
98  $detector->trigger(null);
99 
100  // Assert
101  $actual = $detector->getDetectorState();
102  $this->assertFalse($actual, 'Early trigger should not satisfy detector');
103  }
PhpIncludeInspection

◆ testTriggerValid()

ilTimerDetectorTest::testTriggerValid ( )

Definition at line 105 of file ilTimerDetectorTest.php.

106  {
107  // Arrange
108  $detector = new ilTimerDetector($this->node);
109  $timer_start = ilWorkflowUtils::time(); # +5 Minutes from now.
110  $timer_limit = 0;
111  $detector->setTimerStart($timer_start);
112  $detector->setTimerLimit($timer_limit);
113 
114  // Act
115  $detector->trigger(null);
116 
117  // Assert
118  $actual = $detector->getDetectorState();
119  $this->assertTrue($actual, 'Trigger should not satisfy detector');
120  }
PhpIncludeInspection

◆ testTriggerValidTwice()

ilTimerDetectorTest::testTriggerValidTwice ( )

Definition at line 122 of file ilTimerDetectorTest.php.

123  {
124  // Arrange
125  $detector = new ilTimerDetector($this->node);
126  $timer_start = ilWorkflowUtils::time(); # +5 Minutes from now.
127  $timer_limit = 0;
128  $detector->setTimerStart($timer_start);
129  $detector->setTimerLimit($timer_limit);
130 
131  // Act
132  $detector->trigger(null);
133  $actual = $detector->trigger(null);
134 
135  // Assert
136  $this->assertFalse($actual, 'Detector should be satisfied after single trigger');
137  }
PhpIncludeInspection

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