ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 ()
 
 testIsListeningWithPastTimeFrame ()
 
 testIsListeningWithWildcardEndingTimeFrame ()
 
 testIsListeningWithWildcardBeginningTimeFrame ()
 
 testSetGetListeningTimeframe ()
 
 testSetGetDbId ()
 
 testHasDbIdSet ()
 
 testGetNonExistingDbId ()
 
 testHasDbIdUnset ()
 
 testGetEvent ()
 
 testGetEventSubject ()
 
 testGetEventContext ()
 
 testGetContext ()
 

Additional Inherited Members

- Protected Member Functions inherited from ilWorkflowEngineBaseTest
 setGlobalVariable ($name, $value)
 
 setUp ()
 

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.

References ILIAS\GlobalScreen\Provider\__construct().

17  : void
18  {
20 
21  require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowUtils.php';
22 
23  // Empty workflow.
24  require_once './Services/WorkflowEngine/classes/workflows/class.ilEmptyWorkflow.php';
25  $this->workflow = new ilEmptyWorkflow();
26 
27  // Basic node
28  require_once './Services/WorkflowEngine/classes/nodes/class.ilBasicNode.php';
29  $this->node = new ilBasicNode($this->workflow);
30 
31  // Wiring up so the node is attached to the workflow.
32  $this->workflow->addNode($this->node);
33 
34  require_once './Services/WorkflowEngine/classes/detectors/class.ilTimerDetector.php';
35  }
PhpIncludeInspection
__construct(Container $dic, ilPlugin $plugin)
PhpIncludeInspection
+ Here is the call graph for this function:

◆ tearDown()

ilTimerDetectorTest::tearDown ( )

Definition at line 37 of file ilTimerDetectorTest.php.

References $DIC.

37  : void
38  {
39  global $DIC;
40 
41  if (isset($DIC['ilSetting'])) {
42  $DIC['ilSetting']->delete('IL_PHPUNIT_TEST_TIME');
43  $DIC['ilSetting']->delete('IL_PHPUNIT_TEST_MICROTIME');
44  }
45  }
$DIC
Definition: xapitoken.php:46

◆ 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 354 of file ilTimerDetectorTest.php.

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

◆ testGetEvent()

ilTimerDetectorTest::testGetEvent ( )

Definition at line 306 of file ilTimerDetectorTest.php.

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

◆ testGetEventContext()

ilTimerDetectorTest::testGetEventContext ( )

Definition at line 338 of file ilTimerDetectorTest.php.

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

◆ testGetEventSubject()

ilTimerDetectorTest::testGetEventSubject ( )

Definition at line 322 of file ilTimerDetectorTest.php.

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

◆ testGetNonExistingDbId()

ilTimerDetectorTest::testGetNonExistingDbId ( )

Definition at line 279 of file ilTimerDetectorTest.php.

280  {
281  $this->expectException(ilWorkflowObjectStateException::class);
282 
283  // Arrange
284  $detector = new ilTimerDetector($this->node);
285  $expected = '1234';
286 
287  // Act
288  $actual = $detector->getDbId();
289 
290  // Assert
291  $this->assertEquals($expected, $actual);
292  }
PhpIncludeInspection

◆ testHasDbIdSet()

ilTimerDetectorTest::testHasDbIdSet ( )

Definition at line 262 of file ilTimerDetectorTest.php.

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

◆ testHasDbIdUnset()

ilTimerDetectorTest::testHasDbIdUnset ( )

Definition at line 294 of file ilTimerDetectorTest.php.

295  {
296  // Arrange
297  $detector = new ilTimerDetector($this->node);
298 
299  // Act
300  $actual = $detector->hasDbId();
301 
302  // Assert
303  $this->assertFalse($actual);
304  }
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 188 of file ilTimerDetectorTest.php.

189  {
190  // Arrange
191  $detector = new ilTimerDetector($this->node);
192  $timer_start = ilWorkflowUtils::time() - 5 * 60; # -5 Minutes from now.
193  $timer_end = ilWorkflowUtils::time() - 1 * 60; # -1 Minute from now.
194  $detector->setListeningTimeframe($timer_start, $timer_end);
195 
196  // Act
197  $actual = $detector->isListening();
198 
199  // Assert
200  $this->assertFalse($actual, 'Detector should not be listening.');
201  }
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 218 of file ilTimerDetectorTest.php.

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

◆ testIsListeningWithWildcardEndingTimeFrame()

ilTimerDetectorTest::testIsListeningWithWildcardEndingTimeFrame ( )

Definition at line 203 of file ilTimerDetectorTest.php.

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

◆ testSetGetDbId()

ilTimerDetectorTest::testSetGetDbId ( )

Definition at line 248 of file ilTimerDetectorTest.php.

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

◆ testSetGetIllegalListeningTimeframe()

ilTimerDetectorTest::testSetGetIllegalListeningTimeframe ( )

Definition at line 171 of file ilTimerDetectorTest.php.

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

◆ testSetGetListeningTimeframe()

ilTimerDetectorTest::testSetGetListeningTimeframe ( )

Definition at line 233 of file ilTimerDetectorTest.php.

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