(bug 37352) Boolean issue when using sqlite.
authornischayn22 <nischayn22@gmail.com>
Tue, 22 Jan 2013 04:28:14 +0000 (09:58 +0530)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 6 Mar 2013 03:45:48 +0000 (03:45 +0000)
using a type cast instead, otherwise an empty string gets converted to
true when set with bool type.

Change-Id: I4161de32151a649161ab4084e80cafe4a462c7d5

includes/db/ORMRow.php
tests/phpunit/includes/db/TestORMRowTest.php

index 6acc124..dc8649b 100644 (file)
@@ -509,11 +509,7 @@ class ORMRow implements IORMRow {
                                        $value = (float)$value;
                                        break;
                                case 'bool':
-                                       if ( is_string( $value ) ) {
-                                               $value = $value !== '0';
-                                       } elseif ( is_int( $value ) ) {
-                                               $value = $value !== 0;
-                                       }
+                                       $value = (bool)$value;
                                        break;
                                case 'array':
                                        if ( is_string( $value ) ) {
index 9739f4c..263553a 100644 (file)
@@ -107,6 +107,22 @@ class TestORMRowTest extends ORMRowTest {
                );
        }
 
+       /**
+        * @since 1.21
+        * @return array
+        */
+       protected function getMockValues() {
+               return array(
+                       'id' => 1,
+                       'str' => 'foobar4645645',
+                       'int' => 42,
+                       'float' => 4.2,
+                       'bool' => '',
+                       'array' => array( 42, 'foobar' ),
+                       'blob' => new stdClass()
+               );
+       }
+
 }
 
 class TestORMRow extends ORMRow {}