mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX Parse Enums with dots in their values
This commit is contained in:
parent
e812999632
commit
8e803bbcfc
@ -3150,7 +3150,10 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
list($class, $spec) = explode('.', $helper);
|
$pos = strpos($helper, '.');
|
||||||
|
$class = substr($helper, 0, $pos);
|
||||||
|
$spec = substr($helper, $pos + 1);
|
||||||
|
|
||||||
/** @var DBField $obj */
|
/** @var DBField $obj */
|
||||||
$table = $schema->tableName($class);
|
$table = $schema->tableName($class);
|
||||||
$obj = Injector::inst()->create($spec, $fieldName);
|
$obj = Injector::inst()->create($spec, $fieldName);
|
||||||
|
@ -2622,4 +2622,15 @@ class DataObjectTest extends SapphireTest
|
|||||||
'Salary' => 50,
|
'Salary' => 50,
|
||||||
], DataObject::CREATE_HYDRATED);
|
], DataObject::CREATE_HYDRATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDBObjectEnum()
|
||||||
|
{
|
||||||
|
$obj = new DataObjectTest\Fixture();
|
||||||
|
// enums are parsed correctly
|
||||||
|
$vals = ['25', '50', '75', '100'];
|
||||||
|
$this->assertSame(array_combine($vals, $vals), $obj->dbObject('MyEnum')->enumValues());
|
||||||
|
// enum with dots in their values are also parsed correctly
|
||||||
|
$vals = ['25.25', '50.00', '75.00', '100.50'];
|
||||||
|
$this->assertSame(array_combine($vals, $vals), $obj->dbObject('MyEnumWithDots')->enumValues());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,10 @@ class Fixture extends DataObject implements TestOnly
|
|||||||
'MyInt' => 'Int',
|
'MyInt' => 'Int',
|
||||||
'MyCurrency' => 'Currency',
|
'MyCurrency' => 'Currency',
|
||||||
'MyDecimal'=> 'Decimal',
|
'MyDecimal'=> 'Decimal',
|
||||||
|
|
||||||
|
// Enums
|
||||||
|
'MyEnum' => 'Enum("25,50,75,100", "50")',
|
||||||
|
'MyEnumWithDots' => 'Enum("25.25,50.00,75.00,100.50", "50.00")',
|
||||||
];
|
];
|
||||||
|
|
||||||
private static $defaults = [
|
private static $defaults = [
|
||||||
|
Loading…
Reference in New Issue
Block a user