mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-09 12:58:52 +00:00
[feature/dbal-tests] Make some tests for return_on_error on SELECT-queries
This commit is contained in:
parent
c6442ce640
commit
147d6fd590
1 changed files with 213 additions and 13 deletions
|
@ -17,27 +17,116 @@ class phpbb_dbal_test extends phpbb_database_test_case
|
||||||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/three_users.xml');
|
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/three_users.xml');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_select_row()
|
public static function return_on_error_select_data()
|
||||||
{
|
{
|
||||||
$db = $this->new_dbal();
|
return array(
|
||||||
|
array('phpbb_users', "username_clean = 'bertie'", array(array('username_clean' => 'bertie'))),
|
||||||
$result = $db->sql_query('SELECT username_clean
|
array('phpbb_users', "username_clean = 'phpBB'", array()),
|
||||||
FROM phpbb_users
|
array('phpbb_users', 'username_clean syntax_error', false),
|
||||||
WHERE user_id = 2');
|
array('phpbb_users', 'column_not_exists = 2', false),
|
||||||
$row = $db->sql_fetchrow($result);
|
array('table_not_exists', 'column_not_exists = 2', false),
|
||||||
|
);
|
||||||
$this->assertEquals(array('username_clean' => 'foobar'), $row);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_select_field()
|
/**
|
||||||
|
* @dataProvider return_on_error_select_data
|
||||||
|
*/
|
||||||
|
public function test_return_on_error_select($table, $where, $expected)
|
||||||
|
{
|
||||||
|
$db = $this->new_dbal();
|
||||||
|
|
||||||
|
$db->sql_return_on_error(true);
|
||||||
|
|
||||||
|
$result = $db->sql_query('SELECT username_clean
|
||||||
|
FROM ' . $table . '
|
||||||
|
WHERE ' . $where . '
|
||||||
|
ORDER BY user_id ASC');
|
||||||
|
|
||||||
|
$db->sql_return_on_error(false);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $db->sql_fetchrowset($result));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function fetchrow_data()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('', array(array('username_clean' => 'barfoo'),
|
||||||
|
array('username_clean' => 'foobar'),
|
||||||
|
array('username_clean' => 'bertie'))),
|
||||||
|
array('user_id = 2', array(array('username_clean' => 'foobar'))),
|
||||||
|
array("username_clean = 'bertie'", array(array('username_clean' => 'bertie'))),
|
||||||
|
array("username_clean = 'phpBB'", array()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider fetchrow_data
|
||||||
|
*/
|
||||||
|
public function test_fetchrow($where, $expected)
|
||||||
{
|
{
|
||||||
$db = $this->new_dbal();
|
$db = $this->new_dbal();
|
||||||
|
|
||||||
$result = $db->sql_query('SELECT username_clean
|
$result = $db->sql_query('SELECT username_clean
|
||||||
FROM phpbb_users
|
FROM phpbb_users
|
||||||
WHERE user_id = 2');
|
' . (($where) ? ' WHERE ' . $where : '') . '
|
||||||
|
ORDER BY user_id ASC');
|
||||||
|
|
||||||
$this->assertEquals('foobar', $db->sql_fetchfield('username_clean'));
|
$ary = array();
|
||||||
|
while ($row = $db->sql_fetchrow($result))
|
||||||
|
{
|
||||||
|
$ary[] = $row;
|
||||||
|
}
|
||||||
|
$db->sql_freeresult($result);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $ary);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider fetchrow_data
|
||||||
|
*/
|
||||||
|
public function test_fetchrowset($where, $expected)
|
||||||
|
{
|
||||||
|
$db = $this->new_dbal();
|
||||||
|
|
||||||
|
$result = $db->sql_query('SELECT username_clean
|
||||||
|
FROM phpbb_users
|
||||||
|
' . (($where) ? ' WHERE ' . $where : '') . '
|
||||||
|
ORDER BY user_id ASC');
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $db->sql_fetchrowset($result));
|
||||||
|
|
||||||
|
$db->sql_freeresult($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function fetchfield_data()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('', array('barfoo', 'foobar', 'bertie')),
|
||||||
|
array('user_id = 2', array('foobar')),
|
||||||
|
array("username_clean = 'bertie'", array('bertie')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider fetchfield_data
|
||||||
|
*/
|
||||||
|
public function test_fetchfield($where, $expected)
|
||||||
|
{
|
||||||
|
$db = $this->new_dbal();
|
||||||
|
|
||||||
|
$result = $db->sql_query('SELECT username_clean
|
||||||
|
FROM phpbb_users
|
||||||
|
' . (($where) ? ' WHERE ' . $where : '') . '
|
||||||
|
ORDER BY user_id ASC');
|
||||||
|
|
||||||
|
$ary = array();
|
||||||
|
while ($row = $db->sql_fetchfield('username_clean'))
|
||||||
|
{
|
||||||
|
$ary[] = $row;
|
||||||
|
}
|
||||||
|
$db->sql_freeresult($result);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $ary);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function query_limit_data()
|
public static function query_limit_data()
|
||||||
|
@ -70,7 +159,7 @@ class phpbb_dbal_test extends phpbb_database_test_case
|
||||||
|
|
||||||
$result = $db->sql_query_limit('SELECT username_clean
|
$result = $db->sql_query_limit('SELECT username_clean
|
||||||
FROM phpbb_users
|
FROM phpbb_users
|
||||||
ORDER BY user_id', $total, $offset);
|
ORDER BY user_id ASC', $total, $offset);
|
||||||
|
|
||||||
$ary = array();
|
$ary = array();
|
||||||
while ($row = $db->sql_fetchrow($result))
|
while ($row = $db->sql_fetchrow($result))
|
||||||
|
@ -81,5 +170,116 @@ class phpbb_dbal_test extends phpbb_database_test_case
|
||||||
|
|
||||||
$this->assertEquals($expected, $ary);
|
$this->assertEquals($expected, $ary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function like_expression_data()
|
||||||
|
{
|
||||||
|
// * = any_char; # = one_char
|
||||||
|
return array(
|
||||||
|
array('barfoo', array(array('username_clean' => 'barfoo'))),
|
||||||
|
array('bar', array()),
|
||||||
|
array('bar*', array(array('username_clean' => 'barfoo'))),
|
||||||
|
array('*bar*', array(array('username_clean' => 'barfoo'),
|
||||||
|
array('username_clean' => 'foobar'))),
|
||||||
|
array('*b*', array(array('username_clean' => 'barfoo'),
|
||||||
|
array('username_clean' => 'foobar'),
|
||||||
|
array('username_clean' => 'bertie'))),
|
||||||
|
array('b*r', array()),
|
||||||
|
array('b*e', array(array('username_clean' => 'bertie'))),
|
||||||
|
array('#b*e', array()),
|
||||||
|
array('b####e', array(array('username_clean' => 'bertie'))),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider like_expression_data
|
||||||
|
*/
|
||||||
|
public function test_like_expression($like_expression, $expected)
|
||||||
|
{
|
||||||
|
$db = $this->new_dbal();
|
||||||
|
|
||||||
|
$like_expression = str_replace('*', $db->any_char, $like_expression);
|
||||||
|
$like_expression = str_replace('#', $db->one_char, $like_expression);
|
||||||
|
$where = ($like_expression) ? 'username_clean ' . $db->sql_like_expression($like_expression) : '';
|
||||||
|
|
||||||
|
$result = $db->sql_query('SELECT username_clean
|
||||||
|
FROM phpbb_users
|
||||||
|
' . (($where) ? ' WHERE ' . $where : '') . '
|
||||||
|
ORDER BY user_id ASC');
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $db->sql_fetchrowset($result));
|
||||||
|
|
||||||
|
$db->sql_freeresult($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function in_set_data()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('user_id', 3, false, false, array(array('username_clean' => 'bertie'))),
|
||||||
|
array('user_id', 3, false, true, array(array('username_clean' => 'bertie'))),
|
||||||
|
array('user_id', 3, true, false, array(array('username_clean' => 'barfoo'),
|
||||||
|
array('username_clean' => 'foobar'))),
|
||||||
|
array('user_id', 3, true, true, array(array('username_clean' => 'barfoo'),
|
||||||
|
array('username_clean' => 'foobar'))),
|
||||||
|
array('user_id', '3', false, false, array(array('username_clean' => 'bertie'))),
|
||||||
|
array('user_id', '3', false, true, array(array('username_clean' => 'bertie'))),
|
||||||
|
array('user_id', '3', true, false, array(array('username_clean' => 'barfoo'),
|
||||||
|
array('username_clean' => 'foobar'))),
|
||||||
|
array('user_id', '3', true, true, array(array('username_clean' => 'barfoo'),
|
||||||
|
array('username_clean' => 'foobar'))),
|
||||||
|
array('user_id', array(3), false, false, array(array('username_clean' => 'bertie'))),
|
||||||
|
array('user_id', array(3), false, true, array(array('username_clean' => 'bertie'))),
|
||||||
|
array('user_id', array(3), true, false, array(array('username_clean' => 'barfoo'),
|
||||||
|
array('username_clean' => 'foobar'))),
|
||||||
|
array('user_id', array(3), true, true, array(array('username_clean' => 'barfoo'),
|
||||||
|
array('username_clean' => 'foobar'))),
|
||||||
|
array('user_id', array(1, 3), false, false, array(array('username_clean' => 'barfoo'),
|
||||||
|
array('username_clean' => 'bertie'))),
|
||||||
|
array('user_id', array(1, 3), false, true, array(array('username_clean' => 'barfoo'),
|
||||||
|
array('username_clean' => 'bertie'))),
|
||||||
|
array('user_id', array(1, 3), true, false, array(array('username_clean' => 'foobar'))),
|
||||||
|
array('user_id', array(1, 3), true, true, array(array('username_clean' => 'foobar'))),
|
||||||
|
array('user_id', '', false, false, array()),
|
||||||
|
array('user_id', '', false, true, array()),
|
||||||
|
array('user_id', '', true, false, array(array('username_clean' => 'barfoo'),
|
||||||
|
array('username_clean' => 'foobar'),
|
||||||
|
array('username_clean' => 'bertie'))),
|
||||||
|
array('user_id', '', true, true, array(array('username_clean' => 'barfoo'),
|
||||||
|
array('username_clean' => 'foobar'),
|
||||||
|
array('username_clean' => 'bertie'))),
|
||||||
|
array('user_id', array(), false, false, false, true),
|
||||||
|
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('username_clean' => 'foobar'),
|
||||||
|
array('username_clean' => 'bertie'))),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider in_set_data
|
||||||
|
*/
|
||||||
|
public function test_in_set($field, $array, $negate, $allow_empty_set, $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_in_set($field, $array, $negate, $allow_empty_set) . '
|
||||||
|
ORDER BY user_id ASC');
|
||||||
|
|
||||||
|
if ($catch_error)
|
||||||
|
{
|
||||||
|
$db->sql_return_on_error(falsee);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $db->sql_fetchrowset($result));
|
||||||
|
|
||||||
|
$db->sql_freeresult($result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue