diff --git a/forms/MoneyField.php b/forms/MoneyField.php index 77254045a..161a28bef 100644 --- a/forms/MoneyField.php +++ b/forms/MoneyField.php @@ -106,12 +106,12 @@ class MoneyField extends FormField { $fieldName = $this->name; if($dataObject->hasMethod("set$fieldName")) { $dataObject->$fieldName = DBField::create_field('Money', array( - "Currency" => $this->fieldCurrency->Value(), - "Amount" => $this->fieldAmount->Value() + "Currency" => $this->fieldCurrency->dataValue(), + "Amount" => $this->fieldAmount->dataValue() )); } else { - $dataObject->$fieldName->setCurrency($this->fieldCurrency->Value()); - $dataObject->$fieldName->setAmount($this->fieldAmount->Value()); + $dataObject->$fieldName->setCurrency($this->fieldCurrency->dataValue()); + $dataObject->$fieldName->setAmount($this->fieldAmount->dataValue()); } } @@ -155,7 +155,7 @@ class MoneyField extends FormField { $this->allowedCurrencies = $arr; // @todo Has to be done twice in case allowed currencies changed since construction - $oldVal = $this->fieldCurrency->Value(); + $oldVal = $this->fieldCurrency->dataValue(); $this->fieldCurrency = $this->FieldCurrency($this->name); $this->fieldCurrency->setValue($oldVal); diff --git a/tests/forms/MoneyFieldTest.php b/tests/forms/MoneyFieldTest.php index 91ceedd0e..6ae1e9b1f 100644 --- a/tests/forms/MoneyFieldTest.php +++ b/tests/forms/MoneyFieldTest.php @@ -14,13 +14,13 @@ class MoneyFieldTest extends SapphireTest { $o = new MoneyFieldTest_Object(); $m = new Money(); - $m->setAmount(1.23); + $m->setAmount(123456.78); $m->setCurrency('EUR'); $f = new MoneyField('MyMoney', 'MyMoney', $m); $f->saveInto($o); - $this->assertEquals($o->MyMoney->getAmount(), 1.23); - $this->assertEquals($o->MyMoney->getCurrency(), 'EUR'); + $this->assertEquals(123456.78, $o->MyMoney->getAmount()); + $this->assertEquals('EUR', $o->MyMoney->getCurrency()); } public function testSetValueAsMoney() { @@ -29,13 +29,13 @@ class MoneyFieldTest extends SapphireTest { $f = new MoneyField('MyMoney', 'MyMoney'); $m = new Money(); - $m->setAmount(1.23); + $m->setAmount(123456.78); $m->setCurrency('EUR'); $f->setValue($m); $f->saveInto($o); - $this->assertEquals($o->MyMoney->getAmount(), 1.23); - $this->assertEquals($o->MyMoney->getCurrency(), 'EUR'); + $this->assertEquals(123456.78, $o->MyMoney->getAmount()); + $this->assertEquals('EUR', $o->MyMoney->getCurrency()); } public function testSetValueAsArray() { @@ -43,11 +43,11 @@ class MoneyFieldTest extends SapphireTest { $f = new MoneyField('MyMoney', 'MyMoney'); - $f->setValue(array('Currency'=>'EUR','Amount'=>1.23)); + $f->setValue(array('Currency'=>'EUR','Amount'=>123456.78)); $f->saveInto($o); - $this->assertEquals($o->MyMoney->getAmount(), 1.23); - $this->assertEquals($o->MyMoney->getCurrency(), 'EUR'); + $this->assertEquals(123456.78, $o->MyMoney->getAmount()); + $this->assertEquals('EUR', $o->MyMoney->getCurrency()); } /** @@ -59,12 +59,13 @@ class MoneyFieldTest extends SapphireTest { $o = new MoneyFieldTest_CustomSetter_Object(); $f = new MoneyField('CustomMoney', 'Test Money Field'); - $f->setValue(array('Currency'=>'EUR','Amount'=>1.23)); + $f->setValue(array('Currency'=>'EUR','Amount'=>123456.78)); $f->saveInto($o); - $this->assertEquals($o->MyMoney->getAmount(), (2 * 1.23) ); - $this->assertEquals($o->MyMoney->getCurrency(), 'EUR'); + $this->assertEquals((2 * 123456.78), $o->MyMoney->getAmount()); + $this->assertEquals('EUR', $o->MyMoney->getCurrency()); } + } class MoneyFieldTest_Object extends DataObject implements TestOnly {