mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-02 07:48:00 +02:00
36 lines
986 B
PHP
36 lines
986 B
PHP
<?php
|
|
|
|
namespace SilverStripe\Forms\Tests;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
use SilverStripe\Forms\TextField;
|
|
use SilverStripe\Forms\RequiredFields;
|
|
|
|
class TextFieldTest extends SapphireTest
|
|
{
|
|
|
|
/**
|
|
* Tests the TextField Max Length Validation Failure
|
|
*/
|
|
public function testMaxLengthValidationFail()
|
|
{
|
|
$textField = new TextField('TestField');
|
|
$textField->setMaxLength(5);
|
|
$textField->setValue("John Doe"); // 8 characters, so should fail
|
|
$result = $textField->validate(new RequiredFields());
|
|
$this->assertFalse($result);
|
|
}
|
|
|
|
/**
|
|
* Tests the TextField Max Length Validation Success
|
|
*/
|
|
public function testMaxLengthValidationSuccess()
|
|
{
|
|
$textField = new TextField('TestField');
|
|
$textField->setMaxLength(5);
|
|
$textField->setValue("John"); // 4 characters, so should pass
|
|
$result = $textField->validate(new RequiredFields());
|
|
$this->assertTrue($result);
|
|
}
|
|
}
|