- hasAmount() failed to return true for values <= 0.99 and >= 0.01
- Added unit tests
This commit is contained in:
Russell Michell 2013-09-13 12:21:21 +12:00
parent 92c9febb99
commit 3aaa12f114
2 changed files with 32 additions and 1 deletions

View File

@ -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() {

View File

@ -277,6 +277,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());
}
}