Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
28 / 28
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
phpbb_dbal_case_test
100.00% covered (success)
100.00%
28 / 28
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 getDataSet
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 test_case_int
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 test_case_string
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 test_case_column
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14class phpbb_dbal_case_test extends phpbb_database_test_case
15{
16    public function getDataSet()
17    {
18        return $this->createXMLDataSet(__DIR__.'/fixtures/config.xml');
19    }
20
21    public function test_case_int()
22    {
23        $db = $this->new_dbal();
24
25        $sql = 'SELECT ' . $db->sql_case('1 = 1', '1', '2') . ' AS test_num
26            FROM phpbb_config';
27        $result = $db->sql_query_limit($sql, 1);
28
29        $this->assertEquals(1, (int) $db->sql_fetchfield('test_num'));
30
31        $sql = 'SELECT ' . $db->sql_case('1 = 0', '1', '2') . ' AS test_num
32            FROM phpbb_config';
33        $result = $db->sql_query_limit($sql, 1);
34
35        $this->assertEquals(2, (int) $db->sql_fetchfield('test_num'));
36    }
37
38    public function test_case_string()
39    {
40        $db = $this->new_dbal();
41
42        $sql = 'SELECT ' . $db->sql_case('1 = 1', "'foo'", "'bar'") . ' AS test_string
43            FROM phpbb_config';
44        $result = $db->sql_query_limit($sql, 1);
45
46        $this->assertEquals('foo', $db->sql_fetchfield('test_string'));
47
48        $sql = 'SELECT ' . $db->sql_case('1 = 0', "'foo'", "'bar'") . ' AS test_string
49            FROM phpbb_config';
50        $result = $db->sql_query_limit($sql, 1);
51
52        $this->assertEquals('bar', $db->sql_fetchfield('test_string'));
53    }
54
55    public function test_case_column()
56    {
57        $db = $this->new_dbal();
58
59        $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS test_string
60            FROM phpbb_config
61            WHERE config_name = 'config1'";
62        $result = $db->sql_query_limit($sql, 1);
63
64        $this->assertEquals('config1', $db->sql_fetchfield('test_string'));
65
66        $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS test_string
67            FROM phpbb_config
68            WHERE config_value = 'bar'";
69        $result = $db->sql_query_limit($sql, 1);
70
71        $this->assertEquals('bar', $db->sql_fetchfield('test_string'));
72    }
73}