Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement branchRules at testPart level. #369

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/qtism/runtime/tests/AbstractSessionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use qtism\data\IAssessmentItem;
use qtism\data\NavigationMode;
use qtism\data\SubmissionMode;
use qtism\data\TestPart;

/**
* The AbstractSessionManager class is a bed for instantiating
Expand Down Expand Up @@ -148,6 +149,7 @@ protected function createRoute(AssessmentTest $test): Route
{
$routeStack = [];

/** @var TestPart $testPart */
foreach ($test->getTestParts() as $testPart) {
$assessmentSectionStack = [];

Expand Down Expand Up @@ -212,10 +214,18 @@ protected function createRoute(AssessmentTest $test): Route
}
}
}

// $route contains the currently processed testPart.
// Now, decorate last RouteItem of SelectableRoute with BranchRule objects if any.
if (!empty($route) && $route->count() > 0) {
$route->getLastRouteItem()->addBranchRules($testPart->getBranchRules());
}
}

$finalRoutes = $routeStack;
$route = new SelectableRoute();

/** @var SelectableRoute $finalRoute */
foreach ($finalRoutes as $finalRoute) {
$route->appendRoute($finalRoute);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,22 @@ public function testBranchingOnPreconditon(): void
$this::assertNull($session['Q03.SCORE']);
$this::assertSame(1.0, $session['Q04.SCORE']->getValue());
}

public function testBranchingOnTestPartsSimple1(): void
{
$session = self::instantiate(self::samplesDir() . 'custom/runtime/branchings/branchings_testparts.xml');
$session->beginTestSession();

// We are starting at item Q01, in testPart P01.
$this->assertEquals('Q01', $session->getCurrentAssessmentItemRef()->getIdentifier());

// Let's jump to testPart P03.
$session->beginAttempt();
$session->endAttempt(new State([new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new QtiIdentifier('GotoP03'))]));
$session->moveNext();

// We expect to land in testPart P03, item Q03.
$this->assertEquals('Q03', $session->getCurrentAssessmentItemRef()->getIdentifier());
$this->assertEquals('P03', $session->getCurrentTestPart()->getIdentifier());
}
}
37 changes: 37 additions & 0 deletions test/samples/custom/runtime/branchings/branchings_testparts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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_v2p1.xsd"
identifier="branchings_single_section_linear" title="Branchings Single Section Linear">
<testPart identifier="P01" navigationMode="linear" submissionMode="individual">
<!-- If the response to Q01 "GotoP02", redirect to testPart "P02". -->
<branchRule target="P02">
<match>
<variable identifier="Q01.RESPONSE"/>
<baseValue baseType="identifier">GotoP02</baseValue>
</match>
</branchRule>
<!-- If the response to Q01 "GotoP03", redirect to testPart "P03". -->
<branchRule target="P03">
<match>
<variable identifier="Q01.RESPONSE"/>
<baseValue baseType="identifier">GotoP03</baseValue>
</match>
</branchRule>
<assessmentSection identifier="S01" fixed="false" title="Section1" visible="false">
<assessmentItemRef identifier="Q01" href="./Q01.xml" fixed="false" timeDependent="false">
<responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier"/>
</assessmentItemRef>
</assessmentSection>
</testPart>
<testPart identifier="P02" navigationMode="linear" submissionMode="individual">
<assessmentSection identifier="S02" fixed="false" title="Section2" visible="false">
<assessmentItemRef identifier="Q02" href="./Q02.xml" fixed="false" timeDependent="false"/>
</assessmentSection>
</testPart>
<testPart identifier="P03" navigationMode="linear" submissionMode="individual">
<assessmentSection identifier="S03" fixed="false" title="Section3" visible="false">
<assessmentItemRef identifier="Q03" href="./Q03.xml" fixed="false" timeDependent="false"/>
</assessmentSection>
</testPart>
</assessmentTest>