Permalink
Browse files

FIX: Fixes #2398

- hasAmount() failed to return true for values <= 0.99 and >= 0.01
- Added unit tests
  • Loading branch information...
1 parent 92c9feb commit 3aaa12f114e5ae35ea052a2df5f5eb4c43edd34c Russell Michell committed Sep 13, 2013
Showing with 32 additions and 1 deletion.
  1. +2 −1 model/fieldtypes/Money.php
  2. +30 −0 tests/model/MoneyTest.php
@@ -212,7 +212,8 @@ public function exists() {
* @return boolean
*/
public function hasAmount() {
- return (int)$this->getAmount() != '0';
+ $a = $this->getAmount();
+ return (!empty($a) && is_numeric($a));
}
public function isChanged() {
View
@@ -277,6 +277,36 @@ public function testMoneyLazyLoading() {
$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());
+ }
}

0 comments on commit 3aaa12f

Please sign in to comment.