aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_framework
diff options
context:
space:
mode:
authorPatrick Webster <noxwizard@phpbb.com>2011-09-20 23:23:03 -0500
committerPatrick Webster <noxwizard@phpbb.com>2011-09-20 23:23:03 -0500
commit4bc11db0ffc3b387e4ad38b0d9ceccfa58f2738d (patch)
treebf83b6ada754ee81d07a058c10aab6c21f23e0a3 /tests/test_framework
parentbcaf65d7cd951b9a453cac413c420cb418b42f8d (diff)
downloadforums-4bc11db0ffc3b387e4ad38b0d9ceccfa58f2738d.tar
forums-4bc11db0ffc3b387e4ad38b0d9ceccfa58f2738d.tar.gz
forums-4bc11db0ffc3b387e4ad38b0d9ceccfa58f2738d.tar.bz2
forums-4bc11db0ffc3b387e4ad38b0d9ceccfa58f2738d.tar.xz
forums-4bc11db0ffc3b387e4ad38b0d9ceccfa58f2738d.zip
[ticket/10349] Unit tests: Consolidate schema comment removal functions
PHPBB3-10349
Diffstat (limited to 'tests/test_framework')
-rw-r--r--tests/test_framework/phpbb_database_test_connection_manager.php69
1 files changed, 11 insertions, 58 deletions
diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php
index 78be831ecb..547361b41d 100644
--- a/tests/test_framework/phpbb_database_test_connection_manager.php
+++ b/tests/test_framework/phpbb_database_test_connection_manager.php
@@ -234,12 +234,11 @@ class phpbb_database_test_connection_manager
}
$filename = $directory . $schema . '_schema.sql';
- $remove_remarks = $this->dbms['COMMENTS'];
$queries = file_get_contents($filename);
- $this->$remove_remarks($queries);
+ $sql = $this->remove_comments($queries);
- $sql = $this->split_sql($queries);
+ $sql = $this->split_sql($sql);
foreach ($sql as $query)
{
@@ -271,60 +270,23 @@ class phpbb_database_test_connection_manager
unset($data[key($data)]);
}
- if ($this->config['dbms'] == 'sqlite')
- {
- // remove comment lines starting with # - they are not proper sqlite
- // syntax and break sqlite2
- foreach ($data as $i => $query)
- {
- $data[$i] = preg_replace('/^#.*$/m', "\n", $query);
- }
- }
-
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....
+ * Removes comments from schema files
+ *
+ * Note: This performs the functions of remove_remarks() and remove_comments() used during installation
*/
- protected function remove_comments(&$output)
+ protected function remove_comments($sql)
{
- $lines = explode("\n", $output);
- $output = '';
-
- // try to keep mem. use down
- $linecount = sizeof($lines);
+ // Remove /* */ comments (http://ostermiller.org/findcomment.html)
+ $sql = preg_replace('#/\*(.|[\r\n])*?\*/#', "\n", $sql);
- $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;
- }
- }
+ // Remove # style comments
+ $sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^#.*$/m', "\n", $sql));
- unset($lines);
- return $output;
+ return $sql;
}
/**
@@ -337,55 +299,46 @@ 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',
),
);