added maxLength validation tests

This commit is contained in:
Rastislav Brandobur 2023-08-30 10:56:21 +02:00
parent d6c39e7d36
commit 7ae7e9ff47

View File

@ -4,6 +4,7 @@ namespace SilverStripe\Forms\Tests;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\TextareaField;
use SilverStripe\Forms\RequiredFields;
class TextareaFieldTest extends SapphireTest
{
@ -50,6 +51,30 @@ class TextareaFieldTest extends SapphireTest
);
}
/**
* Tests the TextareaField Max Length Validation Failure
*/
public function testMaxLengthValidationFail()
{
$field = new TextareaField("Test", "Test");
$field->setMaxLength(5);
$field->setValue("John Doe"); // 8 characters, so should fail
$result = $field->validate(new RequiredFields());
$this->assertFalse($result);
}
/**
* Tests the TextareaField Max Length Validation Success
*/
public function testMaxLengthValidationSuccess()
{
$field = new TextareaField("Test", "Test");
$field->setMaxLength(5);
$field->setValue("John"); // 4 characters, so should pass
$result = $field->validate(new RequiredFields());
$this->assertTrue($result);
}
public function testValueEntities()
{
$inputText = "These <b>are</b> some unicodes: äöü";