Skip to content

Commit

Permalink
Updating test for booleans in postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Oct 27, 2010
1 parent d9222cf commit b3d8a61
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
4 changes: 4 additions & 0 deletions cake/libs/model/datasources/dbo/dbo_postgres.php
Expand Up @@ -732,12 +732,16 @@ function boolean($data, $quote = true) {
switch (true) {
case ($data === true || $data === false):
$result = $data;
break;
case ($data === 't' || $data === 'f'):
$result = ($data === 't');
break;
case ($data === 'true' || $data === 'false'):
$result = ($data === 'true');
break;
case ($data === 'TRUE' || $data === 'FALSE'):
$result = ($data === 'TRUE');
break;
default:
$result = (bool) $data;
break;
Expand Down
20 changes: 10 additions & 10 deletions cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php
Expand Up @@ -340,18 +340,18 @@ function testValueQuoting() {
$this->assertEqual($this->Dbo->value('', 'float', false), "NULL");
$this->assertEqual($this->Dbo->value('0.0', 'float'), "'0.0'");

$this->assertEqual($this->Dbo->value('t', 'boolean'), true);
$this->assertEqual($this->Dbo->value('f', 'boolean'), false);
$this->assertEqual($this->Dbo->value(true), true);
$this->assertEqual($this->Dbo->value(false), false);
$this->assertEqual($this->Dbo->value('t', 'boolean'), "'TRUE'");
$this->assertEqual($this->Dbo->value('f', 'boolean'), "'FALSE'");
$this->assertEqual($this->Dbo->value(true), "'TRUE'");
$this->assertEqual($this->Dbo->value(false), "'FALSE'");
$this->assertEqual($this->Dbo->value('t'), "'t'");
$this->assertEqual($this->Dbo->value('f'), "'f'");
$this->assertEqual($this->Dbo->value('true', 'boolean'), true);
$this->assertEqual($this->Dbo->value('false', 'boolean'), false);
$this->assertEqual($this->Dbo->value('', 'boolean'), false);
$this->assertEqual($this->Dbo->value(0, 'boolean'), false);
$this->assertEqual($this->Dbo->value(1, 'boolean'), true);
$this->assertEqual($this->Dbo->value('1', 'boolean'), true);
$this->assertEqual($this->Dbo->value('true', 'boolean'), "'TRUE'");
$this->assertEqual($this->Dbo->value('false', 'boolean'), "'FALSE'");
$this->assertEqual($this->Dbo->value('', 'boolean'), "'FALSE'");
$this->assertEqual($this->Dbo->value(0, 'boolean'), "'FALSE'");
$this->assertEqual($this->Dbo->value(1, 'boolean'), "'TRUE'");
$this->assertEqual($this->Dbo->value('1', 'boolean'), "'TRUE'");
$this->assertEqual($this->Dbo->value(null, 'boolean'), "NULL");
$this->assertEqual($this->Dbo->value(array()), "NULL");
}
Expand Down

0 comments on commit b3d8a61

Please sign in to comment.