ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ilEventDetectorTest Class Reference

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

+ Inheritance diagram for ilEventDetectorTest:
+ Collaboration diagram for ilEventDetectorTest:

Public Member Functions

 setUp ()
 
 tearDown ()
 
 testConstructorValidContext ()
 
 testIsListeningWithTimeFrame ()
 
 testIsListeningWithPastTimeFrame ()
 
 testIsListeningWithWildcardEndingTimeFrame ()
 
 testIsListeningWithWildcardBeginningTimeFrame ()
 
 testIsListeningWithoutTimeFrame ()
 
 testSetGetListeningTimeframe ()
 
 testSetGetIllegalListeningTimeframe ()
 
 testSetGetDbId ()
 
 testGetNonExistingDbId ()
 
 testHasDbIdSet ()
 
 testHasDbIdUnset ()
 
 testSetGetEvent ()
 
 testSetGetEventSubject ()
 
 testSetGetEventContext ()
 
 testGetContext ()
 
 testTriggerValid ()
 
 testTriggerValidTwice ()
 
 testTriggerInvalidContent ()
 
 testTriggerInvalidType ()
 
 testTriggerInvalidSubjectType ()
 
 testTriggerInvalidSubjectId ()
 
 testTriggerInvalidContextType ()
 
 testTriggerInvalidContextId ()
 

Additional Inherited Members

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

Detailed Description

ilEventDetectorTest is part of the petri net based workflow engine.

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

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

/

Definition at line 15 of file ilEventDetectorTest.php.

Member Function Documentation

◆ setUp()

ilEventDetectorTest::setUp ( )

Definition at line 17 of file ilEventDetectorTest.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.ilEventDetector.php';
35  }
PhpIncludeInspection
__construct(Container $dic, ilPlugin $plugin)
PhpIncludeInspection
+ Here is the call graph for this function:

◆ tearDown()

ilEventDetectorTest::tearDown ( )

Definition at line 37 of file ilEventDetectorTest.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()

ilEventDetectorTest::testConstructorValidContext ( )

Definition at line 47 of file ilEventDetectorTest.php.

48  {
49  // Act
50  $detector = new ilEventDetector($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()

ilEventDetectorTest::testGetContext ( )

Definition at line 276 of file ilEventDetectorTest.php.

277  {
278  // Arrange
279  $detector = new ilEventDetector($this->node);
280 
281  // Act
282  $actual = $detector->getContext();
283 
284  // Assert
285  if ($actual === $this->node) {
286  $this->assertEquals($actual, $this->node);
287  } else {
288  $this->assertTrue(false, 'Context not identical.');
289  }
290  }
PhpIncludeInspection

◆ testGetNonExistingDbId()

ilEventDetectorTest::testGetNonExistingDbId ( )

Definition at line 184 of file ilEventDetectorTest.php.

185  {
186  $this->expectException(ilWorkflowObjectStateException::class);
187 
188  // Arrange
189  $detector = new ilEventDetector($this->node);
190  $expected = '1234';
191 
192  // Act
193  $actual = $detector->getDbId();
194 
195  // Assert
196  $this->assertEquals($expected, $actual);
197  }
PhpIncludeInspection

◆ testHasDbIdSet()

ilEventDetectorTest::testHasDbIdSet ( )

Definition at line 199 of file ilEventDetectorTest.php.

200  {
201  // Arrange
202  $detector = new ilEventDetector($this->node);
203  $expected = '1234';
204 
205  // Act
206  $detector->setDbId($expected);
207  $actual = $detector->hasDbId();
208 
209  // Assert
210  $this->assertTrue($actual);
211  }
PhpIncludeInspection

◆ testHasDbIdUnset()

ilEventDetectorTest::testHasDbIdUnset ( )

Definition at line 213 of file ilEventDetectorTest.php.

214  {
215  // Arrange
216  $detector = new ilEventDetector($this->node);
217 
218  // Act
219  $actual = $detector->hasDbId();
220 
221  // Assert
222  $this->assertFalse($actual);
223  }
PhpIncludeInspection

◆ testIsListeningWithoutTimeFrame()

ilEventDetectorTest::testIsListeningWithoutTimeFrame ( )

Definition at line 120 of file ilEventDetectorTest.php.

121  {
122  // Arrange
123  $detector = new ilEventDetector($this->node);
124 
125  // Act
126  $actual = $detector->isListening();
127 
128  // Assert
129  $this->assertTrue($actual, 'Detector should be listening.');
130  }
PhpIncludeInspection

◆ testIsListeningWithPastTimeFrame()

ilEventDetectorTest::testIsListeningWithPastTimeFrame ( )

Definition at line 75 of file ilEventDetectorTest.php.

76  {
77  // Arrange
78  $detector = new ilEventDetector($this->node);
79  $timer_start = ilWorkflowUtils::time() - 5 * 60; # -5 Minutes from now.
80  $timer_end = ilWorkflowUtils::time() - 1 * 60; # -1 Minute from now.
81  $detector->setListeningTimeframe($timer_start, $timer_end);
82 
83  // Act
84  $actual = $detector->isListening();
85 
86  // Assert
87  $this->assertFalse($actual, 'Detector should not be listening.');
88  }
PhpIncludeInspection

◆ testIsListeningWithTimeFrame()

ilEventDetectorTest::testIsListeningWithTimeFrame ( )

Definition at line 60 of file ilEventDetectorTest.php.

61  {
62  // Arrange
63  $detector = new ilEventDetector($this->node);
64  $timer_start = ilWorkflowUtils::time() + 5 * 60; # +5 Minutes from here.
65  $timer_end = 0;
66  $detector->setListeningTimeframe($timer_start, $timer_end);
67 
68  // Act
69  $actual = $detector->isListening();
70 
71  // Assert
72  $this->assertFalse($actual, 'Detector should not be listening.');
73  }
PhpIncludeInspection

◆ testIsListeningWithWildcardBeginningTimeFrame()

ilEventDetectorTest::testIsListeningWithWildcardBeginningTimeFrame ( )

Definition at line 105 of file ilEventDetectorTest.php.

106  {
107  // Arrange
108  $detector = new ilEventDetector($this->node);
109  $timer_start = 0; # Wildcard.
110  $timer_end = ilWorkflowUtils::time() + 5 * 60; # +5 Minutes from now.
111  $detector->setListeningTimeframe($timer_start, $timer_end);
112 
113  // Act
114  $actual = $detector->isListening();
115 
116  // Assert
117  $this->assertTrue($actual, 'Detector should not be listening.');
118  }
PhpIncludeInspection

◆ testIsListeningWithWildcardEndingTimeFrame()

ilEventDetectorTest::testIsListeningWithWildcardEndingTimeFrame ( )

Definition at line 90 of file ilEventDetectorTest.php.

91  {
92  // Arrange
93  $detector = new ilEventDetector($this->node);
94  $timer_start = ilWorkflowUtils::time() - 5 * 60; # -5 Minutes from now.
95  $timer_end = 0; # Wildcard.
96  $detector->setListeningTimeframe($timer_start, $timer_end);
97 
98  // Act
99  $actual = $detector->isListening();
100 
101  // Assert
102  $this->assertTrue($actual, 'Detector should not be listening.');
103  }
PhpIncludeInspection

◆ testSetGetDbId()

ilEventDetectorTest::testSetGetDbId ( )

Definition at line 167 of file ilEventDetectorTest.php.

168  {
169  // Arrange
170  $detector = new ilEventDetector($this->node);
171  $expected = '1234';
172 
173  // Act
174  $detector->setDbId($expected);
175  $actual = $detector->getDbId();
176 
177  // Assert
178  $this->assertEquals($expected, $actual);
179  }
PhpIncludeInspection

◆ testSetGetEvent()

ilEventDetectorTest::testSetGetEvent ( )

Definition at line 225 of file ilEventDetectorTest.php.

226  {
227  // Arrange INC
228  $detector = new ilEventDetector($this->node);
229  $exp_type = 'time_passed';
230  $exp_content = 'time_passed';
231 
232  // Act
233  $detector->setEvent($exp_type, $exp_content);
234 
235  // Assert
236  $event = $detector->getEvent();
237  $act_type = $event['type'];
238  $act_content = $event['content'];
239  $this->assertEquals($exp_type . $exp_content, $act_type . $act_content);
240  }
PhpIncludeInspection

◆ testSetGetEventContext()

ilEventDetectorTest::testSetGetEventContext ( )

Definition at line 259 of file ilEventDetectorTest.php.

260  {
261  // Arrange INC
262  $detector = new ilEventDetector($this->node);
263  $exp_type = 'none';
264  $exp_id = '0';
265 
266  // Act
267  $detector->setEventContext($exp_type, $exp_id);
268 
269  // Assert
270  $event = $detector->getEventContext();
271  $act_type = $event['type'];
272  $act_id = $event['identifier'];
273  $this->assertEquals($exp_type . $exp_id, $act_type . $act_id);
274  }
PhpIncludeInspection

◆ testSetGetEventSubject()

ilEventDetectorTest::testSetGetEventSubject ( )

Definition at line 242 of file ilEventDetectorTest.php.

243  {
244  // Arrange INC
245  $detector = new ilEventDetector($this->node);
246  $exp_type = 'none';
247  $exp_id = '0';
248 
249  // Act
250  $detector->setEventSubject($exp_type, $exp_id);
251 
252  // Assert
253  $event = $detector->getEventSubject();
254  $act_type = $event['type'];
255  $act_id = $event['identifier'];
256  $this->assertEquals($exp_type . $exp_id, $act_type . $act_id);
257  }
PhpIncludeInspection

◆ testSetGetIllegalListeningTimeframe()

ilEventDetectorTest::testSetGetIllegalListeningTimeframe ( )

Definition at line 150 of file ilEventDetectorTest.php.

151  {
152  $this->expectException(ilWorkflowInvalidArgumentException::class);
153 
154  // Arrange
155  $detector = new ilEventDetector($this->node);
156  $exp_start = 4712; # +5 Minutes from here.
157  $exp_end = 4711;
158 
159  // Act
160  $detector->setListeningTimeframe($exp_start, $exp_end);
161  $act = $detector->getListeningTimeframe();
162 
163  // Assert
164  $this->assertEquals($exp_start . $exp_end, $act['listening_start'] . $act['listening_end']);
165  }
PhpIncludeInspection

◆ testSetGetListeningTimeframe()

ilEventDetectorTest::testSetGetListeningTimeframe ( )

Definition at line 132 of file ilEventDetectorTest.php.

133  {
134  // Arrange
135  $detector = new ilEventDetector($this->node);
136  $exp_start = 4711;
137  $exp_end = 4712;
138 
139  // Act
140  $detector->setListeningTimeframe($exp_start, $exp_end);
141  $act = $detector->getListeningTimeframe();
142 
143  // Assert
144  $this->assertEquals($exp_start . $exp_end, $act['listening_start'] . $act['listening_end']);
145  }
PhpIncludeInspection

◆ testTriggerInvalidContent()

ilEventDetectorTest::testTriggerInvalidContent ( )

Definition at line 349 of file ilEventDetectorTest.php.

350  {
351  // Arrange
352  $detector = new ilEventDetector($this->node);
353  $evt_type = 'testEvent';
354  $evt_content = 'content';
355  $detector->setEvent($evt_type, $evt_content);
356  $subj_type = 'usr';
357  $subj_id = 6;
358  $detector->setEventSubject($subj_type, $subj_id);
359  $ctx_type = 'crs';
360  $ctx_id = 48;
361  $detector->setEventContext($ctx_type, $ctx_id);
362  $params = array(
363  $evt_type, $evt_content . 'INVALIDATE',
364  $subj_type, $subj_id,
365  $ctx_type, $ctx_id
366  );
367 
368  // Act
369  $detector->trigger($params);
370 
371  // Assert
372  $actual = $detector->getDetectorState();
373  $this->assertFalse($actual);
374  }
PhpIncludeInspection

◆ testTriggerInvalidContextId()

ilEventDetectorTest::testTriggerInvalidContextId ( )

Definition at line 484 of file ilEventDetectorTest.php.

485  {
486  // Arrange
487  $detector = new ilEventDetector($this->node);
488  $evt_type = 'testEvent';
489  $evt_content = 'content';
490  $detector->setEvent($evt_type, $evt_content);
491  $subj_type = 'usr';
492  $subj_id = 6;
493  $detector->setEventSubject($subj_type, $subj_id);
494  $ctx_type = 'crs';
495  $ctx_id = 48;
496  $detector->setEventContext($ctx_type, $ctx_id);
497  $params = array(
498  $evt_type, $evt_content,
499  $subj_type, $subj_id,
500  $ctx_type, $ctx_id . 'INVALIDATE'
501  );
502 
503  // Act
504  $detector->trigger($params);
505 
506  // Assert
507  $actual = $detector->getDetectorState();
508  $this->assertFalse($actual);
509  }
PhpIncludeInspection

◆ testTriggerInvalidContextType()

ilEventDetectorTest::testTriggerInvalidContextType ( )

Definition at line 457 of file ilEventDetectorTest.php.

458  {
459  // Arrange
460  $detector = new ilEventDetector($this->node);
461  $evt_type = 'testEvent';
462  $evt_content = 'content';
463  $detector->setEvent($evt_type, $evt_content);
464  $subj_type = 'usr';
465  $subj_id = 6;
466  $detector->setEventSubject($subj_type, $subj_id);
467  $ctx_type = 'crs';
468  $ctx_id = 48;
469  $detector->setEventContext($ctx_type, $ctx_id);
470  $params = array(
471  $evt_type, $evt_content,
472  $subj_type, $subj_id,
473  $ctx_type . 'INVALIDATE', $ctx_id
474  );
475 
476  // Act
477  $detector->trigger($params);
478 
479  // Assert
480  $actual = $detector->getDetectorState();
481  $this->assertFalse($actual);
482  }
PhpIncludeInspection

◆ testTriggerInvalidSubjectId()

ilEventDetectorTest::testTriggerInvalidSubjectId ( )

Definition at line 430 of file ilEventDetectorTest.php.

431  {
432  // Arrange
433  $detector = new ilEventDetector($this->node);
434  $evt_type = 'testEvent';
435  $evt_content = 'content';
436  $detector->setEvent($evt_type, $evt_content);
437  $subj_type = 'usr';
438  $subj_id = 6;
439  $detector->setEventSubject($subj_type, $subj_id);
440  $ctx_type = 'crs';
441  $ctx_id = 48;
442  $detector->setEventContext($ctx_type, $ctx_id);
443  $params = array(
444  $evt_type, $evt_content,
445  $subj_type, $subj_id . 'INVALIDATE',
446  $ctx_type, $ctx_id
447  );
448 
449  // Act
450  $detector->trigger($params);
451 
452  // Assert
453  $actual = $detector->getDetectorState();
454  $this->assertFalse($actual);
455  }
PhpIncludeInspection

◆ testTriggerInvalidSubjectType()

ilEventDetectorTest::testTriggerInvalidSubjectType ( )

Definition at line 403 of file ilEventDetectorTest.php.

404  {
405  // Arrange
406  $detector = new ilEventDetector($this->node);
407  $evt_type = 'testEvent';
408  $evt_content = 'content';
409  $detector->setEvent($evt_type, $evt_content);
410  $subj_type = 'usr';
411  $subj_id = 6;
412  $detector->setEventSubject($subj_type, $subj_id);
413  $ctx_type = 'crs';
414  $ctx_id = 48;
415  $detector->setEventContext($ctx_type, $ctx_id);
416  $params = array(
417  $evt_type, $evt_content,
418  $subj_type . 'INVALIDATE', $subj_id,
419  $ctx_type, $ctx_id
420  );
421 
422  // Act
423  $detector->trigger($params);
424 
425  // Assert
426  $actual = $detector->getDetectorState();
427  $this->assertFalse($actual);
428  }
PhpIncludeInspection

◆ testTriggerInvalidType()

ilEventDetectorTest::testTriggerInvalidType ( )

Definition at line 376 of file ilEventDetectorTest.php.

377  {
378  // Arrange
379  $detector = new ilEventDetector($this->node);
380  $evt_type = 'testEvent';
381  $evt_content = 'content';
382  $detector->setEvent($evt_type, $evt_content);
383  $subj_type = 'usr';
384  $subj_id = 6;
385  $detector->setEventSubject($subj_type, $subj_id);
386  $ctx_type = 'crs';
387  $ctx_id = 48;
388  $detector->setEventContext($ctx_type, $ctx_id);
389  $params = array(
390  $evt_type . 'INVALIDATE', $evt_content,
391  $subj_type, $subj_id,
392  $ctx_type, $ctx_id
393  );
394 
395  // Act
396  $detector->trigger($params);
397 
398  // Assert
399  $actual = $detector->getDetectorState();
400  $this->assertFalse($actual);
401  }
PhpIncludeInspection

◆ testTriggerValid()

ilEventDetectorTest::testTriggerValid ( )

Definition at line 292 of file ilEventDetectorTest.php.

293  {
294  // Arrange
295  $detector = new ilEventDetector($this->node);
296  $evt_type = 'testEvent';
297  $evt_content = 'content';
298  $detector->setEvent($evt_type, $evt_content);
299  $subj_type = 'usr';
300  $subj_id = 6;
301  $detector->setEventSubject($subj_type, $subj_id);
302  $ctx_type = 'crs';
303  $ctx_id = 48;
304  $detector->setEventContext($ctx_type, $ctx_id);
305  $params = array(
306  $evt_type, $evt_content,
307  $subj_type, $subj_id,
308  $ctx_type, $ctx_id
309  );
310 
311  // Act
312  $detector->trigger($params);
313 
314  // Assert
315  $actual = $detector->getDetectorState();
316  $this->assertTrue($actual);
317  }
PhpIncludeInspection

◆ testTriggerValidTwice()

ilEventDetectorTest::testTriggerValidTwice ( )

Definition at line 319 of file ilEventDetectorTest.php.

320  {
321  // Arrange
322  $detector = new ilEventDetector($this->node);
323  $evt_type = 'testEvent';
324  $evt_content = 'content';
325  $detector->setEvent($evt_type, $evt_content);
326  $subj_type = 'usr';
327  $subj_id = 6;
328  $detector->setEventSubject($subj_type, $subj_id);
329  $ctx_type = 'crs';
330  $ctx_id = 48;
331  $detector->setEventContext($ctx_type, $ctx_id);
332  $params = array(
333  $evt_type, $evt_content,
334  $subj_type, $subj_id,
335  $ctx_type, $ctx_id
336  );
337 
338  // Act
339  $this->assertTrue($detector->trigger($params), 'First trigger should receive a true state.');
340  $this->assertFalse($detector->trigger($params), 'Second trigger should receive a false state.');
341 
342  // Assert
343  $actual = $detector->getDetectorState();
344  $this->assertTrue($actual, 'After satisfaction of the trigger, detectorstate should be true.');
345  }
PhpIncludeInspection

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