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';
 
   44                        $ilSetting->delete(
'IL_PHPUNIT_TEST_MICROTIME');
 
   57                        'Construction failed with valid context passed to constructor.' 
   65                $timer_start = ilWorkflowUtils::time() + 5*60; # +5 Minutes from here.
 
   67                $detector->setListeningTimeframe($timer_start, $timer_end);
 
   70                $actual = $detector->isListening();
 
   73                $this->assertFalse($actual, 
'Detector should not be listening.');
 
   80                $timer_start = ilWorkflowUtils::time() - 5*60; # -5 Minutes from now.
 
   81                $timer_end = ilWorkflowUtils::time() - 1*60; # -1 Minute from now.
 
   82                $detector->setListeningTimeframe($timer_start, $timer_end);
 
   85                $actual = $detector->isListening();
 
   88                $this->assertFalse($actual, 
'Detector should not be listening.');
 
   95                $timer_start = ilWorkflowUtils::time() - 5*60; # -5 Minutes from now.
 
   96                $timer_end = 0; # Wildcard.
 
   97                $detector->setListeningTimeframe($timer_start, $timer_end);
 
  100                $actual = $detector->isListening();
 
  103                $this->assertTrue($actual, 
'Detector should not be listening.');
 
  110                $timer_start = 0; # Wildcard.
 
  111                $timer_end = ilWorkflowUtils::time() + 5*60; # +5 Minutes from now.
 
  112                $detector->setListeningTimeframe($timer_start, $timer_end);
 
  115                $actual = $detector->isListening();
 
  118                $this->assertTrue($actual, 
'Detector should not be listening.');
 
  127                $actual = $detector->isListening();
 
  130                $this->assertTrue($actual, 
'Detector should be listening.');
 
  141                $detector->setListeningTimeframe($exp_start, $exp_end);
 
  142                $act = $detector->getListeningTimeframe();
 
  145                $this->assertEquals($exp_start.$exp_end, $act[
'listening_start'].$act[
'listening_end']);
 
  155                $exp_start = 4712; # +5 Minutes from here.
 
  159                $detector->setListeningTimeframe($exp_start, $exp_end);
 
  160                $act = $detector->getListeningTimeframe();
 
  163                $this->assertEquals($exp_start.$exp_end, $act[
'listening_start'].$act[
'listening_end']);
 
  173                $detector->setDbId($expected);
 
  174                $actual = $detector->getDbId();
 
  177                $this->assertEquals($expected, $actual);
 
  190                $actual = $detector->getDbId();
 
  193                $this->assertEquals($expected, $actual);
 
  203                $detector->setDbId($expected);
 
  204                $actual = $detector->hasDbId();
 
  207                $this->assertTrue($actual);
 
  216                $actual = $detector->hasDbId();
 
  219                $this->assertFalse($actual);
 
  224                $this->markTestIncomplete(
 
  225                                '$ilDB throws notices during test.' 
  230                require_once 
'./Services/Database/classes/class.ilDBMySQL.php';
 
  231                $ilDB_mock = $this->getMock(
'ilDBMySQL',array(
'nextID',
'quote',
'insert'),array(),
'', FALSE);
 
  233                $ilDB_mock->expects($this->once())->method(
'nextID')->with($this->equalTo(
'wfe_det_listening'))->will($this->returnValue(234));
 
  234                $ilDB_mock->expects($this->any())->method(
'quote')->will($this->returnArgument(0));
 
  235                $ilDB_mock->expects($this->any())->method(
'insert')->with(
 
  238                                'detector_id'           => array (
'integer', 234),
 
  239                                'workflow_id'           => array (
'integer', 
null),
 
  240                                'type'                          => array (
'text', 
'' ),
 
  241                                'content'                       => array (
'text', 
''),
 
  242                                'subject_type'          => array (
'text', 
''),
 
  243                                'subject_id'            => array (
'integer', 
''),
 
  244                                'context_type'          => array (
'text', 
''),
 
  245                                'context_id'            => array (
'integer', 
''),
 
  246                                'listening_start'       => array (
'integer', 
'0'),
 
  247                                'listening_end'         => array (
'integer', 
'0')
 
  249                )->will($this->returnValue(
true));
 
  252                $stashed_real_object = @
$GLOBALS[
'ilDB'];
 
  256                $detector->writeDetectorToDb();
 
  257                $actual = $detector->hasDbId();
 
  260                $this->assertTrue($actual);
 
  262                $GLOBALS[
'ilDB'] = $stashed_real_object;
 
  267                $this->markTestIncomplete(
 
  268                                '$ilDB throws notices during test.' 
  273                require_once 
'./Services/Database/classes/class.ilDBMySQL.php';
 
  274                $ilDB_mock = $this->getMock(
'ilDBMySQL',array(
'quote',
'manipulate'),array(),
'', FALSE);
 
  276                $ilDB_mock->expects($this->any())->method(
'quote')->will($this->returnValue(234));
 
  277                $ilDB_mock->expects($this->any())->method(
'manipulate')->with(
 
  279                                FROM wfe_det_listening 
  280                                WHERE detector_id = 234' 
  281                )->will($this->returnValue(
true));
 
  283                $stashed_real_object = @
$GLOBALS[
'ilDB'];
 
  287                $detector->setDbId(234);
 
  288                $detector->deleteDetectorFromDb();
 
  289                $actual = $detector->hasDbId();
 
  292                $this->assertFalse($actual);
 
  293                $GLOBALS[
'ilDB'] = $stashed_real_object;
 
  298                $this->markTestIncomplete(
 
  299                                '$ilDB throws notices during test.' 
  304                require_once 
'./Services/Database/classes/class.ilDBMySQL.php';
 
  305                $ilDB_mock = $this->getMock(
'ilDBMySQL',array(
'nextID',
'quote',
'insert'),array(),
'', FALSE);
 
  307                $ilDB_mock->expects($this->once())->method(
'nextID')->with($this->equalTo(
'wfe_det_listening'))->will($this->returnValue(234));
 
  308                $ilDB_mock->expects($this->any())->method(
'quote')->will($this->returnArgument(0));
 
  309                $ilDB_mock->expects($this->any())->method(
'insert')->with(
 
  312                                'detector_id'           => array (
'integer', 234),
 
  313                                'workflow_id'           => array (
'integer', 
null),
 
  314                                'type'                          => array (
'text', 
'' ),
 
  315                                'content'                       => array (
'text', 
''),
 
  316                                'subject_type'          => array (
'text', 
''),
 
  317                                'subject_id'            => array (
'integer', 
''),
 
  318                                'context_type'          => array (
'text', 
''),
 
  319                                'context_id'            => array (
'integer', 
''),
 
  320                                'listening_start'       => array (
'integer', 0),
 
  321                                'listening_end'         => array (
'integer', 0)
 
  323                )->will($this->returnValue(
true));
 
  325                $stashed_real_object = @
$GLOBALS[
'ilDB'];
 
  329                $detector->onActivate();
 
  330                $actual = $detector->hasDbId();
 
  333                $this->assertTrue($actual);
 
  334                $this->assertEquals(234, $detector->getDbId());
 
  335                $GLOBALS[
'ilDB'] = $stashed_real_object;
 
  340                $this->markTestIncomplete(
 
  341                                '$ilDB throws notices during test.' 
  347                require_once 
'./Services/Database/classes/class.ilDBMySQL.php';
 
  348                $ilDB_mock = $this->getMock(
'ilDBMySQL',array(
'quote',
'manipulate'),array(),
'', FALSE);
 
  350                $ilDB_mock->expects($this->any())->method(
'quote')->will($this->returnValue(234));
 
  351                $ilDB_mock->expects($this->any())->method(
'manipulate')->with(
 
  353                                FROM wfe_det_listening 
  354                                WHERE detector_id = 234' 
  355                )->will($this->returnValue(
true));
 
  357                $stashed_real_object = @
$GLOBALS[
'ilDB'];
 
  361                $detector->setDbId(234);
 
  362                $detector->onDeactivate();
 
  363                $actual = $detector->hasDbId();
 
  366                $this->assertFalse($actual);
 
  368                $GLOBALS[
'ilDB'] = $stashed_real_object;
 
  375                $exp_type = 
'time_passed';
 
  376                $exp_content = 
'time_passed';
 
  379                $detector->setEvent($exp_type, $exp_content);
 
  382                $event = $detector->getEvent();
 
  383                $act_type = $event[
'type'];
 
  384                $act_content = $event[
'content'];
 
  385                $this->assertEquals($exp_type.$exp_content, $act_type.$act_content);
 
  396                $detector->setEventSubject($exp_type, $exp_id);
 
  399                $event = $detector->getEventSubject();
 
  400                $act_type = $event[
'type'];
 
  401                $act_id = $event[
'identifier'];
 
  402                $this->assertEquals($exp_type.$exp_id, $act_type.$act_id);      
 
  413                $detector->setEventContext($exp_type, $exp_id);
 
  416                $event = $detector->getEventContext();
 
  417                $act_type = $event[
'type'];
 
  418                $act_id = $event[
'identifier'];
 
  419                $this->assertEquals($exp_type.$exp_id, $act_type.$act_id);      
 
  428                $actual = $detector->getContext();
 
  431                if ($actual === $this->node)
 
  433                        $this->assertEquals($actual, $this->node);
 
  435                        $this->assertTrue(
false, 
'Context not identical.');
 
  443                $evt_type        = 
'testEvent';
 
  444                $evt_content = 
'content';
 
  445                $detector->setEvent($evt_type, $evt_content);
 
  448                $detector->setEventSubject($subj_type, $subj_id);
 
  451                $detector->setEventContext($ctx_type, $ctx_id);
 
  453                        $evt_type, $evt_content,
 
  454                        $subj_type, $subj_id,
 
  462                $actual = $detector->getDetectorState();
 
  463                $this->assertTrue($actual);
 
  470                $evt_type        = 
'testEvent';
 
  471                $evt_content = 
'content';
 
  472                $detector->setEvent($evt_type, $evt_content);
 
  475                $detector->setEventSubject($subj_type, $subj_id);
 
  478                $detector->setEventContext($ctx_type, $ctx_id);
 
  480                        $evt_type, $evt_content,
 
  481                        $subj_type, $subj_id,
 
  486                $this->assertTrue($detector->trigger(
$params), 
'First trigger should receive a true state.');
 
  487                $this->assertFalse($detector->trigger(
$params), 
'Second trigger should receive a false state.');
 
  490                $actual = $detector->getDetectorState();
 
  491                $this->assertTrue($actual, 
'After satisfaction of the trigger, detectorstate should be true.');
 
  500                $evt_type        = 
'testEvent';
 
  501                $evt_content = 
'content';
 
  502                $detector->setEvent($evt_type, $evt_content);
 
  505                $detector->setEventSubject($subj_type, $subj_id);
 
  508                $detector->setEventContext($ctx_type, $ctx_id);
 
  510                        $evt_type, $evt_content.
'INVALIDATE',
 
  511                        $subj_type, $subj_id,
 
  519                $actual = $detector->getDetectorState();
 
  520                $this->assertFalse($actual);
 
  527                $evt_type        = 
'testEvent';
 
  528                $evt_content = 
'content';
 
  529                $detector->setEvent($evt_type, $evt_content);
 
  532                $detector->setEventSubject($subj_type, $subj_id);
 
  535                $detector->setEventContext($ctx_type, $ctx_id);
 
  537                        $evt_type.
'INVALIDATE', $evt_content,
 
  538                        $subj_type, $subj_id,
 
  546                $actual = $detector->getDetectorState();
 
  547                $this->assertFalse($actual);
 
  554                $evt_type        = 
'testEvent';
 
  555                $evt_content = 
'content';
 
  556                $detector->setEvent($evt_type, $evt_content);
 
  559                $detector->setEventSubject($subj_type, $subj_id);
 
  562                $detector->setEventContext($ctx_type, $ctx_id);
 
  564                        $evt_type, $evt_content,
 
  565                        $subj_type.
'INVALIDATE', $subj_id,
 
  573                $actual = $detector->getDetectorState();
 
  574                $this->assertFalse($actual);
 
  581                $evt_type        = 
'testEvent';
 
  582                $evt_content = 
'content';
 
  583                $detector->setEvent($evt_type, $evt_content);
 
  586                $detector->setEventSubject($subj_type, $subj_id);
 
  589                $detector->setEventContext($ctx_type, $ctx_id);
 
  591                        $evt_type, $evt_content,
 
  592                        $subj_type, $subj_id.
'INVALIDATE',
 
  600                $actual = $detector->getDetectorState();
 
  601                $this->assertFalse($actual);
 
  608                $evt_type        = 
'testEvent';
 
  609                $evt_content = 
'content';
 
  610                $detector->setEvent($evt_type, $evt_content);
 
  613                $detector->setEventSubject($subj_type, $subj_id);
 
  616                $detector->setEventContext($ctx_type, $ctx_id);
 
  618                        $evt_type, $evt_content,
 
  619                        $subj_type, $subj_id,
 
  620                        $ctx_type.
'INVALIDATE', $ctx_id
 
  627                $actual = $detector->getDetectorState();
 
  628                $this->assertFalse($actual);
 
  635                $evt_type        = 
'testEvent';
 
  636                $evt_content = 
'content';
 
  637                $detector->setEvent($evt_type, $evt_content);
 
  640                $detector->setEventSubject($subj_type, $subj_id);
 
  643                $detector->setEventContext($ctx_type, $ctx_id);
 
  645                        $evt_type, $evt_content,
 
  646                        $subj_type, $subj_id,
 
  647                        $ctx_type, $ctx_id.
'INVALIDATE' 
  654                $actual = $detector->getDetectorState();
 
  655                $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.