Merge pull request #4684 from dhensby/pulls/multiline-enum

Allow multi-line enum declarations
This commit is contained in:
Damian Mooyman 2015-10-16 09:45:34 +13:00
commit f5f2861dc5
2 changed files with 23 additions and 1 deletions

View File

@ -38,7 +38,7 @@ class Enum extends StringField {
public function __construct($name = null, $enum = NULL, $default = NULL) { public function __construct($name = null, $enum = NULL, $default = NULL) {
if($enum) { if($enum) {
if(!is_array($enum)) { if(!is_array($enum)) {
$enum = preg_split("/ *, */", trim($enum)); $enum = preg_split("/\s*,\s*/", trim($enum, ", \t\n\r\0\x0B"));
} }
$this->enum = $enum; $this->enum = $enum;

View File

@ -16,4 +16,26 @@ class EnumFieldTest extends SapphireTest {
$this->assertEquals(true, $searchField->getHasEmptyDefault()); $this->assertEquals(true, $searchField->getHasEmptyDefault());
$this->assertEquals($anyText, $searchField->getEmptyString()); $this->assertEquals($anyText, $searchField->getEmptyString());
} }
public function testEnumParsing() {
$enum = new Enum('testField', "
Item1,
Item2,
Item 3,
Item-4,
item 5
still 5,
trailing comma,
");
$this->assertEquals(ArrayLib::valuekey(array(
'Item1',
'Item2',
'Item 3',
'Item-4',
'item 5
still 5',
'trailing comma'
)), $enum->enumValues());
}
} }