2010-04-13 04:10:13 +02:00
|
|
|
<?php
|
2016-06-15 06:03:16 +02:00
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\ORM\Tests;
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2017-10-09 23:13:26 +02:00
|
|
|
use SilverStripe\ORM\FieldType\DBDecimal;
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
class DecimalTest extends SapphireTest
|
|
|
|
{
|
|
|
|
|
|
|
|
protected static $fixture_file = 'DecimalTest.yml';
|
|
|
|
|
2017-10-09 23:13:26 +02:00
|
|
|
/**
|
|
|
|
* @var DecimalTest\TestObject
|
|
|
|
*/
|
2016-12-16 05:34:21 +01:00
|
|
|
protected $testDataObject;
|
|
|
|
|
2020-04-20 19:58:09 +02:00
|
|
|
protected static $extra_dataobjects = [
|
2016-12-16 05:34:21 +01:00
|
|
|
DecimalTest\TestObject::class
|
2020-04-20 19:58:09 +02:00
|
|
|
];
|
2016-12-16 05:34:21 +01:00
|
|
|
|
2021-10-27 04:39:47 +02:00
|
|
|
protected function setUp(): void
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$this->testDataObject = $this->objFromFixture(DecimalTest\TestObject::class, 'test-dataobject');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDefaultValue()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
$this->testDataObject->MyDecimal1,
|
|
|
|
0,
|
|
|
|
'Database default for Decimal type is 0'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSpecifiedDefaultValue()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
$this->testDataObject->MyDecimal2,
|
|
|
|
2.5,
|
|
|
|
'Default value for Decimal type is set to 2.5'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvalidSpecifiedDefaultValue()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
$this->testDataObject->MyDecimal3,
|
|
|
|
0,
|
|
|
|
'Invalid default value for Decimal type is casted to 0'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSpecifiedDefaultValueInDefaultsArray()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
$this->testDataObject->MyDecimal4,
|
|
|
|
4,
|
|
|
|
'Default value for Decimal type is set to 4'
|
|
|
|
);
|
|
|
|
}
|
2017-10-09 23:13:26 +02:00
|
|
|
|
|
|
|
public function testScaffoldFormField()
|
|
|
|
{
|
|
|
|
/** @var DBDecimal $decimal */
|
|
|
|
$decimal = $this->testDataObject->dbObject('MyDecimal2');
|
|
|
|
$field = $decimal->scaffoldFormField('The Decimal');
|
|
|
|
$this->assertEquals(3, $field->getScale());
|
|
|
|
$field->setValue(1.9999);
|
|
|
|
$this->assertEquals(1.9999, $field->dataValue());
|
|
|
|
$this->assertEquals('2.000', $field->Value());
|
|
|
|
}
|
2010-04-13 04:10:13 +02:00
|
|
|
}
|