Skip to content

Commit

Permalink
Add test for new rounded money format functions
Browse files Browse the repository at this point in the history
Note that there are also some protected functions added. I have left those to be teste via this wrapper as they are not yet exposed
  • Loading branch information
eileenmcnaughton committed Aug 19, 2018
1 parent 4a741fb commit b8b8e60
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions tests/phpunit/CRM/Utils/MoneyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ public function setUp() {

/**
* @dataProvider subtractCurrenciesDataProvider
* @param $inputData
* @param $expectedResult
* @param string $leftOp
* @param string $rightOp
* @param string $currency
* @param float $expectedResult
*/
public function testSubtractCurrencies($leftOp, $rightOp, $currency, $expectedResult) {
$this->assertEquals($expectedResult, CRM_Utils_Money::subtractCurrencies($leftOp, $rightOp, $currency));
Expand Down Expand Up @@ -44,4 +46,29 @@ public function subtractCurrenciesDataProvider() {
);
}

/**
* Test rounded by currency function.
*
* In practice this only does rounding to 2 since rounding by any other amount is
* only place-holder supported.
*/
public function testFormatLocaleNumericRoundedByCurrency() {
$result = CRM_Utils_Money::formatLocaleNumericRoundedByCurrency(8950.3678, 'NZD');
$this->assertEquals('8,950.37', $result);
}

/**
* Test rounded by currency function.
*
* This should be formatted according to European standards - . thousand separator
* and , for decimal. (The Europeans are wrong but they don't know that. We will forgive them
* because ... metric).
*/
public function testFormatLocaleNumericRoundedByCurrencyEuroThousand() {
$this->setCurrencySeparators('.');
$result = CRM_Utils_Money::formatLocaleNumericRoundedByCurrency(8950.3678, 'NZD');
$this->assertEquals('8.950,37', $result);
$this->setCurrencySeparators(',');
}

}

0 comments on commit b8b8e60

Please sign in to comment.