2010-04-13 04:10:13 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2010-04-13 04:10:13 +02:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class DecimalTest extends SapphireTest {
|
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
protected static $fixture_file = 'DecimalTest.yml';
|
2010-04-13 04:10:13 +02:00
|
|
|
|
|
|
|
protected $testDataObject;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-04-13 04:10:13 +02:00
|
|
|
protected $extraDataObjects = array(
|
|
|
|
'DecimalTest_DataObject'
|
|
|
|
);
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
$this->testDataObject = $this->objFromFixture('DecimalTest_DataObject', 'test-dataobject');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDefaultValue() {
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertEquals($this->testDataObject->MyDecimal1, 0,
|
|
|
|
'Database default for Decimal type is 0');
|
2010-04-13 04:10:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSpecifiedDefaultValue() {
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertEquals($this->testDataObject->MyDecimal2, 2.5,
|
|
|
|
'Default value for Decimal type is set to 2.5');
|
2010-04-13 04:10:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvalidSpecifiedDefaultValue() {
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertEquals($this->testDataObject->MyDecimal3, 0,
|
|
|
|
'Invalid default value for Decimal type is casted to 0');
|
2010-04-13 04:10:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSpecifiedDefaultValueInDefaultsArray() {
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertEquals($this->testDataObject->MyDecimal4, 4,
|
|
|
|
'Default value for Decimal type is set to 4');
|
2010-04-13 04:10:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2010-04-13 04:10:13 +02:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class DecimalTest_DataObject extends DataObject implements TestOnly {
|
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $db = array(
|
2010-04-13 04:10:13 +02:00
|
|
|
'Name' => 'Varchar',
|
|
|
|
'MyDecimal1' => 'Decimal',
|
|
|
|
'MyDecimal2' => 'Decimal(5,3,2.5)',
|
|
|
|
'MyDecimal3' => 'Decimal(4,2,"Invalid default value")',
|
|
|
|
'MyDecimal4' => 'Decimal'
|
|
|
|
);
|
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $defaults = array(
|
2010-04-13 04:10:13 +02:00
|
|
|
'MyDecimal4' => 4
|
|
|
|
);
|
|
|
|
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|