public function testSetValueAsMoney() { $o = new MoneyFieldTest_Object(); $f = new MoneyField('MyMoney', 'MyMoney'); $m = new DBMoney(); $m->setAmount(123456.78); $m->setCurrency('EUR'); $f->setValue($m); $f->saveInto($o); $this->assertEquals(123456.78, $o->MyMoney->getAmount()); $this->assertEquals('EUR', $o->MyMoney->getCurrency()); }
public function testAddCompositedExtraFields() { $obj = new ManyManyListTest_ExtraFields(); $obj->write(); $money = new DBMoney(); $money->setAmount(100); $money->setCurrency('USD'); // the actual test is that this does not generate an error in the sql. $obj->Clients()->add($obj, array('Worth' => $money, 'Reference' => 'Foo')); $check = $obj->Clients()->First(); $this->assertEquals('Foo', $check->Reference, 'Basic scalar fields should exist'); $this->assertInstanceOf('SilverStripe\\ORM\\FieldType\\DBMoney', $check->Worth, 'Composite fields should exist on the record'); $this->assertEquals(100, $check->Worth->getAmount()); }
/** * Write a Money object to the database, then re-read it to ensure it * is re-read properly. */ public function testGettingWrittenDataObject() { $local = i18n::get_locale(); //make sure that the $ amount is not prefixed by US$, as it would be in non-US locale i18n::set_locale('en_US'); $obj = new MoneyTest_DataObject(); $m = new DBMoney(); $m->setAmount(987.65); $m->setCurrency('USD'); $obj->MyMoney = $m; $this->assertEquals("\$987.65", $obj->MyMoney->Nice(), "Money field not added to data object properly when read prior to first writing the record."); $objID = $obj->write(); $moneyTest = DataObject::get_by_id('MoneyTest_DataObject', $objID); $this->assertTrue($moneyTest instanceof MoneyTest_DataObject); $this->assertEquals('USD', $moneyTest->MyMoneyCurrency); $this->assertEquals(987.65, $moneyTest->MyMoneyAmount); $this->assertEquals("\$987.65", $moneyTest->MyMoney->Nice(), "Money field not added to data object properly when read."); i18n::set_locale($local); }