Skip to content

Commit

Permalink
fix: provide ability to disable maxword validation
Browse files Browse the repository at this point in the history
  • Loading branch information
kilatib committed Jun 6, 2024
1 parent 95347ec commit d89c1ab
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/qtism/data/content/interactions/ExtendedTextInteraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -313,7 +316,7 @@ public function setPatternMask($patternMask): void
*/
public function getPatternMask(): string
{
return $this->patternMask;
return !$this->isDisabledMaxWordValidation() ? $this->patternMask : '';
}

/**
Expand All @@ -323,7 +326,7 @@ public function getPatternMask(): string
*/
public function hasPatternMask(): bool
{
return $this->getPatternMask() !== '';
return !$this->isDisabledMaxWordValidation() && $this->getPatternMask() !== '';
}

/**
Expand Down Expand Up @@ -389,7 +392,7 @@ public function setMaxStrings($maxStrings): void
*/
public function getMaxStrings(): int
{
return $this->maxStrings;
return !$this->isDisabledMaxWordValidation() ? $this->maxStrings : -1;
}

/**
Expand All @@ -399,7 +402,7 @@ public function getMaxStrings(): int
*/
public function hasMaxStrings(): bool
{
return $this->getMaxStrings() !== -1;
return !$this->isDisabledMaxWordValidation() && $this->getMaxStrings() !== -1;
}

/**
Expand Down Expand Up @@ -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() : '',
);
}

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand Down

0 comments on commit d89c1ab

Please sign in to comment.