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.ilTimerDetector.php';
 
   43            $ilSetting->delete(
'IL_PHPUNIT_TEST_MICROTIME');
 
   56            'Construction failed with valid context passed to constructor.' 
   64        $expected = ilWorkflowUtils::time();
 
   67        $detector->setTimerStart($expected);
 
   68        $actual = $detector->getTimerStart();
 
   71        $this->assertEquals($actual, $expected);
 
   81        $detector->setTimerLimit($expected);
 
   82        $actual = $detector->getTimerLimit();
 
   85        $this->assertEquals($actual, $expected);
 
   92        $timer_start = ilWorkflowUtils::time(); # +5 Minutes from here.
 
   94        $detector->setTimerStart($timer_start);
 
   95        $detector->setTimerLimit($timer_limit);
 
   98        $detector->trigger(
null);
 
  101        $actual = $detector->getDetectorState();
 
  102        $this->assertFalse($actual, 
'Early trigger should not satisfy detector');
 
  109        $timer_start = ilWorkflowUtils::time(); # +5 Minutes from now.
 
  111        $detector->setTimerStart($timer_start);
 
  112        $detector->setTimerLimit($timer_limit);
 
  115        $detector->trigger(
null);
 
  118        $actual = $detector->getDetectorState();
 
  119        $this->assertTrue($actual, 
'Trigger should not satisfy detector');
 
  126        $timer_start = ilWorkflowUtils::time(); # +5 Minutes from now.
 
  128        $detector->setTimerStart($timer_start);
 
  129        $detector->setTimerLimit($timer_limit);
 
  132        $detector->trigger(
null);
 
  133        $actual = $detector->trigger(
null);
 
  136        $this->assertFalse($actual, 
'Detector should be satisfied after single trigger');
 
  143        $timer_start = ilWorkflowUtils::time() + 5*60; # +5 Minutes from here.
 
  145        $detector->setListeningTimeframe($timer_start, $timer_end);
 
  148        $actual = $detector->isListening();
 
  151        $this->assertFalse($actual, 
'Detector should not be listening.');
 
  158        $timer_start = ilWorkflowUtils::time() + 5*60; # +5 Minutes from here.
 
  162        $actual = $detector->isListening();
 
  165        $this->assertTrue($actual, 
'Detector should be listening.');
 
  179        $detector->setListeningTimeframe($exp_start, $exp_end);
 
  180        $act = $detector->getListeningTimeframe();
 
  183        $this->assertEquals($exp_start . $exp_end, $act[
'listening_start'] . $act[
'listening_end']);
 
  190        $timer_start = ilWorkflowUtils::time() - 5*60; # -5 Minutes from now.
 
  191        $timer_end = ilWorkflowUtils::time() - 1*60; # -1 Minute from now.
 
  192        $detector->setListeningTimeframe($timer_start, $timer_end);
 
  195        $actual = $detector->isListening();
 
  198        $this->assertFalse($actual, 
'Detector should not be listening.');
 
  205        $timer_start = ilWorkflowUtils::time() - 5*60; # -5 Minutes from now.
 
  206        $timer_end = 0; # Wildcard.
 
  207        $detector->setListeningTimeframe($timer_start, $timer_end);
 
  210        $actual = $detector->isListening();
 
  213        $this->assertTrue($actual, 
'Detector should not be listening.');
 
  220        $timer_start = 0; # Wildcard.
 
  221        $timer_end = ilWorkflowUtils::time() + 5*60; # +5 Minutes from now.
 
  222        $detector->setListeningTimeframe($timer_start, $timer_end);
 
  225        $actual = $detector->isListening();
 
  228        $this->assertTrue($actual, 
'Detector should not be listening.');
 
  235        $exp_start = 4711; # +5 Minutes from here.
 
  239        $detector->setListeningTimeframe($exp_start, $exp_end);
 
  240        $act = $detector->getListeningTimeframe();
 
  243        $this->assertEquals($exp_start . $exp_end, $act[
'listening_start'] . $act[
'listening_end']);
 
  253        $detector->setDbId($expected);
 
  254        $actual = $detector->getDbId();
 
  257        $this->assertEquals($expected, $actual);
 
  267        $detector->setDbId($expected);
 
  268        $actual = $detector->hasDbId();
 
  271        $this->assertTrue($actual);
 
  284        $actual = $detector->getDbId();
 
  287        $this->assertEquals($expected, $actual);
 
  296        $actual = $detector->hasDbId();
 
  299        $this->assertFalse($actual);
 
  304        $this->markTestIncomplete(
 
  305            '$ilDB throws notices during test.' 
  311        require_once 
'./Services/Database/classes/class.ilDBMySQL.php';
 
  312        $ilDB_mock = $this->createMock(
'ilDBMySQL', array(
'nextID',
'quote',
'insert'), array(), 
'', 
false);
 
  314        $ilDB_mock->expects($this->once())->method(
'nextID')->with($this->equalTo(
'wfe_det_listening'))->will($this->returnValue(234));
 
  315        $ilDB_mock->expects($this->any())->method(
'quote')->will($this->returnArgument(0));
 
  316        $ilDB_mock->expects($this->any())->method(
'insert')->with(
 
  319                'detector_id'           => array(
'integer', 234),
 
  320                'workflow_id'           => array(
'integer', 
null),
 
  321                'type'                          => array(
'text', 
'time_passed' ),
 
  322                'content'                       => array(
'text', 
'time_passed'),
 
  323                'subject_type'          => array(
'text', 
'none'),
 
  324                'subject_id'            => array(
'integer', 0),
 
  325                'context_type'          => array(
'text', 
'none'),
 
  326                'context_id'            => array(
'integer', 0),
 
  327                'listening_start'       => array(
'integer', 0),
 
  328                'listening_end'         => array(
'integer', 0)
 
  330        )->will($this->returnValue(
true));
 
  333        $stashed_real_object = @
$GLOBALS[
'ilDB'];
 
  335        $detector->writeDetectorToDb();
 
  337        $actual = $detector->hasDbId();
 
  340        $this->assertTrue($actual);
 
  342        $GLOBALS[
'ilDB'] = $stashed_real_object;
 
  347        $this->markTestIncomplete(
 
  348            '$ilDB throws notices during test.' 
  354        require_once 
'./Services/Database/classes/class.ilDBMySQL.php';
 
  355        $ilDB_mock = $this->createMock(
'ilDBMySQL', array(
'quote',
'manipulate'), array(), 
'', 
false);
 
  357        $ilDB_mock->expects($this->any())->method(
'quote')->will($this->returnValue(234));
 
  358        $ilDB_mock->expects($this->any())->method(
'manipulate')->with(
 
  360                                FROM wfe_det_listening 
  361                                WHERE detector_id = 234' 
  362        )->will($this->returnValue(
true));
 
  364        $stashed_real_object = @
$GLOBALS[
'ilDB'];
 
  368        $detector->setDbId(234);
 
  369        $detector->deleteDetectorFromDb();
 
  370        $actual = $detector->hasDbId();
 
  373        $this->assertFalse($actual);
 
  374        $GLOBALS[
'ilDB'] = $stashed_real_object;
 
  379        $this->markTestIncomplete(
 
  380            '$ilDB throws notices during test.' 
  386        require_once 
'./Services/Database/classes/class.ilDBMySQL.php';
 
  387        $ilDB_mock = $this->createMock(
'ilDBMySQL', array(
'nextID',
'quote',
'insert'), array(), 
'', 
false);
 
  389        $ilDB_mock->expects($this->once())->method(
'nextID')->with($this->equalTo(
'wfe_det_listening'))->will($this->returnValue(234));
 
  390        $ilDB_mock->expects($this->any())->method(
'quote')->will($this->returnArgument(0));
 
  391        $ilDB_mock->expects($this->any())->method(
'insert')->with(
 
  394                'detector_id'           => array(
'integer', 234),
 
  395                'workflow_id'           => array(
'integer', 
null),
 
  396                'type'                          => array(
'text', 
'time_passed' ),
 
  397                'content'                       => array(
'text', 
'time_passed'),
 
  398                'subject_type'          => array(
'text', 
'none'),
 
  399                'subject_id'            => array(
'integer', 0),
 
  400                'context_type'          => array(
'text', 
'none'),
 
  401                'context_id'            => array(
'integer', 0),
 
  402                'listening_start'       => array(
'integer', 0),
 
  403                'listening_end'         => array(
'integer', 0)
 
  405        )->will($this->returnValue(
true));
 
  407        $stashed_real_object = @
$GLOBALS[
'ilDB'];
 
  411        $detector->onActivate();
 
  412        $actual = $detector->hasDbId();
 
  416        $this->assertTrue($actual);
 
  417        $this->assertEquals(234, $detector->getDbId());
 
  418        $GLOBALS[
'ilDB'] = $stashed_real_object;
 
  423        $this->markTestIncomplete(
 
  424            '$ilDB throws notices during test.' 
  430        require_once 
'./Services/Database/classes/class.ilDBMySQL.php';
 
  431        $ilDB_mock = $this->createMock(
'ilDBMySQL', array(
'quote',
'manipulate'), array(), 
'', 
false);
 
  433        $ilDB_mock->expects($this->any())->method(
'quote')->will($this->returnValue(234));
 
  434        $ilDB_mock->expects($this->any())->method(
'manipulate')->with(
 
  436                                FROM wfe_det_listening 
  437                                WHERE detector_id = 234' 
  438        )->will($this->returnValue(
true));
 
  440        $stashed_real_object = @
$GLOBALS[
'ilDB'];
 
  444        $detector->setDbId(234);
 
  445        $detector->onDeactivate();
 
  446        $actual = $detector->hasDbId();
 
  449        $this->assertFalse($actual);
 
  451        $GLOBALS[
'ilDB'] = $stashed_real_object;
 
  458        $exp_type = 
'time_passed';
 
  459        $exp_content = 
'time_passed';
 
  464        $event = $detector->getEvent();
 
  465        $act_type = $event[
'type'];
 
  466        $act_content = $event[
'content'];
 
  467        $this->assertEquals($exp_type . $exp_content, $act_type . $act_content);
 
  480        $event = $detector->getEventSubject();
 
  481        $act_type = $event[
'type'];
 
  482        $act_id = $event[
'identifier'];
 
  483        $this->assertEquals($exp_type . $exp_id, $act_type . $act_id);
 
  496        $event = $detector->getEventContext();
 
  497        $act_type = $event[
'type'];
 
  498        $act_id = $event[
'identifier'];
 
  499        $this->assertEquals($exp_type . $exp_id, $act_type . $act_id);
 
  508        $actual = $detector->getContext();
 
  511        if ($actual === $this->node) {
 
  512            $this->assertEquals($actual, $this->node);
 
  514            $this->assertTrue(
false, 
'Context not identical.');
 
An exception for terminatinating execution or to throw for unit testing.
@noinspection PhpIncludeInspection
@noinspection PhpIncludeInspection
ilTimerDetectorTest is part of the petri net based workflow engine.
testDeleteDetectorFromDb()
testIsListeningWithWildcardBeginningTimeFrame()
testIsListeningWithWildcardEndingTimeFrame()
testIsListeningWithPastTimeFrame()
testIsListeningWithTimeFrame()
testGetNonExistingDbId()
@expectedException ilWorkflowObjectStateException
testIsListeningWithoutTimeFrame()
testSetGetIllegalListeningTimeframe()
@expectedException ilWorkflowInvalidArgumentException
testConstructorValidContext()
testSetGetListeningTimeframe()
@noinspection PhpIncludeInspection
$GLOBALS['loaded']
Global hash that tracks already loaded includes.