From 2c71daacfe0a4d84e544bf6bb1be414cef7f4238 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Mon, 27 May 2019 13:58:51 +1200 Subject: [PATCH] MINOR: Add tests for GroupedDropdownField empty strings These bugs were never present in SS4 as the relevant code had a substantial rewrite at the same time they were introduced in SS3. In SS3, test C still fails. Fixes #4705 Fixes #4987 Fixes #4793 --- tests/php/Forms/GroupedDropdownFieldTest.php | 90 +++++++++++++++++--- 1 file changed, 80 insertions(+), 10 deletions(-) diff --git a/tests/php/Forms/GroupedDropdownFieldTest.php b/tests/php/Forms/GroupedDropdownFieldTest.php index 104f251c4..2adc2becd 100644 --- a/tests/php/Forms/GroupedDropdownFieldTest.php +++ b/tests/php/Forms/GroupedDropdownFieldTest.php @@ -14,16 +14,16 @@ class GroupedDropdownFieldTest extends SapphireTest $field = GroupedDropdownField::create( 'Test', 'Testing', - array( - "1" => "One", - "Group One" => array( - "2" => "Two", - "3" => "Three" - ), - "Group Two" => array( - "4" => "Four" - ) - ) + [ + "1" => "One", + "Group One" => [ + "2" => "Two", + "3" => "Three" + ], + "Group Two" => [ + "4" => "Four" + ], + ] ); $this->assertEquals(array("1", "2", "3", "4"), $field->getValidValues()); @@ -59,4 +59,74 @@ class GroupedDropdownFieldTest extends SapphireTest $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( + '/