diff --git a/cake/libs/model/datasources/dbo/dbo_postgres.php b/cake/libs/model/datasources/dbo/dbo_postgres.php index 079c6cc22..c262a732a 100644 --- a/cake/libs/model/datasources/dbo/dbo_postgres.php +++ b/cake/libs/model/datasources/dbo/dbo_postgres.php @@ -280,9 +280,9 @@ class DboPostgres extends DboSource { $data = pg_escape_bytea($data); break; case 'boolean': - if ($data === true || $data === 't') { + if ($data === true || $data === 't' || $data === 'true') { return 'TRUE'; - } elseif ($data === false || $data === 'f') { + } elseif ($data === false || $data === 'f' || $data === 'false') { return 'FALSE'; } return (!empty($data) ? 'TRUE' : 'FALSE'); @@ -598,6 +598,10 @@ class DboPostgres extends DboSource { return $data; case ($data === 't' || $data === 'f'): return ($data === 't'); + case ($data === 'true' || $data === 'false'): + return ($data === 'true'); + case ($data === 'TRUE' || $data === 'FALSE'): + return ($data === 'TRUE'); default: return (bool)$data; break; diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php index ecbc0b1b2..7016b40ac 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php @@ -290,12 +290,35 @@ class DboPostgresTest extends CakeTestCase { $this->assertEqual($this->db2->value(false), "FALSE"); $this->assertEqual($this->db2->value('t'), "'t'"); $this->assertEqual($this->db2->value('f'), "'f'"); + $this->assertEqual($this->db2->value('true', 'boolean'), 'TRUE'); + $this->assertEqual($this->db2->value('false', 'boolean'), 'FALSE'); $this->assertEqual($this->db2->value('', 'boolean'), 'FALSE'); $this->assertEqual($this->db2->value(0, 'boolean'), 'FALSE'); $this->assertEqual($this->db2->value(1, 'boolean'), 'TRUE'); $this->assertEqual($this->db2->value('1', 'boolean'), 'TRUE'); $this->assertEqual($this->db2->value(null, 'boolean'), "NULL"); } +/** + * Tests that different Postgres boolean 'flavors' are properly returned as native PHP booleans + * + * @access public + * @return void + */ + function testBooleanNormalization() { + $this->assertTrue($this->db2->boolean('t')); + $this->assertTrue($this->db2->boolean('true')); + $this->assertTrue($this->db2->boolean('TRUE')); + $this->assertTrue($this->db2->boolean(true)); + $this->assertTrue($this->db2->boolean(1)); + $this->assertTrue($this->db2->boolean(" ")); + + $this->assertFalse($this->db2->boolean('f')); + $this->assertFalse($this->db2->boolean('false')); + $this->assertFalse($this->db2->boolean('FALSE')); + $this->assertFalse($this->db2->boolean(false)); + $this->assertFalse($this->db2->boolean(0)); + $this->assertFalse($this->db2->boolean('')); + } /** * testLastInsertIdMultipleInsert method *