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