Skip to content
Snippets Groups Projects
Unverified Commit c604b1eb authored by colemanw's avatar colemanw Committed by GitHub
Browse files

Merge pull request #19805 from MegaphoneJon/escape-boolean-booleans

#2461 - allow booleans to be of type boolean
parents 0dc105e1 9281d89e
Branches
Tags
No related merge requests found
......@@ -625,6 +625,10 @@ class CRM_Utils_Rule {
* @return bool
*/
public static function boolean($value) {
if ($value === TRUE || $value === FALSE) {
return TRUE;
}
// This is intentionally not using === comparison - but will fail on FALSE.
return preg_match(
'/(^(1|0)$)|(^(Y(es)?|N(o)?)$)|(^(T(rue)?|F(alse)?)$)/i', $value
) ? TRUE : FALSE;
......
......@@ -79,6 +79,28 @@ class CRM_Utils_RuleTest extends CiviUnitTestCase {
];
}
/**
* @dataProvider booleanDataProvider
* @param $inputData
* @param $expectedResult
*/
public function testBoolean($inputData, $expectedResult) {
$this->assertEquals($expectedResult, CRM_Utils_Rule::boolean($inputData));
}
/**
* @return array
*/
public function booleanDataProvider() {
return [
[TRUE, TRUE],
['TRUE', TRUE],
[FALSE, TRUE],
['false', TRUE],
['banana', FALSE],
];
}
/**
* @dataProvider moneyDataProvider
* @param $inputData
......
......@@ -131,6 +131,11 @@ class CRM_Utils_TypeTest extends CiviUnitTestCase {
['field(contribution_status_id,4,5,6) asc, contact_id asc', 'MysqlOrderBy', 'field(`contribution_status_id`,4,5,6) asc, `contact_id` asc'],
['table.civicrm_column_name desc,other_column,another_column desc', 'MysqlOrderBy', '`table`.`civicrm_column_name` desc, `other_column`, `another_column` desc'],
['table.`Home-street_address` asc, `table-alias`.`Home-street_address` desc,`table-alias`.column', 'MysqlOrderBy', '`table`.`Home-street_address` asc, `table-alias`.`Home-street_address` desc, `table-alias`.`column`'],
[TRUE, 'Boolean', TRUE],
[FALSE, 'Boolean', FALSE],
['TRUE', 'Boolean', 'TRUE'],
['false', 'Boolean', 'false'],
['banana', 'Boolean', NULL],
];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment