mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Allow multi-line enum declarations
This commit is contained in:
parent
193fc9e469
commit
1974e79d71
@ -38,7 +38,7 @@ class Enum extends StringField {
|
||||
public function __construct($name = null, $enum = NULL, $default = NULL) {
|
||||
if($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;
|
||||
|
@ -16,4 +16,26 @@ class EnumFieldTest extends SapphireTest {
|
||||
$this->assertEquals(true, $searchField->getHasEmptyDefault());
|
||||
$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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user