LOG4PHP-167: Fixed converting of boolean values read from ini file without the INI_SC...
authorIvan Habunek <ihabunek@apache.org>
Sun, 29 Jan 2012 20:10:11 +0000 (20:10 +0000)
committerIvan Habunek <ihabunek@apache.org>
Sun, 29 Jan 2012 20:10:11 +0000 (20:10 +0000)
git-svn-id: https://svn.apache.org/repos/asf/logging/log4php/trunk@1237446 13f79535-47bb-0310-9956-ffa450edef68

src/main/php/helpers/LoggerOptionConverter.php
src/test/php/configurators/LoggerConfigurationAdapterINITest.php
src/test/resources/configs/adapters/ini/values.ini [new file with mode: 0644]

index e0eab16..ddd90dd 100644 (file)
@@ -36,8 +36,14 @@ class LoggerOptionConverter {
        /** String values which are converted to boolean TRUE. */
        private static $trueValues = array('1', 'true', 'yes', 'on');
        
-       /** String values which are converted to boolean FALSE. */
-       private static $falseValues = array('0', 'false', 'no', 'off');
+       /** 
+        * String values which are converted to boolean FALSE.
+        * 
+        * Note that an empty string must convert to false, because 
+        * parse_ini_file() which is used for parsing configuration 
+        * converts the value _false_ to an empty string.
+        */
+       private static $falseValues = array('0', 'false', 'no', 'off', '');
        
        /**
         * Read a predefined var.
index 2865d82..8ec435e 100644 (file)
@@ -130,6 +130,39 @@ class LoggerConfigurationAdapterINITest extends PHPUnit_Framework_TestCase {
                $adapter = new LoggerConfigurationAdapterINI();\r
                $adapter->convert($url);\r
        }\r
+\r
+       /**\r
+        * Check that various boolean equivalents from ini file convert properly \r
+        * to boolean. \r
+        */\r
+       public function testBooleanValues() {\r
+               $values = parse_ini_file(PHPUNIT_CONFIG_DIR . '/adapters/ini/values.ini');\r
+               \r
+               $actual = LoggerOptionConverter::toBooleanEx($values['unquoted_true']);\r
+               self::assertTrue($actual);\r
+               \r
+               $actual = LoggerOptionConverter::toBooleanEx($values['unquoted_yes']);\r
+               self::assertTrue($actual);\r
+               \r
+               $actual = LoggerOptionConverter::toBooleanEx($values['unquoted_false']);\r
+               self::assertFalse($actual);\r
+               \r
+               $actual = LoggerOptionConverter::toBooleanEx($values['unquoted_no']);\r
+               self::assertFalse($actual);\r
+               \r
+               $actual = LoggerOptionConverter::toBooleanEx($values['quoted_true']);\r
+               self::assertTrue($actual);\r
+               \r
+               $actual = LoggerOptionConverter::toBooleanEx($values['quoted_false']);\r
+               self::assertFalse($actual);\r
+               \r
+               $actual = LoggerOptionConverter::toBooleanEx($values['unquoted_one']);\r
+               self::assertTrue($actual);\r
+               \r
+               $actual = LoggerOptionConverter::toBooleanEx($values['unquoted_zero']);\r
+               self::assertFalse($actual);\r
+       }\r
+       \r
 }\r
 \r
 ?>
\ No newline at end of file
diff --git a/src/test/resources/configs/adapters/ini/values.ini b/src/test/resources/configs/adapters/ini/values.ini
new file mode 100644 (file)
index 0000000..85191b3
--- /dev/null
@@ -0,0 +1,8 @@
+unquoted_true = true\r
+unquoted_false = false\r
+unquoted_yes = true\r
+unquoted_no = false\r
+quoted_true = "true"\r
+quoted_false = "false"\r
+unquoted_one = 1\r
+unquoted_zero = 0
\ No newline at end of file