CRM-13460 - Add is_numeric checks and test coverage
[civicrm-core.git] / tests / phpunit / CRM / Utils / RuleTest.php
CommitLineData
f942c321
DL
1<?php
2
3require_once 'CiviTest/CiviUnitTestCase.php';
4
5class CRM_Utils_RuleTest extends CiviUnitTestCase {
6
7 function get_info() {
8 return array(
9 'name' => 'Rule Test',
10 'description' => 'Test the validation rules',
11 'group' => 'CiviCRM BAO Tests',
12 );
13 }
14
15 function setUp() {
16 parent::setUp();
17 }
18
19 /**
20 * @dataProvider integerDataProvider
21 */
22 function testInteger($inputData, $expectedResult) {
23 $this->assertEquals($expectedResult, CRM_Utils_Rule::integer($inputData));
24 }
25
26 function integerDataProvider() {
27 return array(
28 array(10, true),
29 array('145E+3', false),
30 array('10', true),
31 array(-10, true),
32 array('-10', true),
33 array('-10foo', false),
34 );
35 }
36
37 /**
38 * @dataProvider positiveDataProvider
39 */
40 function testPositive($inputData, $expectedResult) {
41 $this->assertEquals($expectedResult, CRM_Utils_Rule::positiveInteger($inputData, $inputType));
42 }
43
44 function positiveDataProvider() {
45 return array(
46 array(10, true),
47 array('145.0E+3', false),
48 array('10', true),
49 array(-10, false),
50 array('-10', false),
51 array('-10foo', false),
52 );
53 }
54
55 /**
56 * @dataProvider numericDataProvider
57 */
58 function testNumeric($inputData, $expectedResult) {
59 $this->assertEquals($expectedResult, CRM_Utils_Rule::numeric($inputData, $inputType));
60 }
61
62 function numericDataProvider() {
63 return array(
64 array(10, true),
65 array('145.0E+3', false),
66 array('10', true),
67 array(-10, true),
68 array('-10', true),
69 array('-10foo', false),
70 );
71 }
72
73
74}