2018-03-23 04:18:32 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
|
|
|
|
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\UserForms\Model\EditableFormField\EditableNumericField;
|
|
|
|
|
|
|
|
class EditableNumericFieldTest extends SapphireTest
|
|
|
|
{
|
|
|
|
public function testAllowEmptyTitle()
|
|
|
|
{
|
|
|
|
/** @var EditableNumericField $field */
|
|
|
|
$field = EditableNumericField::create();
|
|
|
|
$field->Name = 'EditableFormField_123456';
|
|
|
|
$this->assertEmpty($field->getFormField()->Title());
|
|
|
|
}
|
2019-01-16 21:59:02 +01:00
|
|
|
|
|
|
|
public function testValidateAddsErrorWhenMinValueIsGreaterThanMaxValue()
|
|
|
|
{
|
|
|
|
/** @var EditableNumericField $field */
|
|
|
|
$field = EditableNumericField::create();
|
|
|
|
$field->MinValue = 10;
|
|
|
|
$field->MaxValue = 5;
|
|
|
|
|
|
|
|
$result = $field->validate();
|
|
|
|
$this->assertFalse($result->isValid(), 'Validation should fail when min is greater than max');
|
2022-11-28 21:36:08 +01:00
|
|
|
$this->assertStringContainsString('Minimum length should be less than the maximum length', json_encode($result->__serialize()));
|
2019-01-16 21:59:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testValidate()
|
|
|
|
{
|
|
|
|
/** @var EditableNumericField $field */
|
|
|
|
$field = EditableNumericField::create();
|
|
|
|
$field->MinValue = 5;
|
|
|
|
$field->MaxValue = 10;
|
|
|
|
|
|
|
|
$result = $field->validate();
|
|
|
|
$this->assertTrue($result->isValid());
|
|
|
|
}
|
2018-03-23 04:18:32 +01:00
|
|
|
}
|