ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 ()
 ilWorkflowInvalidArgumentException More...
 
 testSetGetDbId ()
 
 testGetNonExistingDbId ()
 ilWorkflowObjectStateException More...
 
 testHasDbIdSet ()
 
 testHasDbIdUnset ()
 
 testSetGetEvent ()
 
 testSetGetEventSubject ()
 
 testSetGetEventContext ()
 
 testGetContext ()
 
 testTriggerValid ()
 
 testTriggerValidTwice ()
 
 testTriggerInvalidContent ()
 
 testTriggerInvalidType ()
 
 testTriggerInvalidSubjectType ()
 
 testTriggerInvalidSubjectId ()
 
 testTriggerInvalidContextType ()
 
 testTriggerInvalidContextId ()
 

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.

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.ilEventDetector.php';
36  }
PhpIncludeInspection
PhpIncludeInspection

◆ tearDown()

ilEventDetectorTest::tearDown ( )

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

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 272 of file ilEventDetectorTest.php.

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

◆ testGetNonExistingDbId()

ilEventDetectorTest::testGetNonExistingDbId ( )

ilWorkflowObjectStateException

Definition at line 182 of file ilEventDetectorTest.php.

183  {
184  // Arrange
185  $detector = new ilEventDetector($this->node);
186  $expected = '1234';
187 
188  // Act
189  $actual = $detector->getDbId();
190 
191  // Assert
192  $this->assertEquals($expected, $actual);
193  }
PhpIncludeInspection

◆ testHasDbIdSet()

ilEventDetectorTest::testHasDbIdSet ( )

Definition at line 195 of file ilEventDetectorTest.php.

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

◆ testHasDbIdUnset()

ilEventDetectorTest::testHasDbIdUnset ( )

Definition at line 209 of file ilEventDetectorTest.php.

210  {
211  // Arrange
212  $detector = new ilEventDetector($this->node);
213 
214  // Act
215  $actual = $detector->hasDbId();
216 
217  // Assert
218  $this->assertFalse($actual);
219  }
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 165 of file ilEventDetectorTest.php.

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

◆ testSetGetEvent()

ilEventDetectorTest::testSetGetEvent ( )

Definition at line 221 of file ilEventDetectorTest.php.

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

◆ testSetGetEventContext()

ilEventDetectorTest::testSetGetEventContext ( )

Definition at line 255 of file ilEventDetectorTest.php.

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

◆ testSetGetEventSubject()

ilEventDetectorTest::testSetGetEventSubject ( )

Definition at line 238 of file ilEventDetectorTest.php.

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

◆ testSetGetIllegalListeningTimeframe()

ilEventDetectorTest::testSetGetIllegalListeningTimeframe ( )

ilWorkflowInvalidArgumentException

Definition at line 150 of file ilEventDetectorTest.php.

151  {
152  // Arrange
153  $detector = new ilEventDetector($this->node);
154  $exp_start = 4712; # +5 Minutes from here.
155  $exp_end = 4711;
156 
157  // Act
158  $detector->setListeningTimeframe($exp_start, $exp_end);
159  $act = $detector->getListeningTimeframe();
160 
161  // Assert
162  $this->assertEquals($exp_start . $exp_end, $act['listening_start'] . $act['listening_end']);
163  }
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 345 of file ilEventDetectorTest.php.

References PHPMailer\PHPMailer\$params.

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

◆ testTriggerInvalidContextId()

ilEventDetectorTest::testTriggerInvalidContextId ( )

Definition at line 480 of file ilEventDetectorTest.php.

References PHPMailer\PHPMailer\$params.

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

◆ testTriggerInvalidContextType()

ilEventDetectorTest::testTriggerInvalidContextType ( )

Definition at line 453 of file ilEventDetectorTest.php.

References PHPMailer\PHPMailer\$params.

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

◆ testTriggerInvalidSubjectId()

ilEventDetectorTest::testTriggerInvalidSubjectId ( )

Definition at line 426 of file ilEventDetectorTest.php.

References PHPMailer\PHPMailer\$params.

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

◆ testTriggerInvalidSubjectType()

ilEventDetectorTest::testTriggerInvalidSubjectType ( )

Definition at line 399 of file ilEventDetectorTest.php.

References PHPMailer\PHPMailer\$params.

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

◆ testTriggerInvalidType()

ilEventDetectorTest::testTriggerInvalidType ( )

Definition at line 372 of file ilEventDetectorTest.php.

References PHPMailer\PHPMailer\$params.

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

◆ testTriggerValid()

ilEventDetectorTest::testTriggerValid ( )

Definition at line 288 of file ilEventDetectorTest.php.

References PHPMailer\PHPMailer\$params.

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

◆ testTriggerValidTwice()

ilEventDetectorTest::testTriggerValidTwice ( )

Definition at line 315 of file ilEventDetectorTest.php.

References PHPMailer\PHPMailer\$params.

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

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