Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
$WPT_TEST_DIR = trim( getenv( 'WPT_TEST_DIR' ) );
$WPT_RM_TEST_DIR_CMD = trim( getenv( 'WPT_RM_TEST_DIR_CMD' ) ) ? : 'rm -r ' . $WPT_TEST_DIR;

// Cleanup the Database.
cleanup_db();

/**
* The directory path of the test preparation directory is assumed to be previously defined.
* For example: $WPT_PREPARE_DIR = '/path/to/your/preparation/dir';
Expand Down
50 changes: 50 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,53 @@ function get_env_details() {
$env['system_utils']['openssl'] = str_replace( 'OpenSSL ', '', trim( shell_exec( 'openssl version' ) ) );
return $env;
}

/**
* Cleanup the Database.
*/
function cleanup_db() {
$prefix = getenv( 'WPT_TABLE_PREFIX' ) ? getenv( 'WPT_TABLE_PREFIX' ) : 'wptests_';

$tables = array(
'users',
'usermeta',
'posts',
'comments',
'links',
'options',
'postmeta',
'terms',
'term_taxonomy',
'term_relationships',
'termmeta',
'commentmeta',
'blogs',
'blogmeta',
'signups',
'site',
'sitemeta',
'sitecategories',
'registration_log',
);

$test_db = new mysqli(
getenv( 'WPT_DB_HOST' ),
getenv( 'WPT_DB_USER' ),
getenv( 'WPT_DB_PASSWORD' ),
getenv( 'WPT_DB_NAME' )
);

if ( $test_db->connect_errno ) {
error_message( 'Could not connect to database.' );
}

log_message( 'Clearing database.' );

foreach ( $tables as $table ) {
if ( ! $test_db->query( "DROP TABLE IF EXISTS {$prefix}{$table}" ) ) {
error_message( "Aborting. Could not DROP table {$prefix}{$table}." );
}
}

$test_db->close();
}