silverstripe-framework/tests/forms/TextFieldTest.php
Damian Mooyman 8dd644d25d
API Namespace all classes
Namespace all templates
Move difflib and BBCodeParser2 to thirdparty
Remove deprecated API marked for removal in 4.0
2016-09-08 10:23:17 +12:00

35 lines
902 B
PHP

<?php
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\RequiredFields;
/**
* @package framework
* @subpackage tests
*/
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);
}
}