diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index 86b72f0b9..740c52797 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -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 diff --git a/src/qtism/data/content/interactions/ExtendedTextInteraction.php b/src/qtism/data/content/interactions/ExtendedTextInteraction.php index 8a0446ecb..c13864bc5 100644 --- a/src/qtism/data/content/interactions/ExtendedTextInteraction.php +++ b/src/qtism/data/content/interactions/ExtendedTextInteraction.php @@ -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(), + ], + ] ); } diff --git a/src/qtism/data/state/ResponseValidityConstraint.php b/src/qtism/data/state/ResponseValidityConstraint.php index cb7f42b23..0a093247b 100644 --- a/src/qtism/data/state/ResponseValidityConstraint.php +++ b/src/qtism/data/state/ResponseValidityConstraint.php @@ -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); } /** @@ -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; + } } diff --git a/test/qtismtest/data/content/interactions/ExtendedTextInteractionTest.php b/test/qtismtest/data/content/interactions/ExtendedTextInteractionTest.php index 7270ddba1..9afed13ec 100644 --- a/test/qtismtest/data/content/interactions/ExtendedTextInteractionTest.php +++ b/test/qtismtest/data/content/interactions/ExtendedTextInteractionTest.php @@ -178,4 +178,10 @@ public function testSetFormatWrongType(): void $extendedTextInteraction->setFormat(999); } + + public function testExtraDataIsProvidedForValidityConstrains(): void + { + $extendedTextInteraction = new ExtendedTextInteraction('RESPONSE'); + $this::assertNotEmpty($extendedTextInteraction->getResponseValidityConstraint()->getExtraData()); + } } diff --git a/test/qtismtest/data/state/ResponseValidityConstraintTest.php b/test/qtismtest/data/state/ResponseValidityConstraintTest.php index 9a2904779..4f23eae37 100644 --- a/test/qtismtest/data/state/ResponseValidityConstraintTest.php +++ b/test/qtismtest/data/state/ResponseValidityConstraintTest.php @@ -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']); + } }