X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=tests%2Fphpunit%2FCRM%2FUtils%2FMoneyTest.php;h=82cca12ca82167dd73486d42b5b4e490092ed30e;hb=6f47e023ddb4d299b4224a094273da3f6b003270;hp=ba6a3dc8ba7320686ecc688ba2a2f7de59dd0926;hpb=e1ae2a86b06078730a6cab4a8746474a01953cf1;p=civicrm-core.git diff --git a/tests/phpunit/CRM/Utils/MoneyTest.php b/tests/phpunit/CRM/Utils/MoneyTest.php index ba6a3dc8ba..82cca12ca8 100644 --- a/tests/phpunit/CRM/Utils/MoneyTest.php +++ b/tests/phpunit/CRM/Utils/MoneyTest.php @@ -41,6 +41,7 @@ class CRM_Utils_MoneyTest extends CiviUnitTestCase { [2, 1, 'USD', 1], [0, 0, 'USD', 0], [1, 2, 'USD', -1], + [269.565217391, 1, 'USD', 268.57], [number_format(19.99, 2), number_format(20.00, 2), 'USD', number_format(-0.01, 2)], ['notanumber', 5.00, 'USD', NULL], ]; @@ -71,6 +72,38 @@ class CRM_Utils_MoneyTest extends CiviUnitTestCase { $this->setCurrencySeparators(','); } + /** + * Test rounded by currency function with specified precision. + * + * @param string $thousandSeparator + * + * @dataProvider getThousandSeparators + */ + public function testFormatLocaleNumericRoundedByPrecision($thousandSeparator) { + $this->setCurrencySeparators($thousandSeparator); + $result = CRM_Utils_Money::formatLocaleNumericRoundedByPrecision(8950.3678, 3); + $expected = ($thousandSeparator === ',') ? '8,950.368' : '8.950,368'; + $this->assertEquals($expected, $result); + } + + /** + * Test rounded by currency function with specified precision but without padding to reach it. + * + * @param string $thousandSeparator + * + * @dataProvider getThousandSeparators + */ + public function testFormatLocaleNumericRoundedByOptionalPrecision($thousandSeparator) { + $this->setCurrencySeparators($thousandSeparator); + $result = CRM_Utils_Money::formatLocaleNumericRoundedByOptionalPrecision(8950.3678, 8); + $expected = ($thousandSeparator === ',') ? '8,950.3678' : '8.950,3678'; + $this->assertEquals($expected, $result); + + $result = CRM_Utils_Money::formatLocaleNumericRoundedByOptionalPrecision(123456789.987654321, 9); + $expected = ($thousandSeparator === ',') ? '123,456,789.98765' : '123.456.789,98765'; + $this->assertEquals($result, $expected); + } + /** * Test that using the space character as a currency works */