aboutsummaryrefslogtreecommitdiffstats
path: root/tests/dbal
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2012-07-02 11:10:58 +0200
committerJoas Schilling <nickvergessen@gmx.de>2012-07-02 11:10:58 +0200
commitad9d6506594f90ac7c6cdf20a5718d28042059c9 (patch)
tree9826d5f904e7a94ad8310a9f01610fc2be434259 /tests/dbal
parenta8cf926566c32097c61c14210990f2a7229ddfc7 (diff)
downloadforums-ad9d6506594f90ac7c6cdf20a5718d28042059c9.tar
forums-ad9d6506594f90ac7c6cdf20a5718d28042059c9.tar.gz
forums-ad9d6506594f90ac7c6cdf20a5718d28042059c9.tar.bz2
forums-ad9d6506594f90ac7c6cdf20a5718d28042059c9.tar.xz
forums-ad9d6506594f90ac7c6cdf20a5718d28042059c9.zip
[ticket/10942] Fix up unit tests for sql_case()
PHPBB3-10942
Diffstat (limited to 'tests/dbal')
-rw-r--r--tests/dbal/case_test.php39
1 files changed, 28 insertions, 11 deletions
diff --git a/tests/dbal/case_test.php b/tests/dbal/case_test.php
index 684f2c26a9..5219defa06 100644
--- a/tests/dbal/case_test.php
+++ b/tests/dbal/case_test.php
@@ -14,39 +14,56 @@ class phpbb_dbal_case_test extends phpbb_database_test_case
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml');
}
+ public function test_case_int()
+ {
+ $db = $this->new_dbal();
+
+ $sql = 'SELECT ' . $db->sql_case('1 = 1', '1', '2') . ' AS num
+ FROM phpbb_config';
+ $result = $db->sql_query_limit($sql, 1);
+
+ $this->assertEquals(1, (int) $db->sql_fetchfield('num'));
+
+ $sql = 'SELECT ' . $db->sql_case('1 = 0', '1', '2') . ' AS num
+ FROM phpbb_config';
+ $result = $db->sql_query_limit($sql, 1);
+
+ $this->assertEquals(2, (int) $db->sql_fetchfield('num'));
+ }
+
public function test_case_string()
{
$db = $this->new_dbal();
- $sql = 'SELECT ' . $db->sql_case('1 = 1', '1', '0') . ' AS bool
+ $sql = 'SELECT ' . $db->sql_case('1 = 1', "'foo'", "'bar'") . ' AS string
FROM phpbb_config';
$result = $db->sql_query_limit($sql, 1);
- $this->assertEquals(true, (bool) $db->sql_fetchfield('bool'));
+ $this->assertEquals('foo', $db->sql_fetchfield('string'));
- $sql = 'SELECT ' . $db->sql_case('1 = 0', '1', '0') . ' AS bool
+ $sql = 'SELECT ' . $db->sql_case('1 = 0', "'foo'", "'bar'") . ' AS string
FROM phpbb_config';
$result = $db->sql_query_limit($sql, 1);
- $this->assertEquals(false, (bool) $db->sql_fetchfield('bool'));
+ $this->assertEquals('bar', $db->sql_fetchfield('string'));
}
- public function test_case_statement()
+ public function test_case_column()
{
$db = $this->new_dbal();
- $sql = 'SELECT ' . $db->sql_case('is_dynamic = 1', 'is_dynamic', '0') . " AS bool
+ $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS string
FROM phpbb_config
- WHERE is_dynamic = 1";
+ WHERE config_name = 'config1'";
$result = $db->sql_query_limit($sql, 1);
- $this->assertEquals(true, (bool) $db->sql_fetchfield('bool'));
+ $this->assertEquals('config1', $db->sql_fetchfield('string'));
- $sql = 'SELECT ' . $db->sql_case('is_dynamic = 1', '1', 'is_dynamic') . " AS bool
+ $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS string
FROM phpbb_config
- WHERE is_dynamic = 0";
+ WHERE config_value = 'bar'";
$result = $db->sql_query_limit($sql, 1);
- $this->assertEquals(false, (bool) $db->sql_fetchfield('bool'));
+ $this->assertEquals('bar', $db->sql_fetchfield('string'));
}
}