mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
b478c8be34
ENHANCEMENT Using MoneyField in Money->scaffoldFormField() BUGFIX Fixed Money->setValue() to respect $value parameter over $record to avoid wrongly updated values from stale $record values instead of new $value git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@77772 467b73ca-7a2a-4603-9d3b-597d59a354a9
53 lines
1.2 KiB
PHP
53 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* @package sapphire
|
|
* @subpackage tests
|
|
*/
|
|
class MoneyFieldTest extends SapphireTest {
|
|
function testSaveInto() {
|
|
$o = new MoneyFieldTest_Object();
|
|
|
|
$m = new Money();
|
|
$m->setAmount(1.23);
|
|
$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');
|
|
}
|
|
|
|
function testSetValueAsMoney() {
|
|
$o = new MoneyFieldTest_Object();
|
|
|
|
$f = new MoneyField('MyMoney', 'MyMoney');
|
|
|
|
$m = new Money();
|
|
$m->setAmount(1.23);
|
|
$m->setCurrency('EUR');
|
|
$f->setValue($m);
|
|
|
|
$f->saveInto($o);
|
|
$this->assertEquals($o->MyMoney->getAmount(), 1.23);
|
|
$this->assertEquals($o->MyMoney->getCurrency(), 'EUR');
|
|
}
|
|
|
|
function testSetValueAsArray() {
|
|
$o = new MoneyFieldTest_Object();
|
|
|
|
$f = new MoneyField('MyMoney', 'MyMoney');
|
|
|
|
$f->setValue(array('Currency'=>'EUR','Amount'=>1.23));
|
|
|
|
$f->saveInto($o);
|
|
$this->assertEquals($o->MyMoney->getAmount(), 1.23);
|
|
$this->assertEquals($o->MyMoney->getCurrency(), 'EUR');
|
|
}
|
|
}
|
|
|
|
class MoneyFieldTest_Object extends DataObject implements TestOnly {
|
|
static $db = array(
|
|
'MyMoney' => 'Money',
|
|
);
|
|
}
|
|
?>
|