1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-05 15:16:16 +02:00

[ticket/10349] Unit tests: Remove comments while loading schema files

Perform the same operations that the installer does when preparing the schema
files. These functions come straight from /includes/functions_install.php and
/includes/functions_admin.php.

PHPBB3-10349
This commit is contained in:
Patrick Webster 2011-09-03 17:26:36 -05:00
parent 8e5eacf692
commit bcaf65d7cd

View File

@ -234,7 +234,12 @@ class phpbb_database_test_connection_manager
}
$filename = $directory . $schema . '_schema.sql';
$sql = $this->split_sql(file_get_contents($filename));
$remove_remarks = $this->dbms['COMMENTS'];
$queries = file_get_contents($filename);
$this->$remove_remarks($queries);
$sql = $this->split_sql($queries);
foreach ($sql as $query)
{
@ -279,6 +284,49 @@ class phpbb_database_test_connection_manager
return $data;
}
/**
* remove_remarks will strip the sql comment lines out of an uploaded sql file
*/
protected function remove_remarks(&$sql)
{
$sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^#.*$/m', "\n", $sql));
}
/**
* remove_comments will strip the sql comment lines out of an uploaded sql file
* specifically for mssql and postgres type files in the install....
*/
protected function remove_comments(&$output)
{
$lines = explode("\n", $output);
$output = '';
// try to keep mem. use down
$linecount = sizeof($lines);
$in_comment = false;
for ($i = 0; $i < $linecount; $i++)
{
if (trim($lines[$i]) == '/*')
{
$in_comment = true;
}
if (!$in_comment)
{
$output .= $lines[$i] . "\n";
}
if (trim($lines[$i]) == '*/')
{
$in_comment = false;
}
}
unset($lines);
return $output;
}
/**
* Map a phpBB dbms driver name to dbms data array
*/
@ -289,46 +337,55 @@ class phpbb_database_test_connection_manager
'SCHEMA' => 'firebird',
'DELIM' => ';;',
'PDO' => 'firebird',
'COMMENTS' => 'remove_remarks',
),
'mysqli' => array(
'SCHEMA' => 'mysql_41',
'DELIM' => ';',
'PDO' => 'mysql',
'COMMENTS' => 'remove_remarks',
),
'mysql' => array(
'SCHEMA' => 'mysql',
'DELIM' => ';',
'PDO' => 'mysql',
'COMMENTS' => 'remove_remarks',
),
'mssql' => array(
'SCHEMA' => 'mssql',
'DELIM' => 'GO',
'PDO' => 'odbc',
'COMMENTS' => 'remove_comments',
),
'mssql_odbc'=> array(
'SCHEMA' => 'mssql',
'DELIM' => 'GO',
'PDO' => 'odbc',
'COMMENTS' => 'remove_comments',
),
'mssqlnative' => array(
'SCHEMA' => 'mssql',
'DELIM' => 'GO',
'PDO' => 'sqlsrv',
'COMMENTS' => 'remove_comments',
),
'oracle' => array(
'SCHEMA' => 'oracle',
'DELIM' => '/',
'PDO' => 'oci',
'COMMENTS' => 'remove_comments',
),
'postgres' => array(
'SCHEMA' => 'postgres',
'DELIM' => ';',
'PDO' => 'pgsql',
'COMMENTS' => 'remove_comments',
),
'sqlite' => array(
'SCHEMA' => 'sqlite',
'DELIM' => ';',
'PDO' => 'sqlite2',
'COMMENTS' => 'remove_remarks',
),
);