Skip to content

Commit

Permalink
Added ::ROUTECOUNT_ALL, ::ROUTECOUNT_EXCLUDENORESPONSE constants.
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Apr 22, 2016
1 parent 2af4072 commit 60f9d58
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/qtism/runtime/tests/AssessmentTestSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
*/
class AssessmentTestSession extends State
{
const ROUTECOUNT_ALL = 0;
const ROUTECOUNT_EXCLUDENORESPONSE = 1;

/**
* A unique ID for this AssessmentTestSession.
*
Expand Down Expand Up @@ -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;
}
}

/**
Expand Down
24 changes: 24 additions & 0 deletions test/qtismtest/runtime/tests/AssessmentTestSessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<assessmentTest xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.imsglobal.org/xsd/imsqti_v2p1 http://www.taotesting.com/xsd/qticompact_v1p0.xsd"
identifier="linear_route_count" title="Linear Route Count">
<testPart identifier="P01" navigationMode="linear" submissionMode="individual">
<assessmentSection identifier="S01" title="Section1" visible="true">
<assessmentItemRef identifier="Q01" href="./Q01.xml" timeDependent="false">
<responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier"/>
</assessmentItemRef>

<assessmentItemRef identifier="Q02" href="./Q02.xml" timeDependent="false">
<responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier"/>
</assessmentItemRef>

<assessmentItemRef identifier="Q03" href="./Q03.xml" timeDependent="false">
<responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier"/>
</assessmentItemRef>
</assessmentSection>
</testPart>
</assessmentTest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<assessmentTest xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.imsglobal.org/xsd/imsqti_v2p1 http://www.taotesting.com/xsd/qticompact_v1p0.xsd"
identifier="linear_route_count" title="Linear Route Count">
<testPart identifier="P01" navigationMode="linear" submissionMode="individual">
<assessmentSection identifier="S01" title="Section1" visible="true">
<assessmentItemRef identifier="Q01" href="./Q01.xml" timeDependent="false">
<responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier"/>
</assessmentItemRef>

<assessmentItemRef identifier="Q02" href="./Q02.xml" timeDependent="false"/>

<assessmentItemRef identifier="Q03" href="./Q03.xml" timeDependent="false">
<responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier"/>
</assessmentItemRef>
</assessmentSection>
</testPart>
</assessmentTest>

0 comments on commit 60f9d58

Please sign in to comment.