mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX: Fixes #2398
- hasAmount() failed to return true for values <= 0.99 and >= 0.01 - Added unit tests
This commit is contained in:
parent
92c9febb99
commit
3aaa12f114
@ -212,7 +212,8 @@ class Money extends DBField implements CompositeDBField {
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasAmount() {
|
||||
return (int)$this->getAmount() != '0';
|
||||
$a = $this->getAmount();
|
||||
return (!empty($a) && is_numeric($a));
|
||||
}
|
||||
|
||||
public function isChanged() {
|
||||
|
@ -278,6 +278,36 @@ class MoneyTest extends SapphireTest {
|
||||
$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->assertEquals(true, $obj->MyMoney->hasAmount());
|
||||
|
||||
$m->setValue(array('Amount' => 1.00));
|
||||
$this->assertEquals(true, $obj->MyMoney->hasAmount());
|
||||
|
||||
$m->setValue(array('Amount' => 1.01));
|
||||
$this->assertEquals(true, $obj->MyMoney->hasAmount());
|
||||
|
||||
$m->setValue(array('Amount' => 0.99));
|
||||
$this->assertEquals(true, $obj->MyMoney->hasAmount());
|
||||
|
||||
$m->setValue(array('Amount' => 0.01));
|
||||
$this->assertEquals(true, $obj->MyMoney->hasAmount());
|
||||
|
||||
$m->setValue(array('Amount' => 0));
|
||||
$this->assertEquals(false, $obj->MyMoney->hasAmount());
|
||||
|
||||
$m->setValue(array('Amount' => 0.0));
|
||||
$this->assertEquals(false, $obj->MyMoney->hasAmount());
|
||||
|
||||
$m->setValue(array('Amount' => 0.00));
|
||||
$this->assertEquals(false, $obj->MyMoney->hasAmount());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MoneyTest_DataObject extends DataObject implements TestOnly {
|
||||
|
Loading…
Reference in New Issue
Block a user