From d89c1ab5a44ab382c1477b1f5510c35f670d6ff0 Mon Sep 17 00:00:00 2001 From: Vitalii Shtykhno Date: Thu, 6 Jun 2024 13:58:32 +0200 Subject: [PATCH] fix: provide ability to disable maxword validation --- .../interactions/ExtendedTextInteraction.php | 31 ++++++++++++++++--- .../ExtendedTextInteractionTest.php | 20 ++++++++++++ 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/qtism/data/content/interactions/ExtendedTextInteraction.php b/src/qtism/data/content/interactions/ExtendedTextInteraction.php index 8a0446ecb..2ab8c7a31 100644 --- a/src/qtism/data/content/interactions/ExtendedTextInteraction.php +++ b/src/qtism/data/content/interactions/ExtendedTextInteraction.php @@ -162,6 +162,9 @@ class ExtendedTextInteraction extends BlockInteraction implements StringInteract */ private $format = TextFormat::PLAIN; + // This option disable also validation for patternMask + private $isDisabledMaxWordValidation = false; + /** * Create a new ExtendedTextInteraction object. * @@ -313,7 +316,7 @@ public function setPatternMask($patternMask): void */ public function getPatternMask(): string { - return $this->patternMask; + return !$this->isDisabledMaxWordValidation() ? $this->patternMask : ''; } /** @@ -323,7 +326,7 @@ public function getPatternMask(): string */ public function hasPatternMask(): bool { - return $this->getPatternMask() !== ''; + return !$this->isDisabledMaxWordValidation() && $this->getPatternMask() !== ''; } /** @@ -389,7 +392,7 @@ public function setMaxStrings($maxStrings): void */ public function getMaxStrings(): int { - return $this->maxStrings; + return !$this->isDisabledMaxWordValidation() ? $this->maxStrings : -1; } /** @@ -399,7 +402,7 @@ public function getMaxStrings(): int */ public function hasMaxStrings(): bool { - return $this->getMaxStrings() !== -1; + return !$this->isDisabledMaxWordValidation() && $this->getMaxStrings() !== -1; } /** @@ -505,7 +508,7 @@ public function getResponseValidityConstraint(): ResponseValidityConstraint $this->getResponseIdentifier(), $this->getMinStrings(), ($this->hasMaxStrings() === false) ? 0 : $this->getMaxStrings(), - $this->getPatternMask() + ($this->isDisabledMaxWordValidation() == false) ? $this->getPatternMask() : '', ); } @@ -524,4 +527,22 @@ public function getQtiClassName(): string { return 'extendedTextInteraction'; } + + /** + * This option disable also validation for patternMask + */ + public function isDisabledMaxWordValidation(): bool + { + return $this->isDisabledMaxWordValidation; + } + + public function setIsDisabledMaxWordValidation(bool $isDisabledMaxWordValidation): void + { + $this->isDisabledMaxWordValidation = $isDisabledMaxWordValidation; + } + + public function disabledMaxWordValidation(): void + { + $this->setIsDisabledMaxWordValidation(true); + } } diff --git a/test/qtismtest/data/content/interactions/ExtendedTextInteractionTest.php b/test/qtismtest/data/content/interactions/ExtendedTextInteractionTest.php index 7270ddba1..5d119bd56 100644 --- a/test/qtismtest/data/content/interactions/ExtendedTextInteractionTest.php +++ b/test/qtismtest/data/content/interactions/ExtendedTextInteractionTest.php @@ -85,6 +85,16 @@ public function testSetPatternMaskWrongType(): void $extendedTextInteraction->setPatternMask(true); } + public function testPatternMaskIgnoredForDisabledValidation(): void + { + $extendedTextInteraction = new ExtendedTextInteraction('RESPONSE'); + $extendedTextInteraction->setPatternMask('pattern'); + $extendedTextInteraction->disabledMaxWordValidation(); + + $this->assertEmpty($extendedTextInteraction->getPatternMask()); + $this->assertFalse($extendedTextInteraction->hasPatternMask()); + } + public function testSetPlaceholderTextWrongType(): void { $extendedTextInteraction = new ExtendedTextInteraction('RESPONSE'); @@ -105,6 +115,16 @@ public function testSetMaxStringsWrongType(): void $extendedTextInteraction->setMaxStrings(true); } + public function testMaxStringsIgnoredForDisableValidation(): void + { + $extendedTextInteraction = new ExtendedTextInteraction('RESPONSE'); + $extendedTextInteraction->setMaxStrings(10); + $extendedTextInteraction->disabledMaxWordValidation(); + + $this->assertEquals(-1, $extendedTextInteraction->getMaxStrings()); + $this->assertFalse($extendedTextInteraction->hasMaxStrings()); + } + public function testSetMinStringsWrongType(): void { $extendedTextInteraction = new ExtendedTextInteraction('RESPONSE');