Skip to content

Commit

Permalink
Merge pull request #12689 from eileenmcnaughton/money_fn
Browse files Browse the repository at this point in the history
Add test for new rounded money format functions
  • Loading branch information
eileenmcnaughton authored Aug 20, 2018
2 parents 4a741fb + b8b8e60 commit 1b81c5d
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 1b81c5d

Please sign in to comment.