aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/test_framework/phpbb_database_test_case.php49
-rw-r--r--tests/test_framework/phpbb_test_case_helpers.php7
2 files changed, 53 insertions, 3 deletions
diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php
index f0aa54ec8d..4f017f08d0 100644
--- a/tests/test_framework/phpbb_database_test_case.php
+++ b/tests/test_framework/phpbb_database_test_case.php
@@ -19,12 +19,59 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
}
}
+ function split_sql_file($sql, $delimiter)
+ {
+ $sql = str_replace("\r" , '', $sql);
+ $data = preg_split('/' . preg_quote($delimiter, '/') . '$/m', $sql);
+
+ $data = array_map('trim', $data);
+
+ // The empty case
+ $end_data = end($data);
+
+ if (empty($end_data))
+ {
+ unset($data[key($data)]);
+ }
+
+ return $data;
+ }
+
public function getConnection()
{
+ static $already_connected;
+
$this->init_test_case_helpers();
$database_config = $this->test_case_helpers->get_database_config();
- $pdo = new PDO('mysql:host=' . $database_config['dbhost'] . ';dbname=' . $database_config['dbname'], $database_config['dbuser'], $database_config['dbpasswd']);
+ if ($already_connected)
+ {
+ $pdo = new PDO('mysql:host=' . $database_config['dbhost'] . ';dbname=' . $database_config['dbname'], $database_config['dbuser'], $database_config['dbpasswd']);
+ }
+ else
+ {
+ $pdo = new PDO('mysql:host=' . $database_config['dbhost'] . ';', $database_config['dbuser'], $database_config['dbpasswd']);
+
+ try
+ {
+ $pdo->exec('DROP DATABASE ' . $database_config['dbname']);
+ }
+ catch (PDOException $e){} // ignore non existent db
+
+ $pdo->exec('CREATE DATABASE ' . $database_config['dbname']);
+
+ $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'), ';');
+
+ foreach ($sql_query as $sql)
+ {
+ $pdo->exec($sql);
+ }
+
+ $already_connected = true;
+ }
+
return $this->createDefaultDBConnection($pdo, 'testdb');
}
diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php
index 27a730e2dd..f9ab750218 100644
--- a/tests/test_framework/phpbb_test_case_helpers.php
+++ b/tests/test_framework/phpbb_test_case_helpers.php
@@ -23,13 +23,16 @@ class phpbb_test_case_helpers
if (!file_exists('test_config.php'))
{
trigger_error("You have to create a test_config.php like this:
-<?php
+\"<?php
$dbms = 'mysqli';
$dbhost = 'localhost';
$dbport = '';
$dbname = 'database';
$dbuser = 'user';
-$dbpasswd = 'password';", E_USER_ERROR);
+$dbpasswd = 'password';
+\"
+
+NOTE: The database is dropped and recreated with the phpbb-db-schema! Do NOT specify a database with important data.", E_USER_ERROR);
}
include('test_config.php');