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);
 
  223        $this->markTestIncomplete(
 
  224            '$ilDB throws notices during test.' 
  229        require_once 
'./Services/Database/classes/class.ilDBMySQL.php';
 
  230        $ilDB_mock = $this->createMock(
'ilDBMySQL', array(
'nextID',
'quote',
'insert'), array(), 
'', 
false);
 
  232        $ilDB_mock->expects($this->once())->method(
'nextID')->with($this->equalTo(
'wfe_det_listening'))->will($this->returnValue(234));
 
  233        $ilDB_mock->expects($this->any())->method(
'quote')->will($this->returnArgument(0));
 
  234        $ilDB_mock->expects($this->any())->method(
'insert')->with(
 
  237                'detector_id'           => array(
'integer', 234),
 
  238                'workflow_id'           => array(
'integer', 
null),
 
  239                'type'                          => array(
'text', 
'' ),
 
  240                'content'                       => array(
'text', 
''),
 
  241                'subject_type'          => array(
'text', 
''),
 
  242                'subject_id'            => array(
'integer', 
''),
 
  243                'context_type'          => array(
'text', 
''),
 
  244                'context_id'            => array(
'integer', 
''),
 
  245                'listening_start'       => array(
'integer', 
'0'),
 
  246                'listening_end'         => array(
'integer', 
'0')
 
  248        )->will($this->returnValue(
true));
 
  251        $stashed_real_object = @
$GLOBALS[
'ilDB'];
 
  255        $detector->writeDetectorToDb();
 
  256        $actual = $detector->hasDbId();
 
  259        $this->assertTrue($actual);
 
  261        $GLOBALS[
'ilDB'] = $stashed_real_object;
 
  266        $this->markTestIncomplete(
 
  267            '$ilDB throws notices during test.' 
  272        require_once 
'./Services/Database/classes/class.ilDBMySQL.php';
 
  273        $ilDB_mock = $this->createMock(
'ilDBMySQL', array(
'quote',
'manipulate'), array(), 
'', 
false);
 
  275        $ilDB_mock->expects($this->any())->method(
'quote')->will($this->returnValue(234));
 
  276        $ilDB_mock->expects($this->any())->method(
'manipulate')->with(
 
  278                                FROM wfe_det_listening 
  279                                WHERE detector_id = 234' 
  280        )->will($this->returnValue(
true));
 
  282        $stashed_real_object = @
$GLOBALS[
'ilDB'];
 
  286        $detector->setDbId(234);
 
  287        $detector->deleteDetectorFromDb();
 
  288        $actual = $detector->hasDbId();
 
  291        $this->assertFalse($actual);
 
  292        $GLOBALS[
'ilDB'] = $stashed_real_object;
 
  297        $this->markTestIncomplete(
 
  298            '$ilDB throws notices during test.' 
  303        require_once 
'./Services/Database/classes/class.ilDBMySQL.php';
 
  304        $ilDB_mock = $this->createMock(
'ilDBMySQL', array(
'nextID',
'quote',
'insert'), array(), 
'', 
false);
 
  306        $ilDB_mock->expects($this->once())->method(
'nextID')->with($this->equalTo(
'wfe_det_listening'))->will($this->returnValue(234));
 
  307        $ilDB_mock->expects($this->any())->method(
'quote')->will($this->returnArgument(0));
 
  308        $ilDB_mock->expects($this->any())->method(
'insert')->with(
 
  311                'detector_id'           => array(
'integer', 234),
 
  312                'workflow_id'           => array(
'integer', 
null),
 
  313                'type'                          => array(
'text', 
'' ),
 
  314                'content'                       => array(
'text', 
''),
 
  315                'subject_type'          => array(
'text', 
''),
 
  316                'subject_id'            => array(
'integer', 
''),
 
  317                'context_type'          => array(
'text', 
''),
 
  318                'context_id'            => array(
'integer', 
''),
 
  319                'listening_start'       => array(
'integer', 0),
 
  320                'listening_end'         => array(
'integer', 0)
 
  322        )->will($this->returnValue(
true));
 
  324        $stashed_real_object = @
$GLOBALS[
'ilDB'];
 
  328        $detector->onActivate();
 
  329        $actual = $detector->hasDbId();
 
  332        $this->assertTrue($actual);
 
  333        $this->assertEquals(234, $detector->getDbId());
 
  334        $GLOBALS[
'ilDB'] = $stashed_real_object;
 
  339        $this->markTestIncomplete(
 
  340            '$ilDB throws notices during test.' 
  346        require_once 
'./Services/Database/classes/class.ilDBMySQL.php';
 
  347        $ilDB_mock = $this->createMock(
'ilDBMySQL', array(
'quote',
'manipulate'), array(), 
'', 
false);
 
  349        $ilDB_mock->expects($this->any())->method(
'quote')->will($this->returnValue(234));
 
  350        $ilDB_mock->expects($this->any())->method(
'manipulate')->with(
 
  352                                FROM wfe_det_listening 
  353                                WHERE detector_id = 234' 
  354        )->will($this->returnValue(
true));
 
  356        $stashed_real_object = @
$GLOBALS[
'ilDB'];
 
  360        $detector->setDbId(234);
 
  361        $detector->onDeactivate();
 
  362        $actual = $detector->hasDbId();
 
  365        $this->assertFalse($actual);
 
  367        $GLOBALS[
'ilDB'] = $stashed_real_object;
 
  374        $exp_type = 
'time_passed';
 
  375        $exp_content = 
'time_passed';
 
  378        $detector->setEvent($exp_type, $exp_content);
 
  381        $event = $detector->getEvent();
 
  382        $act_type = $event[
'type'];
 
  383        $act_content = $event[
'content'];
 
  384        $this->assertEquals($exp_type . $exp_content, $act_type . $act_content);
 
  395        $detector->setEventSubject($exp_type, $exp_id);
 
  398        $event = $detector->getEventSubject();
 
  399        $act_type = $event[
'type'];
 
  400        $act_id = $event[
'identifier'];
 
  401        $this->assertEquals($exp_type . $exp_id, $act_type . $act_id);
 
  412        $detector->setEventContext($exp_type, $exp_id);
 
  415        $event = $detector->getEventContext();
 
  416        $act_type = $event[
'type'];
 
  417        $act_id = $event[
'identifier'];
 
  418        $this->assertEquals($exp_type . $exp_id, $act_type . $act_id);
 
  427        $actual = $detector->getContext();
 
  430        if ($actual === $this->node) {
 
  431            $this->assertEquals($actual, $this->node);
 
  433            $this->assertTrue(
false, 
'Context not identical.');
 
  441        $evt_type        = 
'testEvent';
 
  442        $evt_content = 
'content';
 
  443        $detector->setEvent($evt_type, $evt_content);
 
  446        $detector->setEventSubject($subj_type, $subj_id);
 
  449        $detector->setEventContext($ctx_type, $ctx_id);
 
  451            $evt_type, $evt_content,
 
  452            $subj_type, $subj_id,
 
  460        $actual = $detector->getDetectorState();
 
  461        $this->assertTrue($actual);
 
  468        $evt_type        = 
'testEvent';
 
  469        $evt_content = 
'content';
 
  470        $detector->setEvent($evt_type, $evt_content);
 
  473        $detector->setEventSubject($subj_type, $subj_id);
 
  476        $detector->setEventContext($ctx_type, $ctx_id);
 
  478            $evt_type, $evt_content,
 
  479            $subj_type, $subj_id,
 
  484        $this->assertTrue($detector->trigger(
$params), 
'First trigger should receive a true state.');
 
  485        $this->assertFalse($detector->trigger(
$params), 
'Second trigger should receive a false state.');
 
  488        $actual = $detector->getDetectorState();
 
  489        $this->assertTrue($actual, 
'After satisfaction of the trigger, detectorstate should be true.');
 
  498        $evt_type        = 
'testEvent';
 
  499        $evt_content = 
'content';
 
  500        $detector->setEvent($evt_type, $evt_content);
 
  503        $detector->setEventSubject($subj_type, $subj_id);
 
  506        $detector->setEventContext($ctx_type, $ctx_id);
 
  508            $evt_type, $evt_content . 
'INVALIDATE',
 
  509            $subj_type, $subj_id,
 
  517        $actual = $detector->getDetectorState();
 
  518        $this->assertFalse($actual);
 
  525        $evt_type        = 
'testEvent';
 
  526        $evt_content = 
'content';
 
  527        $detector->setEvent($evt_type, $evt_content);
 
  530        $detector->setEventSubject($subj_type, $subj_id);
 
  533        $detector->setEventContext($ctx_type, $ctx_id);
 
  535            $evt_type . 
'INVALIDATE', $evt_content,
 
  536            $subj_type, $subj_id,
 
  544        $actual = $detector->getDetectorState();
 
  545        $this->assertFalse($actual);
 
  552        $evt_type        = 
'testEvent';
 
  553        $evt_content = 
'content';
 
  554        $detector->setEvent($evt_type, $evt_content);
 
  557        $detector->setEventSubject($subj_type, $subj_id);
 
  560        $detector->setEventContext($ctx_type, $ctx_id);
 
  562            $evt_type, $evt_content,
 
  563            $subj_type . 
'INVALIDATE', $subj_id,
 
  571        $actual = $detector->getDetectorState();
 
  572        $this->assertFalse($actual);
 
  579        $evt_type        = 
'testEvent';
 
  580        $evt_content = 
'content';
 
  581        $detector->setEvent($evt_type, $evt_content);
 
  584        $detector->setEventSubject($subj_type, $subj_id);
 
  587        $detector->setEventContext($ctx_type, $ctx_id);
 
  589            $evt_type, $evt_content,
 
  590            $subj_type, $subj_id . 
'INVALIDATE',
 
  598        $actual = $detector->getDetectorState();
 
  599        $this->assertFalse($actual);
 
  606        $evt_type        = 
'testEvent';
 
  607        $evt_content = 
'content';
 
  608        $detector->setEvent($evt_type, $evt_content);
 
  611        $detector->setEventSubject($subj_type, $subj_id);
 
  614        $detector->setEventContext($ctx_type, $ctx_id);
 
  616            $evt_type, $evt_content,
 
  617            $subj_type, $subj_id,
 
  618            $ctx_type . 
'INVALIDATE', $ctx_id
 
  625        $actual = $detector->getDetectorState();
 
  626        $this->assertFalse($actual);
 
  633        $evt_type        = 
'testEvent';
 
  634        $evt_content = 
'content';
 
  635        $detector->setEvent($evt_type, $evt_content);
 
  638        $detector->setEventSubject($subj_type, $subj_id);
 
  641        $detector->setEventContext($ctx_type, $ctx_id);
 
  643            $evt_type, $evt_content,
 
  644            $subj_type, $subj_id,
 
  645            $ctx_type, $ctx_id . 
'INVALIDATE' 
  652        $actual = $detector->getDetectorState();
 
  653        $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()
testDeleteDetectorFromDb()
testGetNonExistingDbId()
@expectedException ilWorkflowObjectStateException
testConstructorValidContext()
testTriggerInvalidSubjectType()
testIsListeningWithWildcardEndingTimeFrame()
testIsListeningWithWildcardBeginningTimeFrame()
testIsListeningWithTimeFrame()
testTriggerInvalidSubjectId()
testIsListeningWithoutTimeFrame()
testTriggerInvalidContextId()
testIsListeningWithPastTimeFrame()
testSetGetListeningTimeframe()
testSetGetIllegalListeningTimeframe()
@expectedException ilWorkflowInvalidArgumentException
testTriggerInvalidContextType()
@noinspection PhpIncludeInspection
$GLOBALS['loaded']
Global hash that tracks already loaded includes.