From fbed4d6bf9158fe6203d8192e34f311141c37ab4 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 3 Jun 2008 04:43:44 +0000 Subject: [PATCH] Added maular's submitted tests. Closes #4786, #4789 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7099 3807eeeb-6ff5-0310-8944-8be069107fe0 --- .../model/datasources/dbo_source.test.php | 102 +++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index ff257471e..6122ca7d4 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -1158,7 +1158,7 @@ class DboSourceTest extends CakeTestCase { /** * execute method * - * @param \ $sql + * @param \$sql * @access protected * @return void */ @@ -2096,6 +2096,10 @@ class DboSourceTest extends CakeTestCase { $result = $this->testDb->conditions("score BETWEEN 90.1 AND 95.7"); $expected = " WHERE score BETWEEN 90.1 AND 95.7"; $this->assertEqual($result, $expected); + + $result = $this->testDb->conditions(array('score' => array(2=>1, 2, 10))); + $expected = " WHERE `score` IN (1, 2, 10)"; + $this->assertEqual($result, $expected); $result = $this->testDb->conditions("Aro.rght = Aro.lft + 1.1"); $expected = " WHERE `Aro`.`rght` = `Aro`.`lft` + 1.1"; @@ -3203,6 +3207,102 @@ class DboSourceTest extends CakeTestCase { $data = array(2, 2.2); $this->assertEqual($this->testDb->introspectType($data), 'integer'); + + + // NULL + $result = $this->testDb->value(null, 'boolean'); + $this->assertEqual($result, 'NULL'); + + // EMPTY STRING + $result = $this->testDb->value('', 'boolean'); + $this->assertEqual($result, "''"); + + // BOOLEAN + $result = $this->testDb->value('true', 'boolean'); + $this->assertEqual($result, 1); + + $result = $this->testDb->value('false', 'boolean'); + $this->assertEqual($result, 1); + + $result = $this->testDb->value(true, 'boolean'); + $this->assertEqual($result, 1); + + $result = $this->testDb->value(false, 'boolean'); + $this->assertEqual($result, 0); + + $result = $this->testDb->value(1, 'boolean'); + $this->assertEqual($result, 1); + + $result = $this->testDb->value(0, 'boolean'); + $this->assertEqual($result, 0); + + $result = $this->testDb->value('abc', 'boolean'); + $this->assertEqual($result, 1); + + $result = $this->testDb->value(1.234, 'boolean'); + $this->assertEqual($result, 1); + + $result = $this->testDb->value('1.234e05', 'boolean'); + $this->assertEqual($result, 1); + + // NUMBERS + $result = $this->testDb->value(123, 'integer'); + $this->assertEqual($result, 123); + + $result = $this->testDb->value('123', 'integer'); + $this->assertEqual($result, '123'); + + $result = $this->testDb->value('0123', 'integer'); + $this->assertEqual($result, "'0123'"); + + $result = $this->testDb->value('0x123ABC', 'integer'); + $this->assertEqual($result, "'0x123ABC'"); + + $result = $this->testDb->value('0x123', 'integer'); + $this->assertEqual($result, "'0x123'"); + + $result = $this->testDb->value(1.234, 'float'); + $this->assertEqual($result, 1.234); + + $result = $this->testDb->value('1.234', 'float'); + $this->assertEqual($result, '1.234'); + + $result = $this->testDb->value(' 1.234 ', 'float'); + $this->assertEqual($result, "' 1.234 '"); + + $result = $this->testDb->value('1.234e05', 'float'); + $this->assertEqual($result, "'1.234e05'"); + + $result = $this->testDb->value('1.234e+5', 'float'); + $this->assertEqual($result, "'1.234e+5'"); + + $result = $this->testDb->value('1,234', 'float'); + $this->assertEqual($result, "'1,234'"); + + $result = $this->testDb->value('FFF', 'integer'); + $this->assertEqual($result, "'FFF'"); + + $result = $this->testDb->value('abc', 'integer'); + $this->assertEqual($result, "'abc'"); + + // STRINGS + $result = $this->testDb->value('123', 'string'); + $this->assertEqual($result, "'123'"); + + $result = $this->testDb->value(123, 'string'); + $this->assertEqual($result, "'123'"); + + $result = $this->testDb->value(1.234, 'string'); + $this->assertEqual($result, "'1.234'"); + + $result = $this->testDb->value('abc', 'string'); + $this->assertEqual($result, "'abc'"); + + $result = $this->testDb->value(' abc ', 'string'); + $this->assertEqual($result, "' abc '"); + + $result = $this->testDb->value('a bc', 'string'); + $this->assertEqual($result, "'a bc'"); } function testValue() {