Guest User

Untitled

a guest
Jan 21st, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Validate Shopp Schema file
  5. */
  6. class ClassName extends ShoppTestCase
  7. {
  8. function test_shopp_schema () {
  9. $this->AssertTrue(file_exists(SHOPP_DBSCHEMA));
  10.  
  11. ob_start();
  12. include(SHOPP_DBSCHEMA);
  13. $schema = ob_get_contents();
  14. ob_end_clean();
  15.  
  16. // Update the table schema
  17. // Strip SQL comments
  18. $schema = preg_replace('/--\s?(.*?)\n/',"\n",$schema);
  19. $this->AssertTrue((bool) preg_match_all("|CREATE TABLE ([^ ]*)|", $schema, $matches));
  20. $this->AssertTrue(is_array($matches) && isset($matches[1]) && is_array($matches[1]));
  21. $tables = $matches[1];
  22.  
  23. foreach( $tables as $table ) {
  24. $schema = preg_replace("/$table/", "schematest_$table", $schema);
  25. }
  26.  
  27. $statements = explode(';', $schema);
  28.  
  29. $tables = array();
  30. $checks = true;
  31.  
  32. foreach ( $statements as $i => $statement ) {
  33. $statement = trim(preg_replace('/\s+/', ' ', $statement));
  34. if ( $statement ) {
  35. $checks = $checks && DB::query($statement);
  36. }
  37. }
  38.  
  39. // cleanup
  40. foreach ( $tables as $table ) {
  41. $checks = $checks && DB::query("DROP TABLE $table");
  42. }
  43.  
  44. $this->AssertTrue($checks);
  45. }
  46. }
  47.  
  48. ?>
Add Comment
Please, Sign In to add comment