Allow multi-line enum declarations

This commit is contained in:
Daniel Hensby 2015-10-15 15:18:32 +01:00
parent 193fc9e469
commit 1974e79d71
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());
}
} }