mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[feature/dbal-tests] Make some tests for build_array_data on SELECT
This commit is contained in:
parent
147d6fd590
commit
53d316dc9e
2 changed files with 114 additions and 4 deletions
|
@ -246,12 +246,14 @@ class phpbb_dbal_test extends phpbb_database_test_case
|
||||||
array('user_id', '', true, true, array(array('username_clean' => 'barfoo'),
|
array('user_id', '', true, true, array(array('username_clean' => 'barfoo'),
|
||||||
array('username_clean' => 'foobar'),
|
array('username_clean' => 'foobar'),
|
||||||
array('username_clean' => 'bertie'))),
|
array('username_clean' => 'bertie'))),
|
||||||
array('user_id', array(), false, false, false, true),
|
|
||||||
array('user_id', array(), false, true, array()),
|
array('user_id', array(), false, true, array()),
|
||||||
array('user_id', array(), true, false, false, true),
|
|
||||||
array('user_id', array(), true, true, array(array('username_clean' => 'barfoo'),
|
array('user_id', array(), true, true, array(array('username_clean' => 'barfoo'),
|
||||||
array('username_clean' => 'foobar'),
|
array('username_clean' => 'foobar'),
|
||||||
array('username_clean' => 'bertie'))),
|
array('username_clean' => 'bertie'))),
|
||||||
|
|
||||||
|
// These here would throw errors and therefor $result should be false.
|
||||||
|
array('user_id', array(), false, false, false, true),
|
||||||
|
array('user_id', array(), true, false, false, true),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +276,48 @@ class phpbb_dbal_test extends phpbb_database_test_case
|
||||||
|
|
||||||
if ($catch_error)
|
if ($catch_error)
|
||||||
{
|
{
|
||||||
$db->sql_return_on_error(falsee);
|
$db->sql_return_on_error(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $db->sql_fetchrowset($result));
|
||||||
|
|
||||||
|
$db->sql_freeresult($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function build_array_data()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array(array('username_clean' => 'barfoo'), array(array('username_clean' => 'barfoo'))),
|
||||||
|
array(array('username_clean' => 'barfoo', 'user_id' => 1), array(array('username_clean' => 'barfoo'))),
|
||||||
|
array(array('username_clean' => 'barfoo', 'user_id' => 2), array()),
|
||||||
|
|
||||||
|
// These here would throw errors and therefor $result should be false.
|
||||||
|
array(array(), false, true),
|
||||||
|
array('no_array', false, true),
|
||||||
|
array(0, false, true),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider build_array_data
|
||||||
|
*/
|
||||||
|
public function test_build_array($assoc_ary, $expected, $catch_error = false)
|
||||||
|
{
|
||||||
|
$db = $this->new_dbal();
|
||||||
|
|
||||||
|
if ($catch_error)
|
||||||
|
{
|
||||||
|
$db->sql_return_on_error(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $db->sql_query('SELECT username_clean
|
||||||
|
FROM phpbb_users
|
||||||
|
WHERE ' . $db->sql_build_array('SELECT', $assoc_ary) . '
|
||||||
|
ORDER BY user_id ASC');
|
||||||
|
|
||||||
|
if ($catch_error)
|
||||||
|
{
|
||||||
|
$db->sql_return_on_error(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertEquals($expected, $db->sql_fetchrowset($result));
|
$this->assertEquals($expected, $db->sql_fetchrowset($result));
|
||||||
|
|
|
@ -19,6 +19,57 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_dbms_data($dbms)
|
||||||
|
{
|
||||||
|
$available_dbms = array(
|
||||||
|
'firebird' => array(
|
||||||
|
'SCHEMA' => 'firebird',
|
||||||
|
'DELIM' => ';;',
|
||||||
|
),
|
||||||
|
'mysqli' => array(
|
||||||
|
'SCHEMA' => 'mysql_41',
|
||||||
|
'DELIM' => ';',
|
||||||
|
),
|
||||||
|
'mysql' => array(
|
||||||
|
'SCHEMA' => 'mysql',
|
||||||
|
'DELIM' => ';',
|
||||||
|
),
|
||||||
|
'mssql' => array(
|
||||||
|
'SCHEMA' => 'mssql',
|
||||||
|
'DELIM' => 'GO',
|
||||||
|
),
|
||||||
|
'mssql_odbc'=> array(
|
||||||
|
'SCHEMA' => 'mssql',
|
||||||
|
'DELIM' => 'GO',
|
||||||
|
),
|
||||||
|
'mssqlnative' => array(
|
||||||
|
'SCHEMA' => 'mssql',
|
||||||
|
'DELIM' => 'GO',
|
||||||
|
),
|
||||||
|
'oracle' => array(
|
||||||
|
'SCHEMA' => 'oracle',
|
||||||
|
'DELIM' => '/',
|
||||||
|
),
|
||||||
|
'postgres' => array(
|
||||||
|
'SCHEMA' => 'postgres',
|
||||||
|
'DELIM' => ';',
|
||||||
|
),
|
||||||
|
'sqlite' => array(
|
||||||
|
'SCHEMA' => 'sqlite',
|
||||||
|
'DELIM' => ';',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isset($available_dbms[$dbms]))
|
||||||
|
{
|
||||||
|
return $available_dbms[$dbms];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
trigger_error('Database unsupported', E_USER_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function split_sql_file($sql, $delimiter)
|
function split_sql_file($sql, $delimiter)
|
||||||
{
|
{
|
||||||
$sql = str_replace("\r" , '', $sql);
|
$sql = str_replace("\r" , '', $sql);
|
||||||
|
@ -62,7 +113,23 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
|
||||||
|
|
||||||
$pdo = new PDO('mysql:host=' . $database_config['dbhost'] . ';dbname=' . $database_config['dbname'], $database_config['dbuser'], $database_config['dbpasswd']);
|
$pdo = new PDO('mysql:host=' . $database_config['dbhost'] . ';dbname=' . $database_config['dbname'], $database_config['dbuser'], $database_config['dbpasswd']);
|
||||||
|
|
||||||
$sql_query = $this->split_sql_file(file_get_contents('../phpBB/install/schemas/mysql_41_schema.sql'), ';');
|
$dbms_data = $this->get_dbms_data($database_config['dbms']);
|
||||||
|
if ($database_config['dbms'] == 'mysql')
|
||||||
|
{
|
||||||
|
$pdo->exec('SELECT VERSION() AS version');
|
||||||
|
$row = $sth->fetch(PDO::FETCH_ASSOC);
|
||||||
|
if (version_compare($row['version'], '4.1.3', '>='))
|
||||||
|
{
|
||||||
|
$dbms_data['SCHEMA'] .= '_41';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$dbms_data['SCHEMA'] .= '_40';
|
||||||
|
}
|
||||||
|
unset($row);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql_query = $this->split_sql_file(file_get_contents("../phpBB/install/schemas/{$dbms_data['SCHEMA']}_schema.sql"), $dbms_data['DELIM']);
|
||||||
|
|
||||||
foreach ($sql_query as $sql)
|
foreach ($sql_query as $sql)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue