diff options
-rw-r--r-- | tests/dbal/dbal.php | 49 | ||||
-rw-r--r-- | tests/test_framework/phpbb_database_test_case.php | 69 |
2 files changed, 114 insertions, 4 deletions
diff --git a/tests/dbal/dbal.php b/tests/dbal/dbal.php index 0239f91a2d..f90b5efeb5 100644 --- a/tests/dbal/dbal.php +++ b/tests/dbal/dbal.php @@ -246,12 +246,14 @@ class phpbb_dbal_test extends phpbb_database_test_case 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'))), + + // 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) { - $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)); diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 4f017f08d0..547ee6404e 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -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) { $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']); - $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) { |