From 9ba26a04c4d7c050022b13505023a58634197fa8 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Mon, 22 Apr 2013 11:50:57 +1200 Subject: [PATCH] Added test for lazy-loading edge-case in Money field. --- tests/model/MoneyTest.php | 16 ++++++++++++++++ tests/model/MoneyTest.yml | 6 +++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/model/MoneyTest.php b/tests/model/MoneyTest.php index 9b8bfc92d..f9a547cc6 100644 --- a/tests/model/MoneyTest.php +++ b/tests/model/MoneyTest.php @@ -17,6 +17,7 @@ class MoneyTest extends SapphireTest { protected $extraDataObjects = array( 'MoneyTest_DataObject', + 'MoneyTest_SubClass', ); public function testMoneyFieldsReturnedAsObjects() { @@ -268,6 +269,15 @@ class MoneyTest extends SapphireTest { ))->value() ); } + + public function testMoneyLazyLoading() { + // Get the object, ensuring that MyOtherMoney will be lazy loaded + $id = $this->idFromFixture('MoneyTest_SubClass', 'test2'); + $obj = MoneyTest_DataObject::get()->byID($id); + + $this->assertEquals('£2.46', $obj->obj('MyOtherMoney')->Nice()); + } + } class MoneyTest_DataObject extends DataObject implements TestOnly { @@ -277,3 +287,9 @@ class MoneyTest_DataObject extends DataObject implements TestOnly { ); } +class MoneyTest_SubClass extends MoneyTest_DataObject implements TestOnly { + static $db = array( + 'MyOtherMoney' => 'Money', + ); + +} diff --git a/tests/model/MoneyTest.yml b/tests/model/MoneyTest.yml index 1e49e6e35..816f4f9e3 100644 --- a/tests/model/MoneyTest.yml +++ b/tests/model/MoneyTest.yml @@ -1,4 +1,8 @@ MoneyTest_DataObject: test1: MyMoneyCurrency: EUR - MyMoneyAmount: 1.23 \ No newline at end of file + MyMoneyAmount: 1.23 +MoneyTest_SubClass: + test2: + MyOtherMoneyCurrency: GBP + MyOtherMoneyAmount: 2.46 \ No newline at end of file