19        include_once(
"./Services/PHPUnit/classes/class.ilUnitUtil.php");
 
   22        require_once 
'./Services/WorkflowEngine/classes/utils/class.ilWorkflowUtils.php';
 
   25        require_once 
'./Services/WorkflowEngine/classes/workflows/class.ilEmptyWorkflow.php';
 
   29        require_once 
'./Services/WorkflowEngine/classes/nodes/class.ilBasicNode.php';
 
   33        $this->workflow->addNode($this->node);
 
   35        require_once 
'./Services/WorkflowEngine/classes/detectors/class.ilEventDetector.php';
 
   43            $ilSetting->delete(
'IL_PHPUNIT_TEST_MICROTIME');
 
   56            'Construction failed with valid context passed to constructor.' 
   64        $timer_start = ilWorkflowUtils::time() + 5 * 60; # +5 Minutes from here.
 
   66        $detector->setListeningTimeframe($timer_start, $timer_end);
 
   69        $actual = $detector->isListening();
 
   72        $this->assertFalse($actual, 
'Detector should not be listening.');
 
   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);
 
   84        $actual = $detector->isListening();
 
   87        $this->assertFalse($actual, 
'Detector should not be listening.');
 
   94        $timer_start = ilWorkflowUtils::time() - 5 * 60; # -5 Minutes from now.
 
   95        $timer_end = 0; # Wildcard.
 
   96        $detector->setListeningTimeframe($timer_start, $timer_end);
 
   99        $actual = $detector->isListening();
 
  102        $this->assertTrue($actual, 
'Detector should not be listening.');
 
  109        $timer_start = 0; # Wildcard.
 
  110        $timer_end = ilWorkflowUtils::time() + 5 * 60; # +5 Minutes from now.
 
  111        $detector->setListeningTimeframe($timer_start, $timer_end);
 
  114        $actual = $detector->isListening();
 
  117        $this->assertTrue($actual, 
'Detector should not be listening.');
 
  126        $actual = $detector->isListening();
 
  129        $this->assertTrue($actual, 
'Detector should be listening.');
 
  140        $detector->setListeningTimeframe($exp_start, $exp_end);
 
  141        $act = $detector->getListeningTimeframe();
 
  144        $this->assertEquals($exp_start . $exp_end, $act[
'listening_start'] . $act[
'listening_end']);
 
  154        $exp_start = 4712; # +5 Minutes from here.
 
  158        $detector->setListeningTimeframe($exp_start, $exp_end);
 
  159        $act = $detector->getListeningTimeframe();
 
  162        $this->assertEquals($exp_start . $exp_end, $act[
'listening_start'] . $act[
'listening_end']);
 
  172        $detector->setDbId($expected);
 
  173        $actual = $detector->getDbId();
 
  176        $this->assertEquals($expected, $actual);
 
  189        $actual = $detector->getDbId();
 
  192        $this->assertEquals($expected, $actual);
 
  202        $detector->setDbId($expected);
 
  203        $actual = $detector->hasDbId();
 
  206        $this->assertTrue($actual);
 
  215        $actual = $detector->hasDbId();
 
  218        $this->assertFalse($actual);
 
  225        $exp_type = 
'time_passed';
 
  226        $exp_content = 
'time_passed';
 
  229        $detector->setEvent($exp_type, $exp_content);
 
  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);
 
  246        $detector->setEventSubject($exp_type, $exp_id);
 
  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);
 
  263        $detector->setEventContext($exp_type, $exp_id);
 
  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);
 
  278        $actual = $detector->getContext();
 
  281        if ($actual === $this->node) {
 
  282            $this->assertEquals($actual, $this->node);
 
  284            $this->assertTrue(
false, 
'Context not identical.');
 
  292        $evt_type = 
'testEvent';
 
  293        $evt_content = 
'content';
 
  294        $detector->setEvent($evt_type, $evt_content);
 
  297        $detector->setEventSubject($subj_type, $subj_id);
 
  300        $detector->setEventContext($ctx_type, $ctx_id);
 
  302            $evt_type, $evt_content,
 
  303            $subj_type, $subj_id,
 
  311        $actual = $detector->getDetectorState();
 
  312        $this->assertTrue($actual);
 
  319        $evt_type = 
'testEvent';
 
  320        $evt_content = 
'content';
 
  321        $detector->setEvent($evt_type, $evt_content);
 
  324        $detector->setEventSubject($subj_type, $subj_id);
 
  327        $detector->setEventContext($ctx_type, $ctx_id);
 
  329            $evt_type, $evt_content,
 
  330            $subj_type, $subj_id,
 
  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.');
 
  339        $actual = $detector->getDetectorState();
 
  340        $this->assertTrue($actual, 
'After satisfaction of the trigger, detectorstate should be true.');
 
  349        $evt_type = 
'testEvent';
 
  350        $evt_content = 
'content';
 
  351        $detector->setEvent($evt_type, $evt_content);
 
  354        $detector->setEventSubject($subj_type, $subj_id);
 
  357        $detector->setEventContext($ctx_type, $ctx_id);
 
  359            $evt_type, $evt_content . 
'INVALIDATE',
 
  360            $subj_type, $subj_id,
 
  368        $actual = $detector->getDetectorState();
 
  369        $this->assertFalse($actual);
 
  376        $evt_type = 
'testEvent';
 
  377        $evt_content = 
'content';
 
  378        $detector->setEvent($evt_type, $evt_content);
 
  381        $detector->setEventSubject($subj_type, $subj_id);
 
  384        $detector->setEventContext($ctx_type, $ctx_id);
 
  386            $evt_type . 
'INVALIDATE', $evt_content,
 
  387            $subj_type, $subj_id,
 
  395        $actual = $detector->getDetectorState();
 
  396        $this->assertFalse($actual);
 
  403        $evt_type = 
'testEvent';
 
  404        $evt_content = 
'content';
 
  405        $detector->setEvent($evt_type, $evt_content);
 
  408        $detector->setEventSubject($subj_type, $subj_id);
 
  411        $detector->setEventContext($ctx_type, $ctx_id);
 
  413            $evt_type, $evt_content,
 
  414            $subj_type . 
'INVALIDATE', $subj_id,
 
  422        $actual = $detector->getDetectorState();
 
  423        $this->assertFalse($actual);
 
  430        $evt_type = 
'testEvent';
 
  431        $evt_content = 
'content';
 
  432        $detector->setEvent($evt_type, $evt_content);
 
  435        $detector->setEventSubject($subj_type, $subj_id);
 
  438        $detector->setEventContext($ctx_type, $ctx_id);
 
  440            $evt_type, $evt_content,
 
  441            $subj_type, $subj_id . 
'INVALIDATE',
 
  449        $actual = $detector->getDetectorState();
 
  450        $this->assertFalse($actual);
 
  457        $evt_type = 
'testEvent';
 
  458        $evt_content = 
'content';
 
  459        $detector->setEvent($evt_type, $evt_content);
 
  462        $detector->setEventSubject($subj_type, $subj_id);
 
  465        $detector->setEventContext($ctx_type, $ctx_id);
 
  467            $evt_type, $evt_content,
 
  468            $subj_type, $subj_id,
 
  469            $ctx_type . 
'INVALIDATE', $ctx_id
 
  476        $actual = $detector->getDetectorState();
 
  477        $this->assertFalse($actual);
 
  484        $evt_type = 
'testEvent';
 
  485        $evt_content = 
'content';
 
  486        $detector->setEvent($evt_type, $evt_content);
 
  489        $detector->setEventSubject($subj_type, $subj_id);
 
  492        $detector->setEventContext($ctx_type, $ctx_id);
 
  494            $evt_type, $evt_content,
 
  495            $subj_type, $subj_id,
 
  496            $ctx_type, $ctx_id . 
'INVALIDATE' 
  503        $actual = $detector->getDetectorState();
 
  504        $this->assertFalse($actual);
 
An exception for terminatinating execution or to throw for unit testing.
@noinspection PhpIncludeInspection
@noinspection PhpIncludeInspection
ilEventDetectorTest is part of the petri net based workflow engine.
testTriggerInvalidContent()
testGetNonExistingDbId()
@expectedException ilWorkflowObjectStateException
testConstructorValidContext()
testTriggerInvalidSubjectType()
testIsListeningWithWildcardEndingTimeFrame()
testIsListeningWithWildcardBeginningTimeFrame()
testIsListeningWithTimeFrame()
testTriggerInvalidSubjectId()
testIsListeningWithoutTimeFrame()
testTriggerInvalidContextId()
testIsListeningWithPastTimeFrame()
testSetGetListeningTimeframe()
testSetGetIllegalListeningTimeframe()
@expectedException ilWorkflowInvalidArgumentException
testTriggerInvalidContextType()
@noinspection PhpIncludeInspection