Skip to content

Commit

Permalink
chore: simplify test and cover all cases on a single xml
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielfs7 committed Sep 27, 2023
1 parent 24c9b35 commit 85f9d10
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 61 deletions.
10 changes: 7 additions & 3 deletions src/qtism/runtime/tests/AssessmentTestSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -2441,16 +2441,20 @@ protected function nextRouteItem($ignoreBranchings = false, $ignorePreConditions

// Preconditions on target?
if ($ignorePreConditions === false && $route->valid() === true && ($preConditions = $route->current()->getEffectivePreConditions()) && count($preConditions) > 0 && $this->mustApplyPreConditions() === true) {
$preConditionFailed = false;

for ($i = 0; $i < count($preConditions); $i++) {
$engine = new ExpressionEngine($preConditions[$i]->getExpression(), $this);
$condition = $engine->process();

if ($condition !== null && $condition->getValue() === true) {
// The item must be presented.
$stop = true;
if ($condition === null || $condition->getValue() === false) {
// The item must NOT be presented.
$preConditionFailed = true;
break;
}
}

$stop = !$preConditionFailed;
} else {
$stop = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,27 +164,29 @@ public function testKillerTestEpicWin(): void
$this::assertFalse($testSession->isRunning());
}

public function testSectionPreConditionOnLinearTestWorks(): void
public function testTestParAndSectionAndItemPreConditionOnLinearTestWorks(): void
{
$testSession = self::instantiate(self::samplesDir() . 'custom/runtime/preconditions/preconditions_on_section_prevails_linear.xml');
$testSession = self::instantiate(self::samplesDir() . 'custom/runtime/preconditions/preconditions_on_test_part_section_item_combined_linear.xml');
$testSession->beginTestSession();
$testSession->beginAttempt();
$testSession->moveNext();

// Q02 is skipped due precondition
$this::assertSame($testSession->getRoute()->current()->getAssessmentItemRef()->getIdentifier(), 'Q03');
}
// P02, S03, Q04 are skipped due precondition, but Q04.1 is passed
$this::assertSame($testSession->getRoute()->current()->getAssessmentItemRef()->getIdentifier(), 'Q04.1');

$testSession->moveNext();

// P05 precondition passed
$this::assertSame($testSession->getRoute()->current()->getAssessmentItemRef()->getIdentifier(), 'Q05');

$testSession->moveNext();

// S06 precondition passed
$this::assertSame($testSession->getRoute()->current()->getAssessmentItemRef()->getIdentifier(), 'Q06');

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');
// S07 precondition passed
$this::assertSame($testSession->getRoute()->current()->getAssessmentItemRef()->getIdentifier(), 'Q07');
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?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="preconditions" title="Preconditions">
<testPart identifier="P01" navigationMode="linear" submissionMode="individual">
<assessmentSection identifier="S01" title="Section1" visible="true">
<assessmentItemRef identifier="Q01" href="./Q01.xml" timeDependent="false"/>
</assessmentSection>
</testPart>
<!-- All will be skipped due pre-conditions -->
<testPart identifier="P02" navigationMode="linear" submissionMode="individual">
<preCondition>
<baseValue baseType="boolean">false</baseValue>
</preCondition>
<assessmentSection identifier="S02" title="Section2" visible="true">
<assessmentItemRef identifier="Q02" href="./Q02.xml" timeDependent="false"/>
</assessmentSection>
</testPart>
<!-- All will be skipped due pre-conditions -->
<testPart identifier="P03" navigationMode="linear" submissionMode="individual">
<assessmentSection identifier="S03" title="Section3" visible="true">
<preCondition>
<baseValue baseType="boolean">false</baseValue>
</preCondition>
<assessmentItemRef identifier="Q03" href="./Q03.xml" timeDependent="false">
</assessmentItemRef>
</assessmentSection>
</testPart>
<!-- Q04 Will be skipped due pre-conditions -->
<testPart identifier="P04" navigationMode="linear" submissionMode="individual">
<preCondition>
<baseValue baseType="boolean">true</baseValue>
</preCondition>
<assessmentSection identifier="S04" title="Section4" visible="true">
<preCondition>
<baseValue baseType="boolean">true</baseValue>
</preCondition>
<assessmentItemRef identifier="Q04" href="./Q04.xml" timeDependent="false">
<preCondition>
<baseValue baseType="boolean">false</baseValue>
</preCondition>
</assessmentItemRef>
<assessmentItemRef identifier="Q04.1" href="./Q04.1.xml" timeDependent="false">
<preCondition>
<baseValue baseType="boolean">true</baseValue>
</preCondition>
</assessmentItemRef>
</assessmentSection>
</testPart>
<!-- Will be accessed due pre-conditions -->
<testPart identifier="P05" navigationMode="linear" submissionMode="individual">
<preCondition>
<baseValue baseType="boolean">true</baseValue>
</preCondition>
<assessmentSection identifier="S05" title="Section5" visible="true">
<assessmentItemRef identifier="Q05" href="./Q05.xml" timeDependent="false"/>
</assessmentSection>
</testPart>
<!-- Will be accessed due pre-conditions -->
<testPart identifier="P06" navigationMode="linear" submissionMode="individual">
<assessmentSection identifier="S06" title="Section6" visible="true">
<preCondition>
<baseValue baseType="boolean">true</baseValue>
</preCondition>
<assessmentItemRef identifier="Q06" href="./Q06.xml" timeDependent="false"/>
</assessmentSection>
</testPart>
<!-- Will be accessed due pre-conditions -->
<testPart identifier="P07" navigationMode="linear" submissionMode="individual">
<assessmentSection identifier="S07" title="Section7" visible="true">
<assessmentItemRef identifier="Q07" href="./Q07.xml" timeDependent="false">
<preCondition>
<baseValue baseType="boolean">true</baseValue>
</preCondition>
</assessmentItemRef>
</assessmentSection>
</testPart>
</assessmentTest>

0 comments on commit 85f9d10

Please sign in to comment.