mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #4206 from gregsmirnov/pulls/localised-moneyfield-fix
BUG Fixed handling of numbers in certain locales
This commit is contained in:
commit
e733efa195
@ -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);
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user