mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-06 16:56:44 +02:00
Merge remote-tracking branch 'nickvergessen/ticket/10942' into develop
* nickvergessen/ticket/10942: [ticket/10942] Avoid possible conflicts with magic words in unit tests [ticket/10942] Add access modifiers [ticket/10942] Use ANSI SQL standard || in dbal.php [ticket/10942] Fix up unit tests for sql_case() [ticket/10942] Require same data type and do not cast expressions automatically [ticket/10942] Make unit tests for sql_case simpler [ticket/10942] Add a comment why we cast to sql_case() [ticket/10942] Rename method sql_conditional() to sql_case() [ticket/10942] Change term string to expression to avoid confusion [ticket/10942] Fix sql_conditional for mssql, postgre and oracle [ticket/10942] Fix function name on order_lower_test.php [ticket/10942] Add unit tests for sql_concatenate [ticket/10942] Add sql_concatenate to dbal [ticket/10942] Add unit tests for sql_conditional [ticket/10942] Add sql_conditional to dbal
This commit is contained in:
69
tests/dbal/case_test.php
Normal file
69
tests/dbal/case_test.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_dbal_case_test extends phpbb_database_test_case
|
||||
{
|
||||
public function getDataSet()
|
||||
{
|
||||
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 test_num
|
||||
FROM phpbb_config';
|
||||
$result = $db->sql_query_limit($sql, 1);
|
||||
|
||||
$this->assertEquals(1, (int) $db->sql_fetchfield('test_num'));
|
||||
|
||||
$sql = 'SELECT ' . $db->sql_case('1 = 0', '1', '2') . ' AS test_num
|
||||
FROM phpbb_config';
|
||||
$result = $db->sql_query_limit($sql, 1);
|
||||
|
||||
$this->assertEquals(2, (int) $db->sql_fetchfield('test_num'));
|
||||
}
|
||||
|
||||
public function test_case_string()
|
||||
{
|
||||
$db = $this->new_dbal();
|
||||
|
||||
$sql = 'SELECT ' . $db->sql_case('1 = 1', "'foo'", "'bar'") . ' AS test_string
|
||||
FROM phpbb_config';
|
||||
$result = $db->sql_query_limit($sql, 1);
|
||||
|
||||
$this->assertEquals('foo', $db->sql_fetchfield('test_string'));
|
||||
|
||||
$sql = 'SELECT ' . $db->sql_case('1 = 0', "'foo'", "'bar'") . ' AS test_string
|
||||
FROM phpbb_config';
|
||||
$result = $db->sql_query_limit($sql, 1);
|
||||
|
||||
$this->assertEquals('bar', $db->sql_fetchfield('test_string'));
|
||||
}
|
||||
|
||||
public function test_case_column()
|
||||
{
|
||||
$db = $this->new_dbal();
|
||||
|
||||
$sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS test_string
|
||||
FROM phpbb_config
|
||||
WHERE config_name = 'config1'";
|
||||
$result = $db->sql_query_limit($sql, 1);
|
||||
|
||||
$this->assertEquals('config1', $db->sql_fetchfield('test_string'));
|
||||
|
||||
$sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS test_string
|
||||
FROM phpbb_config
|
||||
WHERE config_value = 'bar'";
|
||||
$result = $db->sql_query_limit($sql, 1);
|
||||
|
||||
$this->assertEquals('bar', $db->sql_fetchfield('test_string'));
|
||||
}
|
||||
}
|
64
tests/dbal/concatenate_test.php
Normal file
64
tests/dbal/concatenate_test.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_dbal_concatenate_test extends phpbb_database_test_case
|
||||
{
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml');
|
||||
}
|
||||
|
||||
public function test_concatenate_string()
|
||||
{
|
||||
$db = $this->new_dbal();
|
||||
|
||||
$sql = 'SELECT config_name, ' . $db->sql_concatenate('config_name', "'" . $db->sql_escape('append') . "'") . ' AS string
|
||||
FROM phpbb_config';
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
$db->sql_return_on_error(false);
|
||||
|
||||
$this->assertEquals(array(
|
||||
array(
|
||||
'config_name' => 'config1',
|
||||
'string' => 'config1append',
|
||||
),
|
||||
array(
|
||||
'config_name' => 'config2',
|
||||
'string' => 'config2append',
|
||||
),
|
||||
),
|
||||
$db->sql_fetchrowset($result)
|
||||
);
|
||||
}
|
||||
|
||||
public function test_concatenate_statement()
|
||||
{
|
||||
$db = $this->new_dbal();
|
||||
|
||||
$sql = 'SELECT config_name, ' . $db->sql_concatenate('config_name', 'config_value') . ' AS string
|
||||
FROM phpbb_config';
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
$db->sql_return_on_error(false);
|
||||
|
||||
$this->assertEquals(array(
|
||||
array(
|
||||
'config_name' => 'config1',
|
||||
'string' => 'config1foo',
|
||||
),
|
||||
array(
|
||||
'config_name' => 'config2',
|
||||
'string' => 'config2bar',
|
||||
),
|
||||
),
|
||||
$db->sql_fetchrowset($result)
|
||||
);
|
||||
}
|
||||
}
|
@@ -14,7 +14,7 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case
|
||||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/styles.xml');
|
||||
}
|
||||
|
||||
public function test_cross_join()
|
||||
public function test_order_lower()
|
||||
{
|
||||
$db = $this->new_dbal();
|
||||
|
||||
|
Reference in New Issue
Block a user