From 24c9b3581e19589e8210a626023cc8a2f8e15e73 Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Tue, 26 Sep 2023 18:53:02 +0200 Subject: [PATCH] chore: add unit test to cover pre-condition on test part and section --- ...AssessmentTestSessionPreConditionsTest.php | 24 +++++++++++++++++++ ...econditions_on_section_prevails_linear.xml | 20 ++++++++++++++++ ...onditions_on_test_part_prevails_linear.xml | 24 +++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 test/samples/custom/runtime/preconditions/preconditions_on_section_prevails_linear.xml create mode 100644 test/samples/custom/runtime/preconditions/preconditions_on_test_part_prevails_linear.xml diff --git a/test/qtismtest/runtime/tests/AssessmentTestSessionPreConditionsTest.php b/test/qtismtest/runtime/tests/AssessmentTestSessionPreConditionsTest.php index 9030ba643..15ea4cb00 100644 --- a/test/qtismtest/runtime/tests/AssessmentTestSessionPreConditionsTest.php +++ b/test/qtismtest/runtime/tests/AssessmentTestSessionPreConditionsTest.php @@ -163,4 +163,28 @@ public function testKillerTestEpicWin(): void $this::assertFalse($testSession->isRunning()); } + + public function testSectionPreConditionOnLinearTestWorks(): void + { + $testSession = self::instantiate(self::samplesDir() . 'custom/runtime/preconditions/preconditions_on_section_prevails_linear.xml'); + $testSession->beginTestSession(); + $testSession->beginAttempt(); + $testSession->moveNext(); + + // Q02 is skipped due precondition + $this::assertSame($testSession->getRoute()->current()->getAssessmentItemRef()->getIdentifier(), 'Q03'); + } + + public function testTestPartPreConditionOnLinearTestWorks(): void + { + $testSession = self::instantiate(self::samplesDir() . 'custom/runtime/preconditions/preconditions_on_test_part_prevails_linear.xml'); + $testSession->beginTestSession(); + $testSession->beginAttempt(); + $testSession->moveNext(); + + // P02, S02, Q02 is skipped due precondition + $this::assertSame($testSession->getRoute()->current()->getTestPart()->getIdentifier(), 'P03'); + $this::assertSame($testSession->getRoute()->current()->getAssessmentSection()->getIdentifier(), 'S03'); + $this::assertSame($testSession->getRoute()->current()->getAssessmentItemRef()->getIdentifier(), 'Q03'); + } } diff --git a/test/samples/custom/runtime/preconditions/preconditions_on_section_prevails_linear.xml b/test/samples/custom/runtime/preconditions/preconditions_on_section_prevails_linear.xml new file mode 100644 index 000000000..eb5a39667 --- /dev/null +++ b/test/samples/custom/runtime/preconditions/preconditions_on_section_prevails_linear.xml @@ -0,0 +1,20 @@ + + + + + + + + + false + + + + + + + + diff --git a/test/samples/custom/runtime/preconditions/preconditions_on_test_part_prevails_linear.xml b/test/samples/custom/runtime/preconditions/preconditions_on_test_part_prevails_linear.xml new file mode 100644 index 000000000..9902444d1 --- /dev/null +++ b/test/samples/custom/runtime/preconditions/preconditions_on_test_part_prevails_linear.xml @@ -0,0 +1,24 @@ + + + + + + + + + + false + + + + + + + + + + +