mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-27 21:58:52 +00:00
[ticket/10942] Fix up unit tests for sql_case()
PHPBB3-10942
This commit is contained in:
parent
a8cf926566
commit
ad9d650659
1 changed files with 28 additions and 11 deletions
|
@ -14,39 +14,56 @@ class phpbb_dbal_case_test extends phpbb_database_test_case
|
||||||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml');
|
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()
|
public function test_case_string()
|
||||||
{
|
{
|
||||||
$db = $this->new_dbal();
|
$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';
|
FROM phpbb_config';
|
||||||
$result = $db->sql_query_limit($sql, 1);
|
$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';
|
FROM phpbb_config';
|
||||||
$result = $db->sql_query_limit($sql, 1);
|
$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();
|
$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
|
FROM phpbb_config
|
||||||
WHERE is_dynamic = 1";
|
WHERE config_name = 'config1'";
|
||||||
$result = $db->sql_query_limit($sql, 1);
|
$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
|
FROM phpbb_config
|
||||||
WHERE is_dynamic = 0";
|
WHERE config_value = 'bar'";
|
||||||
$result = $db->sql_query_limit($sql, 1);
|
$result = $db->sql_query_limit($sql, 1);
|
||||||
|
|
||||||
$this->assertEquals(false, (bool) $db->sql_fetchfield('bool'));
|
$this->assertEquals('bar', $db->sql_fetchfield('string'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue