From bcaf65d7cd951b9a453cac413c420cb418b42f8d Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Sat, 3 Sep 2011 17:26:36 -0500 Subject: [PATCH] [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 --- ...phpbb_database_test_connection_manager.php | 59 ++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index a7559e2183..78be831ecb 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -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', ), );