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()); }
public function testToCurrency() { $USD = new DBMoney(); $USD->setLocale('en_US'); $USD->setAmount(53292.18); $this->assertSame('$53,292.18', $USD->Nice()); $this->assertSame('$ 53.292,18', $USD->Nice(array('format' => 'de_AT'))); }