2012-06-20 01:50:42 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @package testing
|
|
|
|
* @copyright (c) 2012 phpBB Group
|
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-06-20 12:57:08 +02:00
|
|
|
class phpbb_dbal_case_test extends phpbb_database_test_case
|
2012-06-20 01:50:42 +02:00
|
|
|
{
|
|
|
|
public function getDataSet()
|
|
|
|
{
|
|
|
|
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml');
|
|
|
|
}
|
|
|
|
|
2012-07-02 11:10:58 +02:00
|
|
|
public function test_case_int()
|
|
|
|
{
|
|
|
|
$db = $this->new_dbal();
|
|
|
|
|
2012-07-16 16:59:40 +02:00
|
|
|
$sql = 'SELECT ' . $db->sql_case('1 = 1', '1', '2') . ' AS test_num
|
2012-07-02 11:10:58 +02:00
|
|
|
FROM phpbb_config';
|
|
|
|
$result = $db->sql_query_limit($sql, 1);
|
|
|
|
|
2012-07-16 16:59:40 +02:00
|
|
|
$this->assertEquals(1, (int) $db->sql_fetchfield('test_num'));
|
2012-07-02 11:10:58 +02:00
|
|
|
|
2012-07-16 16:59:40 +02:00
|
|
|
$sql = 'SELECT ' . $db->sql_case('1 = 0', '1', '2') . ' AS test_num
|
2012-07-02 11:10:58 +02:00
|
|
|
FROM phpbb_config';
|
|
|
|
$result = $db->sql_query_limit($sql, 1);
|
|
|
|
|
2012-07-16 16:59:40 +02:00
|
|
|
$this->assertEquals(2, (int) $db->sql_fetchfield('test_num'));
|
2012-07-02 11:10:58 +02:00
|
|
|
}
|
|
|
|
|
2012-06-20 12:57:08 +02:00
|
|
|
public function test_case_string()
|
2012-06-20 01:50:42 +02:00
|
|
|
{
|
|
|
|
$db = $this->new_dbal();
|
|
|
|
|
2012-07-16 16:59:40 +02:00
|
|
|
$sql = 'SELECT ' . $db->sql_case('1 = 1', "'foo'", "'bar'") . ' AS test_string
|
2012-06-20 01:50:42 +02:00
|
|
|
FROM phpbb_config';
|
2012-06-30 13:00:41 +02:00
|
|
|
$result = $db->sql_query_limit($sql, 1);
|
2012-06-20 01:50:42 +02:00
|
|
|
|
2012-07-16 16:59:40 +02:00
|
|
|
$this->assertEquals('foo', $db->sql_fetchfield('test_string'));
|
2012-06-20 01:50:42 +02:00
|
|
|
|
2012-07-16 16:59:40 +02:00
|
|
|
$sql = 'SELECT ' . $db->sql_case('1 = 0', "'foo'", "'bar'") . ' AS test_string
|
2012-06-30 13:00:41 +02:00
|
|
|
FROM phpbb_config';
|
|
|
|
$result = $db->sql_query_limit($sql, 1);
|
|
|
|
|
2012-07-16 16:59:40 +02:00
|
|
|
$this->assertEquals('bar', $db->sql_fetchfield('test_string'));
|
2012-06-20 01:50:42 +02:00
|
|
|
}
|
|
|
|
|
2012-07-02 11:10:58 +02:00
|
|
|
public function test_case_column()
|
2012-06-20 01:50:42 +02:00
|
|
|
{
|
|
|
|
$db = $this->new_dbal();
|
|
|
|
|
2012-07-16 16:59:40 +02:00
|
|
|
$sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS test_string
|
2012-06-30 13:00:41 +02:00
|
|
|
FROM phpbb_config
|
2012-07-02 11:10:58 +02:00
|
|
|
WHERE config_name = 'config1'";
|
2012-06-30 13:00:41 +02:00
|
|
|
$result = $db->sql_query_limit($sql, 1);
|
|
|
|
|
2012-07-16 16:59:40 +02:00
|
|
|
$this->assertEquals('config1', $db->sql_fetchfield('test_string'));
|
2012-06-20 01:50:42 +02:00
|
|
|
|
2012-07-16 16:59:40 +02:00
|
|
|
$sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS test_string
|
2012-06-30 13:00:41 +02:00
|
|
|
FROM phpbb_config
|
2012-07-02 11:10:58 +02:00
|
|
|
WHERE config_value = 'bar'";
|
2012-06-30 13:00:41 +02:00
|
|
|
$result = $db->sql_query_limit($sql, 1);
|
2012-06-20 01:50:42 +02:00
|
|
|
|
2012-07-16 16:59:40 +02:00
|
|
|
$this->assertEquals('bar', $db->sql_fetchfield('test_string'));
|
2012-06-20 01:50:42 +02:00
|
|
|
}
|
|
|
|
}
|