From 334b83dd2337026c3106bd965cef19fefb1f629a Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 13 Apr 2010 02:10:13 +0000 Subject: [PATCH] MINOR Added DecimalTest (merged from 2.4) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102595 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- tests/fieldtypes/DecimalTest.php | 57 ++++++++++++++++++++++++++++++++ tests/fieldtypes/DecimalTest.yml | 3 ++ 2 files changed, 60 insertions(+) create mode 100644 tests/fieldtypes/DecimalTest.php create mode 100644 tests/fieldtypes/DecimalTest.yml diff --git a/tests/fieldtypes/DecimalTest.php b/tests/fieldtypes/DecimalTest.php new file mode 100644 index 000000000..5d9ad7030 --- /dev/null +++ b/tests/fieldtypes/DecimalTest.php @@ -0,0 +1,57 @@ +testDataObject = $this->objFromFixture('DecimalTest_DataObject', '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'); + } + +} + +/** + * @package sapphire + * @subpackage tests + */ +class DecimalTest_DataObject extends DataObject implements TestOnly { + + public static $db = array( + 'Name' => 'Varchar', + 'MyDecimal1' => 'Decimal', + 'MyDecimal2' => 'Decimal(5,3,2.5)', + 'MyDecimal3' => 'Decimal(4,2,"Invalid default value")', + 'MyDecimal4' => 'Decimal' + ); + + public static $defaults = array( + 'MyDecimal4' => 4 + ); + +} \ No newline at end of file diff --git a/tests/fieldtypes/DecimalTest.yml b/tests/fieldtypes/DecimalTest.yml new file mode 100644 index 000000000..99e3fb3a5 --- /dev/null +++ b/tests/fieldtypes/DecimalTest.yml @@ -0,0 +1,3 @@ +DecimalTest_DataObject: + test-dataobject: + Name: test \ No newline at end of file