diff options
Diffstat (limited to 'tests/dbal')
-rw-r--r-- | tests/dbal/case_test.php | 39 |
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')); } } |