Skip to content

Commit

Permalink
BUG Fixed handling of numbers in certain locales
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory Smirnov committed May 20, 2015
1 parent 0ba3ada commit f9bdf61
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
10 changes: 5 additions & 5 deletions forms/MoneyField.php
Expand Up @@ -106,12 +106,12 @@ public function saveInto(DataObjectInterface $dataObject) {
$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());
}
}

Expand Down Expand Up @@ -155,7 +155,7 @@ public function setAllowedCurrencies($arr) {
$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);

Expand Down
25 changes: 13 additions & 12 deletions tests/forms/MoneyFieldTest.php
Expand Up @@ -14,13 +14,13 @@ public function testSaveInto() {
$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() {
Expand All @@ -29,25 +29,25 @@ public function testSetValueAsMoney() {
$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() {
$o = new MoneyFieldTest_Object();

$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());
}

/**
Expand All @@ -59,12 +59,13 @@ public function testSetValueViaSetter() {
$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 {
Expand Down

0 comments on commit f9bdf61

Please sign in to comment.