mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge branch '4.11' into 4.12-release
This commit is contained in:
commit
8bb712a461
@ -126,7 +126,7 @@ class DBDecimal extends DBField
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ctype_digit((string) $value)) {
|
||||
if (abs((float) $value - (int) $value) < PHP_FLOAT_EPSILON) {
|
||||
return (int)$value;
|
||||
}
|
||||
|
||||
|
@ -355,7 +355,7 @@ class SSViewer_DataPresenter extends SSViewer_Scope
|
||||
// Check if the method to-be-called exists on the target object - if so, don't check any further
|
||||
// injection locations
|
||||
$on = $this->itemIterator ? $this->itemIterator->current() : $this->item;
|
||||
if (isset($on->$property) || method_exists($on, $property ?? '')) {
|
||||
if ($on && (isset($on->$property) || method_exists($on, $property ?? ''))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -61,6 +61,35 @@ class DecimalTest extends SapphireTest
|
||||
);
|
||||
}
|
||||
|
||||
public function testLongValueStoredCorrectly()
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->testDataObject->MyDecimal5,
|
||||
1.0,
|
||||
'Long default long decimal value is rounded correctly'
|
||||
);
|
||||
|
||||
$this->assertEqualsWithDelta(
|
||||
$this->testDataObject->MyDecimal5,
|
||||
0.99999999999999999999,
|
||||
PHP_FLOAT_EPSILON,
|
||||
'Long default long decimal value is correct within float epsilon'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$this->testDataObject->MyDecimal6,
|
||||
8.0,
|
||||
'Long decimal value with a default value is rounded correctly'
|
||||
);
|
||||
|
||||
$this->assertEqualsWithDelta(
|
||||
$this->testDataObject->MyDecimal6,
|
||||
7.99999999999999999999,
|
||||
PHP_FLOAT_EPSILON,
|
||||
'Long decimal value is within epsilon if longer than allowed number of float digits'
|
||||
);
|
||||
}
|
||||
|
||||
public function testScaffoldFormField()
|
||||
{
|
||||
/** @var DBDecimal $decimal */
|
||||
|
@ -14,10 +14,13 @@ class TestObject extends DataObject implements TestOnly
|
||||
'MyDecimal1' => 'Decimal',
|
||||
'MyDecimal2' => 'Decimal(5,3,2.5)',
|
||||
'MyDecimal3' => 'Decimal(4,2,"Invalid default value")',
|
||||
'MyDecimal4' => 'Decimal'
|
||||
'MyDecimal4' => 'Decimal',
|
||||
'MyDecimal5' => 'Decimal(20,18,0.99999999999999999999)',
|
||||
'MyDecimal6' => 'Decimal',
|
||||
];
|
||||
|
||||
private static $defaults = [
|
||||
'MyDecimal4' => 4
|
||||
'MyDecimal4' => 4,
|
||||
'MyDecimal6' => 7.99999999999999999999,
|
||||
];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user