mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR: Add tests for GroupedDropdownField empty strings (#9015)
MINOR: Add tests for GroupedDropdownField empty strings
This commit is contained in:
commit
a01e2496e5
@ -14,16 +14,16 @@ class GroupedDropdownFieldTest extends SapphireTest
|
|||||||
$field = GroupedDropdownField::create(
|
$field = GroupedDropdownField::create(
|
||||||
'Test',
|
'Test',
|
||||||
'Testing',
|
'Testing',
|
||||||
array(
|
[
|
||||||
"1" => "One",
|
"1" => "One",
|
||||||
"Group One" => array(
|
"Group One" => [
|
||||||
"2" => "Two",
|
"2" => "Two",
|
||||||
"3" => "Three"
|
"3" => "Three"
|
||||||
),
|
],
|
||||||
"Group Two" => array(
|
"Group Two" => [
|
||||||
"4" => "Four"
|
"4" => "Four"
|
||||||
)
|
],
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(array("1", "2", "3", "4"), $field->getValidValues());
|
$this->assertEquals(array("1", "2", "3", "4"), $field->getValidValues());
|
||||||
@ -59,4 +59,74 @@ class GroupedDropdownFieldTest extends SapphireTest
|
|||||||
|
|
||||||
$this->assertFalse($field->validate($validator));
|
$this->assertFalse($field->validate($validator));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that empty-string values are supported by GroupDropdownTest
|
||||||
|
*/
|
||||||
|
public function testEmptyString()
|
||||||
|
{
|
||||||
|
// Case A: empty value in the top level of the source
|
||||||
|
$field = GroupedDropdownField::create(
|
||||||
|
'Test',
|
||||||
|
'Testing',
|
||||||
|
[
|
||||||
|
"" => "(Choose A)",
|
||||||
|
"1" => "One",
|
||||||
|
"Group One" => [
|
||||||
|
"2" => "Two",
|
||||||
|
"3" => "Three"
|
||||||
|
],
|
||||||
|
"Group Two" => [
|
||||||
|
"4" => "Four"
|
||||||
|
],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertRegExp(
|
||||||
|
'/<option value="" selected="selected" >\(Choose A\)<\/option>/',
|
||||||
|
preg_replace('/\s+/', ' ', (string)$field->Field())
|
||||||
|
);
|
||||||
|
|
||||||
|
// Case B: empty value in the nested level of the source
|
||||||
|
$field = GroupedDropdownField::create(
|
||||||
|
'Test',
|
||||||
|
'Testing',
|
||||||
|
[
|
||||||
|
"1" => "One",
|
||||||
|
"Group One" => [
|
||||||
|
"" => "(Choose B)",
|
||||||
|
"2" => "Two",
|
||||||
|
"3" => "Three"
|
||||||
|
],
|
||||||
|
"Group Two" => [
|
||||||
|
"4" => "Four"
|
||||||
|
],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$this->assertRegExp(
|
||||||
|
'/<option value="" selected="selected" >\(Choose B\)<\/option>/',
|
||||||
|
preg_replace('/\s+/', ' ', (string)$field->Field())
|
||||||
|
);
|
||||||
|
|
||||||
|
// Case C: setEmptyString
|
||||||
|
$field = GroupedDropdownField::create(
|
||||||
|
'Test',
|
||||||
|
'Testing',
|
||||||
|
[
|
||||||
|
"1" => "One",
|
||||||
|
"Group One" => [
|
||||||
|
"2" => "Two",
|
||||||
|
"3" => "Three"
|
||||||
|
],
|
||||||
|
"Group Two" => [
|
||||||
|
"4" => "Four"
|
||||||
|
],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$field->setEmptyString('(Choose C)');
|
||||||
|
$this->assertRegExp(
|
||||||
|
'/<option value="" selected="selected" >\(Choose C\)<\/option>/',
|
||||||
|
preg_replace('/\s+/', ' ', (string)$field->Field())
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user