mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
commit
e4ff3b8ec8
@ -212,7 +212,8 @@ class Money extends DBField implements CompositeDBField {
|
|||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function hasAmount() {
|
public function hasAmount() {
|
||||||
return (int)$this->getAmount() != '0';
|
$a = $this->getAmount();
|
||||||
|
return (!empty($a) && is_numeric($a));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isChanged() {
|
public function isChanged() {
|
||||||
|
@ -278,6 +278,36 @@ class MoneyTest extends SapphireTest {
|
|||||||
$this->assertEquals('£2.46', $obj->obj('MyOtherMoney')->Nice());
|
$this->assertEquals('£2.46', $obj->obj('MyOtherMoney')->Nice());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testHasAmount() {
|
||||||
|
$obj = new MoneyTest_DataObject();
|
||||||
|
$m = new Money();
|
||||||
|
$obj->MyMoney = $m;
|
||||||
|
|
||||||
|
$m->setValue(array('Amount' => 1));
|
||||||
|
$this->assertTrue($obj->MyMoney->hasAmount());
|
||||||
|
|
||||||
|
$m->setValue(array('Amount' => 1.00));
|
||||||
|
$this->assertTrue($obj->MyMoney->hasAmount());
|
||||||
|
|
||||||
|
$m->setValue(array('Amount' => 1.01));
|
||||||
|
$this->assertTrue($obj->MyMoney->hasAmount());
|
||||||
|
|
||||||
|
$m->setValue(array('Amount' => 0.99));
|
||||||
|
$this->assertTrue($obj->MyMoney->hasAmount());
|
||||||
|
|
||||||
|
$m->setValue(array('Amount' => 0.01));
|
||||||
|
$this->assertTrue($obj->MyMoney->hasAmount());
|
||||||
|
|
||||||
|
$m->setValue(array('Amount' => 0));
|
||||||
|
$this->assertFalse($obj->MyMoney->hasAmount());
|
||||||
|
|
||||||
|
$m->setValue(array('Amount' => 0.0));
|
||||||
|
$this->assertFalse($obj->MyMoney->hasAmount());
|
||||||
|
|
||||||
|
$m->setValue(array('Amount' => 0.00));
|
||||||
|
$this->assertFalse($obj->MyMoney->hasAmount());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MoneyTest_DataObject extends DataObject implements TestOnly {
|
class MoneyTest_DataObject extends DataObject implements TestOnly {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user