silverstripe-framework/tests/forms/GroupedDropdownFieldTest.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

61 lines
1.4 KiB
PHP

<?php
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\GroupedDropdownField;
use SilverStripe\Forms\RequiredFields;
/**
* @package framework
* @subpackage tests
*/
class GroupedDropdownFieldTest extends SapphireTest {
public function testValidation() {
$field = GroupedDropdownField::create('Test', 'Testing', array(
"1" => "One",
"Group One" => array(
"2" => "Two",
"3" => "Three"
),
"Group Two" => array(
"4" => "Four"
)
));
$this->assertEquals(array("1", "2", "3", "4"), $field->getValidValues());
$validator = new RequiredFields();
$field->setValue("1");
$this->assertTrue($field->validate($validator));
//test grouped values
$field->setValue("3");
$this->assertTrue($field->validate($validator));
//non-existent value should make the field invalid
$field->setValue("Over 9000");
$this->assertFalse($field->validate($validator));
//empty string shouldn't validate
$field->setValue('');
$this->assertFalse($field->validate($validator));
//empty field should validate after being set
$field->setEmptyString('Empty String');
$field->setValue('');
$this->assertTrue($field->validate($validator));
//disabled items shouldn't validate
$field->setDisabledItems(array('1'));
$field->setValue('1');
$this->assertEquals(array("2", "3", "4"), $field->getValidValues());
$this->assertEquals(array("1"), $field->getDisabledItems());
$this->assertFalse($field->validate($validator));
}
}