diff --git a/src/qtism/runtime/tests/AssessmentTestSession.php b/src/qtism/runtime/tests/AssessmentTestSession.php index 126051b50..91618f56e 100644 --- a/src/qtism/runtime/tests/AssessmentTestSession.php +++ b/src/qtism/runtime/tests/AssessmentTestSession.php @@ -70,6 +70,9 @@ */ class AssessmentTestSession extends State { + const ROUTECOUNT_ALL = 0; + const ROUTECOUNT_EXCLUDENORESPONSE = 1; + /** * A unique ID for this AssessmentTestSession. * @@ -1052,12 +1055,31 @@ public function getItemSubset($sectionIdentifier = '', IdentifierCollection $inc /** * Get the number of items in the current Route. In other words, the total number * of item occurences the candidate can take during the test. + * + * The $mode parameter can take two values: + * + * * AssessmentTestSession::ROUTECOUNT_ALL: consider all item occurences of the test + * * AssessmentTestSession::ROUTECOUNT_EXCLUDENORESPONSE: consider only item occurences containing at least one response declaration. * + * @param integer $mode AssessmentTestSession::ROUTECOUNT_ALL | AssessmentTestSession::ROUTECOUNT_EXCLUDENORESPONSE * @return integer */ - public function getRouteCount() + public function getRouteCount($mode = self::ROUTECOUNT_ALL) { - return $this->getRoute()->count(); + if ($mode === self::ROUTECOUNT_ALL) { + + return $this->getRoute()->count(); + } else { + $i = 0; + + foreach ($this->getRoute()->getAssessmentItemRefs() as $assessmentItemRef) { + if (count($assessmentItemRef->getResponseDeclarations()) > 0) { + $i++; + } + } + + return $i; + } } /** diff --git a/test/qtismtest/runtime/tests/AssessmentTestSessionTest.php b/test/qtismtest/runtime/tests/AssessmentTestSessionTest.php index b9cdfd54a..ade77ccd7 100644 --- a/test/qtismtest/runtime/tests/AssessmentTestSessionTest.php +++ b/test/qtismtest/runtime/tests/AssessmentTestSessionTest.php @@ -1547,4 +1547,28 @@ public function testIsTimeout() { $this->assertEquals(AssessmentTestSessionState::CLOSED, $session->getState()); $this->assertFalse($session->isTimeout()); } + + public function testGetRouteCountAllWithResponseDeclaration() { + $doc = new XmlCompactDocument(); + $doc->load(self::samplesDir() . 'custom/runtime/route_count/all_with_responsedeclaration.xml'); + $manager = new SessionManager(); + $session = $manager->createAssessmentTestSession($doc->getDocumentComponent()); + $session->beginTestSession(); + + $this->assertEquals(3, $session->getRouteCount()); + $this->assertEquals(3, $session->getRouteCount(AssessmentTestSession::ROUTECOUNT_ALL)); + $this->assertEquals(3, $session->getRouteCount(AssessmentTestSession::ROUTECOUNT_EXCLUDENORESPONSE)); + } + + public function testGetRouteCountMissingResponseDeclaration() { + $doc = new XmlCompactDocument(); + $doc->load(self::samplesDir() . 'custom/runtime/route_count/missing_responsedeclaration.xml'); + $manager = new SessionManager(); + $session = $manager->createAssessmentTestSession($doc->getDocumentComponent()); + $session->beginTestSession(); + + $this->assertEquals(3, $session->getRouteCount()); + $this->assertEquals(3, $session->getRouteCount(AssessmentTestSession::ROUTECOUNT_ALL)); + $this->assertEquals(2, $session->getRouteCount(AssessmentTestSession::ROUTECOUNT_EXCLUDENORESPONSE)); + } } diff --git a/test/samples/custom/runtime/route_count/all_with_responsedeclaration.xml b/test/samples/custom/runtime/route_count/all_with_responsedeclaration.xml new file mode 100644 index 000000000..72b2ff50b --- /dev/null +++ b/test/samples/custom/runtime/route_count/all_with_responsedeclaration.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + diff --git a/test/samples/custom/runtime/route_count/missing_responsedeclaration.xml b/test/samples/custom/runtime/route_count/missing_responsedeclaration.xml new file mode 100644 index 000000000..921640fc0 --- /dev/null +++ b/test/samples/custom/runtime/route_count/missing_responsedeclaration.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + +