2015-05-16 01:46:54 +02:00
|
|
|
<?php
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\Forms\Tests;
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\Forms\TextField;
|
|
|
|
use SilverStripe\Forms\RequiredFields;
|
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
class TextFieldTest extends SapphireTest
|
|
|
|
{
|
2015-05-16 01:46:54 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
2015-05-16 01:46:54 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
2015-05-16 01:46:54 +02:00
|
|
|
}
|