From c94c1070f2a7893a935fe6c40026c6c268b7c48f Mon Sep 17 00:00:00 2001 From: Aleh Hutnikau Date: Mon, 7 Sep 2015 12:33:25 +0300 Subject: [PATCH] add unit test --- .../tests/AssessmentItemSessionTest.php | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/qtism/runtime/tests/AssessmentItemSessionTest.php b/test/qtism/runtime/tests/AssessmentItemSessionTest.php index 158ca426a..6287fda59 100644 --- a/test/qtism/runtime/tests/AssessmentItemSessionTest.php +++ b/test/qtism/runtime/tests/AssessmentItemSessionTest.php @@ -346,4 +346,42 @@ public function testSimultaneousSubmissionOnlyOneAttempt() { $this->assertEquals(AssessmentItemSessionException::STATE_VIOLATION, $e->getCode()); } } + + public function testRunCallback() { + $itemSession = self::instantiateBasicAssessmentItemSession(); + $itemSession->beginItemSession(); + + $itemSession->registerCallback('beginAttempt', function ($item, $itemSessionTest, $itemSession) { + $itemSessionTest->assertEquals($item, $itemSession); + $itemSessionTest->assertEquals($item->getState(), AssessmentItemSessionState::INTERACTING); + }, + array($this, $itemSession) + ); + + $itemSession->registerCallback('suspend', function ($item, $itemSessionTest, $itemSession) { + $itemSessionTest->assertEquals($item, $itemSession); + $itemSessionTest->assertEquals($item->getState(), AssessmentItemSessionState::SUSPENDED); + }, + array($this, $itemSession) + ); + + $itemSession->registerCallback('interact', function ($item, $itemSessionTest, $itemSession) { + $itemSessionTest->assertEquals($item, $itemSession); + $itemSessionTest->assertEquals($item->getState(), AssessmentItemSessionState::INTERACTING); + }, + array($this, $itemSession) + ); + + $itemSession->registerCallback('endAttempt', function ($item, $itemSessionTest, $itemSession) { + $itemSessionTest->assertEquals($item, $itemSession); + $itemSessionTest->assertEquals($item->getState(), AssessmentItemSessionState::CLOSED); + }, + array($this, $itemSession) + ); + + $itemSession->beginAttempt(); + $itemSession->suspend(); + $itemSession->interact(); + $itemSession->endAttempt(); + } } \ No newline at end of file