Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Validate Shopp Schema file
- */
- class ClassName extends ShoppTestCase
- {
- function test_shopp_schema () {
- $this->AssertTrue(file_exists(SHOPP_DBSCHEMA));
- ob_start();
- include(SHOPP_DBSCHEMA);
- $schema = ob_get_contents();
- ob_end_clean();
- // Update the table schema
- // Strip SQL comments
- $schema = preg_replace('/--\s?(.*?)\n/',"\n",$schema);
- $this->AssertTrue((bool) preg_match_all("|CREATE TABLE ([^ ]*)|", $schema, $matches));
- $this->AssertTrue(is_array($matches) && isset($matches[1]) && is_array($matches[1]));
- $tables = $matches[1];
- foreach( $tables as $table ) {
- $schema = preg_replace("/$table/", "schematest_$table", $schema);
- }
- $statements = explode(';', $schema);
- $tables = array();
- $checks = true;
- foreach ( $statements as $i => $statement ) {
- $statement = trim(preg_replace('/\s+/', ' ', $statement));
- if ( $statement ) {
- $checks = $checks && DB::query($statement);
- }
- }
- // cleanup
- foreach ( $tables as $table ) {
- $checks = $checks && DB::query("DROP TABLE $table");
- }
- $this->AssertTrue($checks);
- }
- }
- ?>
Add Comment
Please, Sign In to add comment