| @@ 44-54 (lines=11) @@ | ||
| 41 | $this->assertEquals('EUR', $o->MyMoney->getCurrency()); |
|
| 42 | } |
|
| 43 | ||
| 44 | public function testSetValueAsArray() { |
|
| 45 | $o = new MoneyFieldTest_Object(); |
|
| 46 | ||
| 47 | $f = new MoneyField('MyMoney', 'MyMoney'); |
|
| 48 | ||
| 49 | $f->setValue(array('Currency'=>'EUR','Amount'=>123456.78)); |
|
| 50 | ||
| 51 | $f->saveInto($o); |
|
| 52 | $this->assertEquals(123456.78, $o->MyMoney->getAmount()); |
|
| 53 | $this->assertEquals('EUR', $o->MyMoney->getCurrency()); |
|
| 54 | } |
|
| 55 | ||
| 56 | /** |
|
| 57 | * This UT tests if saveInto used customised getters/setters correctly. |
|
| @@ 61-70 (lines=10) @@ | ||
| 58 | * Saving values for CustomMoney shall go through the setCustomMoney_Test |
|
| 59 | * setter method and double the value. |
|
| 60 | */ |
|
| 61 | public function testSetValueViaSetter() { |
|
| 62 | $o = new MoneyFieldTest_CustomSetter_Object(); |
|
| 63 | ||
| 64 | $f = new MoneyField('CustomMoney', 'Test Money Field'); |
|
| 65 | $f->setValue(array('Currency'=>'EUR','Amount'=>123456.78)); |
|
| 66 | ||
| 67 | $f->saveInto($o); |
|
| 68 | $this->assertEquals((2 * 123456.78), $o->MyMoney->getAmount()); |
|
| 69 | $this->assertEquals('EUR', $o->MyMoney->getCurrency()); |
|
| 70 | } |
|
| 71 | ||
| 72 | } |
|
| 73 | ||
| @@ 263-277 (lines=15) @@ | ||
| 260 | $this->assertTrue($m3->exists()); |
|
| 261 | } |
|
| 262 | ||
| 263 | public function testLoadIntoDataObject() { |
|
| 264 | $obj = new MoneyTest_DataObject(); |
|
| 265 | ||
| 266 | $this->assertInstanceOf('SilverStripe\Model\FieldType\DBMoney', $obj->obj('MyMoney')); |
|
| 267 | ||
| 268 | $m = new DBMoney(); |
|
| 269 | $m->setValue(array( |
|
| 270 | 'Currency' => 'EUR', |
|
| 271 | 'Amount' => 1.23 |
|
| 272 | )); |
|
| 273 | $obj->MyMoney = $m; |
|
| 274 | ||
| 275 | $this->assertEquals($obj->MyMoney->getCurrency(), 'EUR'); |
|
| 276 | $this->assertEquals($obj->MyMoney->getAmount(), 1.23); |
|
| 277 | } |
|
| 278 | ||
| 279 | public function testWriteToDataObject() { |
|
| 280 | $obj = new MoneyTest_DataObject(); |
|