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';
44 $ilSetting->delete(
'IL_PHPUNIT_TEST_MICROTIME');
57 'Construction failed with valid context passed to constructor.'
65 $expected = ilWorkflowUtils::time();
68 $detector->setTimerStart($expected);
69 $actual = $detector->getTimerStart();
72 $this->assertEquals($actual, $expected);
82 $detector->setTimerLimit($expected);
83 $actual = $detector->getTimerLimit();
86 $this->assertEquals($actual, $expected);
93 $timer_start = ilWorkflowUtils::time(); # +5 Minutes from here.
95 $detector->setTimerStart($timer_start);
96 $detector->setTimerLimit($timer_limit);
99 $detector->trigger(
null);
102 $actual = $detector->getDetectorState();
103 $this->assertFalse($actual,
'Early trigger should not satisfy detector');
110 $timer_start = ilWorkflowUtils::time(); # +5 Minutes from now.
112 $detector->setTimerStart($timer_start);
113 $detector->setTimerLimit($timer_limit);
116 $detector->trigger(
null);
119 $actual = $detector->getDetectorState();
120 $this->assertTrue($actual,
'Trigger should not satisfy detector');
127 $timer_start = ilWorkflowUtils::time(); # +5 Minutes from now.
129 $detector->setTimerStart($timer_start);
130 $detector->setTimerLimit($timer_limit);
133 $detector->trigger(
null);
134 $actual = $detector->trigger(
null);
137 $this->assertFalse($actual,
'Detector should be satisfied after single trigger');
144 $timer_start = ilWorkflowUtils::time() + 5*60; # +5 Minutes from here.
146 $detector->setListeningTimeframe($timer_start, $timer_end);
149 $actual = $detector->isListening();
152 $this->assertFalse($actual,
'Detector should not be listening.');
159 $timer_start = ilWorkflowUtils::time() + 5*60; # +5 Minutes from here.
163 $actual = $detector->isListening();
166 $this->assertTrue($actual,
'Detector should be listening.');
180 $detector->setListeningTimeframe($exp_start, $exp_end);
181 $act = $detector->getListeningTimeframe();
184 $this->assertEquals($exp_start.$exp_end, $act[
'listening_start'].$act[
'listening_end']);
191 $timer_start = ilWorkflowUtils::time() - 5*60; # -5 Minutes from now.
192 $timer_end = ilWorkflowUtils::time() - 1*60; # -1 Minute from now.
193 $detector->setListeningTimeframe($timer_start, $timer_end);
196 $actual = $detector->isListening();
199 $this->assertFalse($actual,
'Detector should not be listening.');
206 $timer_start = ilWorkflowUtils::time() - 5*60; # -5 Minutes from now.
207 $timer_end = 0; # Wildcard.
208 $detector->setListeningTimeframe($timer_start, $timer_end);
211 $actual = $detector->isListening();
214 $this->assertTrue($actual,
'Detector should not be listening.');
221 $timer_start = 0; # Wildcard.
222 $timer_end = ilWorkflowUtils::time() + 5*60; # +5 Minutes from now.
223 $detector->setListeningTimeframe($timer_start, $timer_end);
226 $actual = $detector->isListening();
229 $this->assertTrue($actual,
'Detector should not be listening.');
236 $exp_start = 4711; # +5 Minutes from here.
240 $detector->setListeningTimeframe($exp_start, $exp_end);
241 $act = $detector->getListeningTimeframe();
244 $this->assertEquals($exp_start.$exp_end, $act[
'listening_start'].$act[
'listening_end']);
254 $detector->setDbId($expected);
255 $actual = $detector->getDbId();
258 $this->assertEquals($expected, $actual);
268 $detector->setDbId($expected);
269 $actual = $detector->hasDbId();
272 $this->assertTrue($actual);
285 $actual = $detector->getDbId();
288 $this->assertEquals($expected, $actual);
297 $actual = $detector->hasDbId();
300 $this->assertFalse($actual);
305 $this->markTestIncomplete(
306 '$ilDB throws notices during test.'
312 require_once
'./Services/Database/classes/class.ilDBMySQL.php';
313 $ilDB_mock = $this->getMock(
'ilDBMySQL',array(
'nextID',
'quote',
'insert'),array(),
'', FALSE);
315 $ilDB_mock->expects($this->once())->method(
'nextID')->with($this->equalTo(
'wfe_det_listening'))->will($this->returnValue(234));
316 $ilDB_mock->expects($this->any())->method(
'quote')->will($this->returnArgument(0));
317 $ilDB_mock->expects($this->any())->method(
'insert')->with(
320 'detector_id' => array (
'integer', 234),
321 'workflow_id' => array (
'integer',
null),
322 'type' => array (
'text',
'time_passed' ),
323 'content' => array (
'text',
'time_passed'),
324 'subject_type' => array (
'text',
'none'),
325 'subject_id' => array (
'integer', 0),
326 'context_type' => array (
'text',
'none'),
327 'context_id' => array (
'integer', 0),
328 'listening_start' => array (
'integer', 0),
329 'listening_end' => array (
'integer', 0)
331 )->will($this->returnValue(
true));
334 $stashed_real_object = @
$GLOBALS[
'ilDB'];
336 $detector->writeDetectorToDb();
338 $actual = $detector->hasDbId();
341 $this->assertTrue($actual);
343 $GLOBALS[
'ilDB'] = $stashed_real_object;
348 $this->markTestIncomplete(
349 '$ilDB throws notices during test.'
355 require_once
'./Services/Database/classes/class.ilDBMySQL.php';
356 $ilDB_mock = $this->getMock(
'ilDBMySQL',array(
'quote',
'manipulate'),array(),
'', FALSE);
358 $ilDB_mock->expects($this->any())->method(
'quote')->will($this->returnValue(234));
359 $ilDB_mock->expects($this->any())->method(
'manipulate')->with(
361 FROM wfe_det_listening
362 WHERE detector_id = 234'
363 )->will($this->returnValue(
true));
365 $stashed_real_object = @
$GLOBALS[
'ilDB'];
369 $detector->setDbId(234);
370 $detector->deleteDetectorFromDb();
371 $actual = $detector->hasDbId();
374 $this->assertFalse($actual);
375 $GLOBALS[
'ilDB'] = $stashed_real_object;
380 $this->markTestIncomplete(
381 '$ilDB throws notices during test.'
387 require_once
'./Services/Database/classes/class.ilDBMySQL.php';
388 $ilDB_mock = $this->getMock(
'ilDBMySQL',array(
'nextID',
'quote',
'insert'),array(),
'', FALSE);
390 $ilDB_mock->expects($this->once())->method(
'nextID')->with($this->equalTo(
'wfe_det_listening'))->will($this->returnValue(234));
391 $ilDB_mock->expects($this->any())->method(
'quote')->will($this->returnArgument(0));
392 $ilDB_mock->expects($this->any())->method(
'insert')->with(
395 'detector_id' => array (
'integer', 234),
396 'workflow_id' => array (
'integer',
null),
397 'type' => array (
'text',
'time_passed' ),
398 'content' => array (
'text',
'time_passed'),
399 'subject_type' => array (
'text',
'none'),
400 'subject_id' => array (
'integer', 0),
401 'context_type' => array (
'text',
'none'),
402 'context_id' => array (
'integer', 0),
403 'listening_start' => array (
'integer', 0),
404 'listening_end' => array (
'integer', 0)
406 )->will($this->returnValue(
true));
408 $stashed_real_object = @
$GLOBALS[
'ilDB'];
412 $detector->onActivate();
413 $actual = $detector->hasDbId();
417 $this->assertTrue($actual);
418 $this->assertEquals(234, $detector->getDbId());
419 $GLOBALS[
'ilDB'] = $stashed_real_object;
424 $this->markTestIncomplete(
425 '$ilDB throws notices during test.'
431 require_once
'./Services/Database/classes/class.ilDBMySQL.php';
432 $ilDB_mock = $this->getMock(
'ilDBMySQL',array(
'quote',
'manipulate'),array(),
'', FALSE);
434 $ilDB_mock->expects($this->any())->method(
'quote')->will($this->returnValue(234));
435 $ilDB_mock->expects($this->any())->method(
'manipulate')->with(
437 FROM wfe_det_listening
438 WHERE detector_id = 234'
439 )->will($this->returnValue(
true));
441 $stashed_real_object = @
$GLOBALS[
'ilDB'];
445 $detector->setDbId(234);
446 $detector->onDeactivate();
447 $actual = $detector->hasDbId();
450 $this->assertFalse($actual);
452 $GLOBALS[
'ilDB'] = $stashed_real_object;
459 $exp_type =
'time_passed';
460 $exp_content =
'time_passed';
465 $event = $detector->getEvent();
466 $act_type = $event[
'type'];
467 $act_content = $event[
'content'];
468 $this->assertEquals($exp_type.$exp_content, $act_type.$act_content);
481 $event = $detector->getEventSubject();
482 $act_type = $event[
'type'];
483 $act_id = $event[
'identifier'];
484 $this->assertEquals($exp_type.$exp_id, $act_type.$act_id);
497 $event = $detector->getEventContext();
498 $act_type = $event[
'type'];
499 $act_id = $event[
'identifier'];
500 $this->assertEquals($exp_type.$exp_id, $act_type.$act_id);
509 $actual = $detector->getContext();
512 if ($actual === $this->node)
514 $this->assertEquals($actual, $this->node);
516 $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.