diff --git a/tests/phpunit/CRM/Utils/MoneyTest.php b/tests/phpunit/CRM/Utils/MoneyTest.php index 921818cad58c..d8b8b6635afb 100644 --- a/tests/phpunit/CRM/Utils/MoneyTest.php +++ b/tests/phpunit/CRM/Utils/MoneyTest.php @@ -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)); @@ -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(','); + } + }