From d8b58d1e10af3f50f537ae2b688036aee35ab6da Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Tue, 12 Dec 2023 17:08:29 +0100 Subject: [PATCH 1/5] chore: add test that must pass after fix --- .../AssessmentTestSessionBranchingsTest.php | 12 ++++++++++ .../runtime/branchings/branching_rules.xml | 22 ++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/test/qtismtest/runtime/tests/AssessmentTestSessionBranchingsTest.php b/test/qtismtest/runtime/tests/AssessmentTestSessionBranchingsTest.php index 9523d1fcb..7429688d1 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-10', $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..01d5cf719 100644 --- a/test/samples/custom/runtime/branchings/branching_rules.xml +++ b/test/samples/custom/runtime/branchings/branching_rules.xml @@ -85,18 +85,34 @@ + + + + + true + + + + + + + + + + + + + + - - - From 6bf92c6229d59142a4feb34896a114b68d416666 Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Tue, 12 Dec 2023 17:59:53 +0100 Subject: [PATCH 2/5] fix: if branching rules are from test part, allow nonlinear mode --- src/qtism/data/rules/BranchRuleCollection.php | 14 ++++++++++++++ src/qtism/runtime/tests/AssessmentTestSession.php | 6 +++++- src/qtism/runtime/tests/RouteItem.php | 5 ++++- .../tests/AssessmentTestSessionBranchingsTest.php | 2 +- .../custom/runtime/branchings/branching_rules.xml | 3 ++- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/qtism/data/rules/BranchRuleCollection.php b/src/qtism/data/rules/BranchRuleCollection.php index 39e17c052..bc53776ba 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 $supportsNonLinearNavigationMode = false; + + public function isAllowedForNonLinearNavigationMode(): bool + { + return $this->supportsNonLinearNavigationMode; + } + + public function allowForNonLinearNavigationMode(): void + { + $this->supportsNonLinearNavigationMode = 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..4daa71f9b 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->isAllowedForNonLinearNavigationMode() + ) { 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..8f9fdb368 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->allowForNonLinearNavigationMode(); + + return $branchingRules; } } diff --git a/test/qtismtest/runtime/tests/AssessmentTestSessionBranchingsTest.php b/test/qtismtest/runtime/tests/AssessmentTestSessionBranchingsTest.php index 7429688d1..cdeb78562 100644 --- a/test/qtismtest/runtime/tests/AssessmentTestSessionBranchingsTest.php +++ b/test/qtismtest/runtime/tests/AssessmentTestSessionBranchingsTest.php @@ -315,7 +315,7 @@ public function testBranchingRules(): void $session->moveNext(); $this->assertEquals('testPart-8', $session->getCurrentTestPart()->getIdentifier()); - $this->assertEquals('assessmentSection-10', $session->getCurrentAssessmentSection()->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 01d5cf719..c735b36ca 100644 --- a/test/samples/custom/runtime/branchings/branching_rules.xml +++ b/test/samples/custom/runtime/branchings/branching_rules.xml @@ -88,7 +88,7 @@ - + true @@ -107,6 +107,7 @@ + From 3b3533cf9bb2ba9c28052ae188013846854fb271 Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Tue, 12 Dec 2023 18:16:32 +0100 Subject: [PATCH 3/5] chore: comment typo fix --- test/samples/custom/runtime/branchings/branching_rules.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/samples/custom/runtime/branchings/branching_rules.xml b/test/samples/custom/runtime/branchings/branching_rules.xml index c735b36ca..44de80481 100644 --- a/test/samples/custom/runtime/branchings/branching_rules.xml +++ b/test/samples/custom/runtime/branchings/branching_rules.xml @@ -107,7 +107,7 @@ - + From ca7df1533e94e76a481b6216371a63407e0e1f53 Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Tue, 12 Dec 2023 18:20:17 +0100 Subject: [PATCH 4/5] chore: better method names --- src/qtism/data/rules/BranchRuleCollection.php | 10 +++++----- src/qtism/runtime/tests/AssessmentTestSession.php | 2 +- src/qtism/runtime/tests/RouteItem.php | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/qtism/data/rules/BranchRuleCollection.php b/src/qtism/data/rules/BranchRuleCollection.php index bc53776ba..08b0d21f3 100644 --- a/src/qtism/data/rules/BranchRuleCollection.php +++ b/src/qtism/data/rules/BranchRuleCollection.php @@ -33,16 +33,16 @@ class BranchRuleCollection extends QtiComponentCollection { /** @var bool */ - private $supportsNonLinearNavigationMode = false; + private $allowNonLinearNavigationMode = false; - public function isAllowedForNonLinearNavigationMode(): bool + public function isNonLinearNavigationModeAllowed(): bool { - return $this->supportsNonLinearNavigationMode; + return $this->allowNonLinearNavigationMode; } - public function allowForNonLinearNavigationMode(): void + public function allowNonLinearNavigationMode(): void { - $this->supportsNonLinearNavigationMode = true; + $this->allowNonLinearNavigationMode = true; } /** diff --git a/src/qtism/runtime/tests/AssessmentTestSession.php b/src/qtism/runtime/tests/AssessmentTestSession.php index 4daa71f9b..6a087ed6d 100644 --- a/src/qtism/runtime/tests/AssessmentTestSession.php +++ b/src/qtism/runtime/tests/AssessmentTestSession.php @@ -2415,7 +2415,7 @@ protected function nextRouteItem($ignoreBranchings = false, $ignorePreConditions if ( $ignoreBranchings === false && $numberOfBranchRules > 0 && - $this->mustApplyBranchRules() || $branchRules->isAllowedForNonLinearNavigationMode() + $this->mustApplyBranchRules() || $branchRules->isNonLinearNavigationModeAllowed() ) { for ($i = 0; $i < $numberOfBranchRules; $i++) { $engine = new ExpressionEngine($branchRules[$i]->getExpression(), $this); diff --git a/src/qtism/runtime/tests/RouteItem.php b/src/qtism/runtime/tests/RouteItem.php index 8f9fdb368..834e7a554 100644 --- a/src/qtism/runtime/tests/RouteItem.php +++ b/src/qtism/runtime/tests/RouteItem.php @@ -479,7 +479,7 @@ public function getEffectiveBranchRules(): BranchRuleCollection // Return branching rules from the Test Part level $branchingRules = $this->getTestPart()->getBranchRules(); - $branchingRules->allowForNonLinearNavigationMode(); + $branchingRules->allowNonLinearNavigationMode(); return $branchingRules; } From 2283f4a400790c51b5f2f28c796db4ee03b991eb Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Tue, 12 Dec 2023 18:25:04 +0100 Subject: [PATCH 5/5] chore: isolate conditional or logic --- src/qtism/runtime/tests/AssessmentTestSession.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qtism/runtime/tests/AssessmentTestSession.php b/src/qtism/runtime/tests/AssessmentTestSession.php index 6a087ed6d..ea2d43af8 100644 --- a/src/qtism/runtime/tests/AssessmentTestSession.php +++ b/src/qtism/runtime/tests/AssessmentTestSession.php @@ -2415,7 +2415,7 @@ protected function nextRouteItem($ignoreBranchings = false, $ignorePreConditions if ( $ignoreBranchings === false && $numberOfBranchRules > 0 && - $this->mustApplyBranchRules() || $branchRules->isNonLinearNavigationModeAllowed() + ($this->mustApplyBranchRules() || $branchRules->isNonLinearNavigationModeAllowed()) ) { for ($i = 0; $i < $numberOfBranchRules; $i++) { $engine = new ExpressionEngine($branchRules[$i]->getExpression(), $this);