-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CRM-13460 - Add is_numeric checks and test coverage
---------------------------------------- * CRM-13460: Make the numeric rule checks stricter http://issues.civicrm.org/jira/browse/CRM-13460 Conflicts: tools/scripts/git/commit-msg
- Loading branch information
1 parent
3edf128
commit f18140d
Showing
3 changed files
with
163 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
require_once 'CiviTest/CiviUnitTestCase.php'; | ||
|
||
class CRM_Utils_RuleTest extends CiviUnitTestCase { | ||
|
||
function get_info() { | ||
return array( | ||
'name' => 'Rule Test', | ||
'description' => 'Test the validation rules', | ||
'group' => 'CiviCRM BAO Tests', | ||
); | ||
} | ||
|
||
function setUp() { | ||
parent::setUp(); | ||
} | ||
|
||
/** | ||
* @dataProvider integerDataProvider | ||
*/ | ||
function testInteger($inputData, $expectedResult) { | ||
$this->assertEquals($expectedResult, CRM_Utils_Rule::integer($inputData)); | ||
} | ||
|
||
function integerDataProvider() { | ||
return array( | ||
array(10, true), | ||
array('145E+3', false), | ||
array('10', true), | ||
array(-10, true), | ||
array('-10', true), | ||
array('-10foo', false), | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider positiveDataProvider | ||
*/ | ||
function testPositive($inputData, $expectedResult) { | ||
$this->assertEquals($expectedResult, CRM_Utils_Rule::positiveInteger($inputData, $inputType)); | ||
} | ||
|
||
function positiveDataProvider() { | ||
return array( | ||
array(10, true), | ||
array('145.0E+3', false), | ||
array('10', true), | ||
array(-10, false), | ||
array('-10', false), | ||
array('-10foo', false), | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider numericDataProvider | ||
*/ | ||
function testNumeric($inputData, $expectedResult) { | ||
$this->assertEquals($expectedResult, CRM_Utils_Rule::numeric($inputData, $inputType)); | ||
} | ||
|
||
function numericDataProvider() { | ||
return array( | ||
array(10, true), | ||
array('145.0E+3', false), | ||
array('10', true), | ||
array(-10, true), | ||
array('-10', true), | ||
array('-10foo', false), | ||
); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
require_once 'CiviTest/CiviUnitTestCase.php'; | ||
|
||
class CRM_Utils_TypeTest extends CiviUnitTestCase { | ||
|
||
function get_info() { | ||
return array( | ||
'name' => 'Type Test', | ||
'description' => 'Test the validate function', | ||
'group' => 'CiviCRM BAO Tests', | ||
); | ||
} | ||
|
||
function setUp() { | ||
parent::setUp(); | ||
} | ||
|
||
/** | ||
* @dataProvider validateDataProvider | ||
*/ | ||
function testValidate($inputData, $inputType, $expectedResult) { | ||
$this->assertEquals($expectedResult, CRM_Utils_Type::validate($inputData, $inputType, FALSE)); | ||
} | ||
|
||
function validateDataProvider() { | ||
return array( | ||
array(10, 'Int', 10), | ||
array('145E+3', 'Int', NULL), | ||
array('10', 'Integer', 10), | ||
array(-10, 'Int', -10), | ||
array('-10', 'Integer', -10), | ||
array('-10foo', 'Int', NULL), | ||
array(10, 'Positive', 10), | ||
array('145.0E+3', 'Positive', NULL), | ||
array('10', 'Positive', 10), | ||
array(-10, 'Positive', NULL), | ||
array('-10', 'Positive', NULL), | ||
array('-10foo', 'Positive', NULL), | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider numericDataProvider | ||
*/ | ||
function testNumeric($inputData, $expectedResult) { | ||
$this->assertEquals($expectedResult, CRM_Utils_Rule::numeric($inputData, $inputType)); | ||
} | ||
|
||
function numericDataProvider() { | ||
return array( | ||
array(10, true), | ||
array('145.0E+3', false), | ||
array('10', true), | ||
array(-10, true), | ||
array('-10', true), | ||
array('-10foo', false), | ||
); | ||
} | ||
|
||
|
||
} |