From b8b8e60402404558518fd447685c262deecd4416 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 20 Aug 2018 10:40:57 +1200 Subject: [PATCH] Add test for new rounded money format functions 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 --- tests/phpunit/CRM/Utils/MoneyTest.php | 31 +++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/CRM/Utils/MoneyTest.php b/tests/phpunit/CRM/Utils/MoneyTest.php index 921818cad5..d8b8b6635a 100644 --- a/tests/phpunit/CRM/Utils/MoneyTest.php +++ b/tests/phpunit/CRM/Utils/MoneyTest.php @@ -12,8 +12,10 @@ class CRM_Utils_MoneyTest extends CiviUnitTestCase { /** * @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 @@ class CRM_Utils_MoneyTest extends CiviUnitTestCase { ); } + /** + * 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(','); + } + } -- 2.25.1