From a5b8726fd0df32c376db2268c9e9f8e3aed92d42 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 20 Jun 2014 21:08:50 -0700 Subject: [PATCH] CRM_Utils_StringTest - Add test for strtobool --- tests/phpunit/CRM/Utils/StringTest.php | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/phpunit/CRM/Utils/StringTest.php b/tests/phpunit/CRM/Utils/StringTest.php index 862d3f2c3c..04c320c388 100644 --- a/tests/phpunit/CRM/Utils/StringTest.php +++ b/tests/phpunit/CRM/Utils/StringTest.php @@ -130,5 +130,41 @@ class CRM_Utils_StringTest extends CiviUnitTestCase { $actual = CRM_Utils_String::parsePrefix(':', $input, $defaultPrefix); $this->assertEquals($expected, $actual); } + + function booleanDataProvider() { + $cases = array(); // array(0 => $input, 1 => $expectedOutput) + $cases[] = array(TRUE, TRUE); + $cases[] = array(FALSE, FALSE); + $cases[] = array(1, TRUE); + $cases[] = array(0, FALSE); + $cases[] = array('1', TRUE); + $cases[] = array('0', FALSE); + $cases[] = array(TRUE, TRUE); + $cases[] = array(FALSE, FALSE); + $cases[] = array('Y', TRUE); + $cases[] = array('N', FALSE); + $cases[] = array('y', TRUE); + $cases[] = array('n', FALSE); + $cases[] = array('Yes', TRUE); + $cases[] = array('No', FALSE); + $cases[] = array('True', TRUE); + $cases[] = array('False', FALSE); + $cases[] = array('yEs', TRUE); + $cases[] = array('nO', FALSE); + $cases[] = array('tRuE', TRUE); + $cases[] = array('FaLsE', FALSE); + return $cases; + } + + /** + * @param $input + * @param $expected bool + * @dataProvider booleanDataProvider + */ + function testStrToBool($input, $expected) { + $actual = CRM_Utils_String::strtobool($input); + $this->assertTrue($expected === $actual); + } + } -- 2.25.1