diff --git a/src/qtism/data/rules/BranchRuleCollection.php b/src/qtism/data/rules/BranchRuleCollection.php
index 39e17c052..08b0d21f3 100644
--- a/src/qtism/data/rules/BranchRuleCollection.php
+++ b/src/qtism/data/rules/BranchRuleCollection.php
@@ -31,6 +31,20 @@
*/
class BranchRuleCollection extends QtiComponentCollection
{
+
+ /** @var bool */
+ private $allowNonLinearNavigationMode = false;
+
+ public function isNonLinearNavigationModeAllowed(): bool
+ {
+ return $this->allowNonLinearNavigationMode;
+ }
+
+ public function allowNonLinearNavigationMode(): void
+ {
+ $this->allowNonLinearNavigationMode = true;
+ }
+
/**
* Check if a given $value is an instance of BranchRule.
*
diff --git a/src/qtism/runtime/tests/AssessmentTestSession.php b/src/qtism/runtime/tests/AssessmentTestSession.php
index 8085ca1ab..ea2d43af8 100644
--- a/src/qtism/runtime/tests/AssessmentTestSession.php
+++ b/src/qtism/runtime/tests/AssessmentTestSession.php
@@ -2412,7 +2412,11 @@ protected function nextRouteItem($ignoreBranchings = false, $ignorePreConditions
$numberOfBranchRules = $branchRules->count();
// Branchings?
- if ($ignoreBranchings === false && $numberOfBranchRules > 0 && $this->mustApplyBranchRules() === true) {
+ if (
+ $ignoreBranchings === false &&
+ $numberOfBranchRules > 0 &&
+ ($this->mustApplyBranchRules() || $branchRules->isNonLinearNavigationModeAllowed())
+ ) {
for ($i = 0; $i < $numberOfBranchRules; $i++) {
$engine = new ExpressionEngine($branchRules[$i]->getExpression(), $this);
$condition = $engine->process();
diff --git a/src/qtism/runtime/tests/RouteItem.php b/src/qtism/runtime/tests/RouteItem.php
index c29e9a75b..834e7a554 100644
--- a/src/qtism/runtime/tests/RouteItem.php
+++ b/src/qtism/runtime/tests/RouteItem.php
@@ -478,6 +478,9 @@ public function getEffectiveBranchRules(): BranchRuleCollection
} while ($parentSection = $parentSection->getParent());
// Return branching rules from the Test Part level
- return $this->getTestPart()->getBranchRules();
+ $branchingRules = $this->getTestPart()->getBranchRules();
+ $branchingRules->allowNonLinearNavigationMode();
+
+ return $branchingRules;
}
}
diff --git a/test/qtismtest/runtime/tests/AssessmentTestSessionBranchingsTest.php b/test/qtismtest/runtime/tests/AssessmentTestSessionBranchingsTest.php
index 9523d1fcb..cdeb78562 100644
--- a/test/qtismtest/runtime/tests/AssessmentTestSessionBranchingsTest.php
+++ b/test/qtismtest/runtime/tests/AssessmentTestSessionBranchingsTest.php
@@ -305,5 +305,17 @@ public function testBranchingRules(): void
$this->assertEquals('testPart-5', $session->getCurrentTestPart()->getIdentifier());
$this->assertEquals('assessmentSection-8', $session->getCurrentAssessmentSection()->getIdentifier());
$this->assertEquals('item-11', $session->getCurrentAssessmentItemRef()->getIdentifier());
+
+ $session->moveNext();
+
+ $this->assertEquals('testPart-6', $session->getCurrentTestPart()->getIdentifier());
+ $this->assertEquals('assessmentSection-9', $session->getCurrentAssessmentSection()->getIdentifier());
+ $this->assertEquals('item-12', $session->getCurrentAssessmentItemRef()->getIdentifier());
+
+ $session->moveNext();
+
+ $this->assertEquals('testPart-8', $session->getCurrentTestPart()->getIdentifier());
+ $this->assertEquals('assessmentSection-11', $session->getCurrentAssessmentSection()->getIdentifier());
+ $this->assertEquals('item-14', $session->getCurrentAssessmentItemRef()->getIdentifier());
}
}
diff --git a/test/samples/custom/runtime/branchings/branching_rules.xml b/test/samples/custom/runtime/branchings/branching_rules.xml
index cf9e3557e..44de80481 100644
--- a/test/samples/custom/runtime/branchings/branching_rules.xml
+++ b/test/samples/custom/runtime/branchings/branching_rules.xml
@@ -85,18 +85,35 @@
+
+
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-