Merge pull request #10005 from creative-commoners/pulls/4.8/10k

FIX Parse Enums with dots in their values
This commit is contained in:
Ingo Schommer 2021-07-02 09:33:29 +12:00 committed by GitHub
commit e8c14a9d5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

View File

@ -3150,7 +3150,10 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
return $value;
}
list($class, $spec) = explode('.', $helper);
$pos = strpos($helper, '.');
$class = substr($helper, 0, $pos);
$spec = substr($helper, $pos + 1);
/** @var DBField $obj */
$table = $schema->tableName($class);
$obj = Injector::inst()->create($spec, $fieldName);

View File

@ -2622,4 +2622,15 @@ class DataObjectTest extends SapphireTest
'Salary' => 50,
], 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());
}
}

View File

@ -25,6 +25,10 @@ class Fixture extends DataObject implements TestOnly
'MyInt' => 'Int',
'MyCurrency' => 'Currency',
'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 = [