From b9b3d8821ae3dc9f121c27f0bd96a56b93068d91 Mon Sep 17 00:00:00 2001 From: nischayn22 Date: Tue, 22 Jan 2013 09:58:14 +0530 Subject: [PATCH] (bug 37352) Boolean issue when using sqlite. 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 | 6 +----- tests/phpunit/includes/db/TestORMRowTest.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/includes/db/ORMRow.php b/includes/db/ORMRow.php index 6acc124aed..dc8649b749 100644 --- a/includes/db/ORMRow.php +++ b/includes/db/ORMRow.php @@ -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 ) ) { diff --git a/tests/phpunit/includes/db/TestORMRowTest.php b/tests/phpunit/includes/db/TestORMRowTest.php index 9739f4cf41..263553ac8b 100644 --- a/tests/phpunit/includes/db/TestORMRowTest.php +++ b/tests/phpunit/includes/db/TestORMRowTest.php @@ -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 {} -- 2.20.1