From 970c1413d39a3a80d0493d2e3ea96d000bd4b6e5 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Mon, 7 Aug 2017 11:56:14 +0100 Subject: [PATCH] Add unit test --- tests/phpunit/CRM/Utils/RuleTest.php | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/phpunit/CRM/Utils/RuleTest.php b/tests/phpunit/CRM/Utils/RuleTest.php index 7342906b37..2839a22c7e 100644 --- a/tests/phpunit/CRM/Utils/RuleTest.php +++ b/tests/phpunit/CRM/Utils/RuleTest.php @@ -79,4 +79,36 @@ class CRM_Utils_RuleTest extends CiviUnitTestCase { ); } + /** + * @dataProvider moneyDataProvider + * @param $inputData + * @param $expectedResult + */ + public function testMoney($inputData, $expectedResult) { + $this->assertEquals($expectedResult, CRM_Utils_Rule::money($inputData)); + } + + /** + * @return array + */ + public function moneyDataProvider() { + return array( + array(10, TRUE), + array('145.0E+3', FALSE), + array('10', TRUE), + array(-10, TRUE), + array('-10', TRUE), + array('-10foo', FALSE), + array('-10.0345619', TRUE), + array('-10.010,4345619', TRUE), + array('10.0104345619', TRUE), + array('-0', TRUE), + array('-.1', TRUE), + array('.1', TRUE), + // Test currency symbols too, default locale uses $, so if we wanted to test others we'd need to reconfigure locale + array('$500.3333', TRUE), + array('-$500.3333', TRUE), + array('$-500.3333', TRUE), + ); + } } -- 2.25.1