4 * Class CRM_Utils_RuleTest
7 class CRM_Utils_RuleTest
extends CiviUnitTestCase
{
9 public function setUp() {
14 * @dataProvider integerDataProvider
16 * @param $expectedResult
18 public function testInteger($inputData, $expectedResult) {
19 $this->assertEquals($expectedResult, CRM_Utils_Rule
::integer($inputData));
25 public function integerDataProvider() {
28 array('145E+3', FALSE),
32 array('-10foo', FALSE),
37 * @dataProvider positiveDataProvider
39 * @param $expectedResult
41 public function testPositive($inputData, $expectedResult) {
42 $this->assertEquals($expectedResult, CRM_Utils_Rule
::positiveInteger($inputData));
48 public function positiveDataProvider() {
51 array('145.0E+3', FALSE),
55 array('-10foo', FALSE),
60 * @dataProvider numericDataProvider
62 * @param $expectedResult
64 public function testNumeric($inputData, $expectedResult) {
65 $this->assertEquals($expectedResult, CRM_Utils_Rule
::numeric($inputData));
71 public function numericDataProvider() {
74 array('145.0E+3', FALSE),
78 array('-10foo', FALSE),
83 * @dataProvider moneyDataProvider
85 * @param $expectedResult
87 public function testMoney($inputData, $expectedResult) {
88 $this->assertEquals($expectedResult, CRM_Utils_Rule
::money($inputData));
94 public function moneyDataProvider() {
97 array('145.0E+3', FALSE),
101 array('-10foo', FALSE),
102 array('-10.0345619', TRUE),
103 array('-10.010,4345619', TRUE),
104 array('10.0104345619', TRUE),
108 // Test currency symbols too, default locale uses $, so if we wanted to test others we'd need to reconfigure locale
109 array('$500.3333', TRUE),
110 array('-$500.3333', TRUE),
111 array('$-500.3333', TRUE),
118 public function extenionKeyTests() {
120 $keys[] = array('org.civicrm.multisite', TRUE);
121 $keys[] = array('au.org.contribute2016', TRUE);
122 $keys[] = array('%3Csvg%20onload=alert(0)%3E', FALSE);
128 * @param $expectedResult
129 * @dataProvider extenionKeyTests
131 public function testExtenionKeyValid($key, $expectedResult) {
132 $this->assertEquals($expectedResult, CRM_Utils_Rule
::checkExtesnionKeyIsValid($key));