Skip to content

Commit

Permalink
Merge pull request #397 from oat-sa/fix/6169/disable-vilidation-for-x…
Browse files Browse the repository at this point in the history
…tml-format

fix: not validate maxWords for XHTML extendTextInteractions
  • Loading branch information
wazelin authored Jun 20, 2024
2 parents 95347ec + 2487ac3 commit a40ea3f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
operating-system: [ ubuntu-latest ]
php-versions: [ '7.4', '8.0', '8.1']
php-versions: [ '7.4', '8.0', '8.1', '8.2', '8.3']

steps:
- uses: actions/checkout@v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,13 @@ public function getResponseValidityConstraint(): ResponseValidityConstraint
$this->getResponseIdentifier(),
$this->getMinStrings(),
($this->hasMaxStrings() === false) ? 0 : $this->getMaxStrings(),
$this->getPatternMask()
$this->getPatternMask(),
[
'qtiClassName' => $this->getQtiClassName(),
'options' => [
'format' => $this->getFormat(),
],
]
);
}

Expand Down
24 changes: 22 additions & 2 deletions src/qtism/data/state/ResponseValidityConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,38 @@ class ResponseValidityConstraint extends QtiComponent

/**
* The collection of nested AssociationValidityConstraints objects.
*
* @var AssociationValidityConstraintCollection
*/
private $associationValidityConstraints;

/**
* Metadata defined by @see \qtism\data\content\interactions\Interaction instantiating this ResponseValidityConstraint
*/
private $extraData = [];

/**
* Create a new ResponseValidityConstraint object.
*
* If the $patternMask attribute is provided, it represent a constraint to be applied on all string
* If the $patternMask attribute is provided, it represents a constraint to be applied on all string
* values contained by the variable described in the $responseÏdentifier variable.
*
* @param string $responseIdentifier The identifier of the response the validity constraint applies to.
* @param int $minConstraint The minimum cardinality the value to be set to the response must have.
* @param int $maxConstraint The maximum cardinality the value to be set the response must have.
* @param string $patternMask (optional) A XML Schema regular expression.
* @param array $extraData (optional) Metadata defined by the Interaction instantiating this ResponseValidityConstraint
* @see \qtism\data\content\interactions\Interaction
* @throws InvalidArgumentException If one or more of the arguments above are invalid.
*/
public function __construct($responseIdentifier, $minConstraint, $maxConstraint, $patternMask = '')
public function __construct($responseIdentifier, $minConstraint, $maxConstraint, $patternMask = '', $extraData = [])
{
$this->setResponseIdentifier($responseIdentifier);
$this->setMinConstraint($minConstraint);
$this->setMaxConstraint($maxConstraint);
$this->setPatternMask($patternMask);
$this->setAssociationValidityConstraints(new AssociationValidityConstraintCollection());
$this->setExtraData($extraData);
}

/**
Expand Down Expand Up @@ -278,4 +288,14 @@ public function getComponents(): QtiComponentCollection
$this->getAssociationValidityConstraints()->getArrayCopy()
);
}

public function getExtraData(): array
{
return $this->extraData;
}

public function setExtraData(array $extraData)
{
$this->extraData = $extraData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,10 @@ public function testSetFormatWrongType(): void

$extendedTextInteraction->setFormat(999);
}

public function testExtraDataIsProvidedForValidityConstrains(): void
{
$extendedTextInteraction = new ExtendedTextInteraction('RESPONSE');
$this::assertNotEmpty($extendedTextInteraction->getResponseValidityConstraint()->getExtraData());
}
}
8 changes: 8 additions & 0 deletions test/qtismtest/data/state/ResponseValidityConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,12 @@ public function testAssociations(): void
$this::assertCount(1, $responseValidityConstraint->getAssociationValidityConstraints());
$this::assertEquals('MYID', $responseValidityConstraint->getAssociationValidityConstraints()[0]->getIdentifier());
}

public function testExtraDataCouldBeProvidedToConstrain(): void
{
$responseValidityConstraint = new ResponseValidityConstraint('RESPONSE', 0, 0, 'patternMask', ['qtiClassName' => 'test']);
$extraData = $responseValidityConstraint->getExtraData();
$this->assertNotEmpty($extraData);
$this::assertEquals('test', $extraData['qtiClassName']);
}
}

0 comments on commit a40ea3f

Please sign in to comment.