mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-10-03 22:27:04 +00:00
Unit Tests:
* Automatically delete objects that we were created during `wpSetUpBeforeClass` - posts, comments, terms (except 1), and user (except 1) * The amount of leftover data between tests was breathtaking - use the new function: `_delete_all_data()` * Commit database transactions for all `TestCase`s, not just those that implement `wpSetUpBeforeClass` and `wpTearDownAfterClass` * The tests run 10-20 seconds faster now See #37699. git-svn-id: https://develop.svn.wordpress.org/trunk@38398 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -48,13 +48,47 @@ function _test_filter_build_unique_id($tag, $function, $priority) {
|
||||
}
|
||||
}
|
||||
|
||||
function _delete_all_data() {
|
||||
global $wpdb;
|
||||
|
||||
foreach ( array(
|
||||
$wpdb->posts,
|
||||
$wpdb->postmeta,
|
||||
$wpdb->comments,
|
||||
$wpdb->commentmeta,
|
||||
$wpdb->term_relationships,
|
||||
$wpdb->termmeta
|
||||
) as $table ) {
|
||||
$wpdb->query( "DELETE FROM {$table}" );
|
||||
}
|
||||
|
||||
foreach ( array(
|
||||
$wpdb->terms,
|
||||
$wpdb->term_taxonomy
|
||||
) as $table ) {
|
||||
$wpdb->query( "DELETE FROM {$table} WHERE term_id != 1" );
|
||||
}
|
||||
|
||||
$wpdb->query( "UPDATE {$wpdb->term_taxonomy} SET count = 0" );
|
||||
|
||||
$wpdb->query( "DELETE FROM {$wpdb->users} WHERE ID != 1" );
|
||||
$wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE user_id != 1" );
|
||||
}
|
||||
|
||||
function _delete_all_posts() {
|
||||
global $wpdb;
|
||||
|
||||
$all_posts = $wpdb->get_col("SELECT ID from {$wpdb->posts}");
|
||||
if ($all_posts) {
|
||||
foreach ($all_posts as $id)
|
||||
wp_delete_post( $id, true );
|
||||
$all_posts = $wpdb->get_results( "SELECT ID, post_type from {$wpdb->posts}", ARRAY_A );
|
||||
if ( ! $all_posts ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $all_posts as $data ) {
|
||||
if ( 'attachment' === $data['post_type'] ) {
|
||||
wp_delete_attachment( $data['ID'], true );
|
||||
} else {
|
||||
wp_delete_post( $data['ID'], true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user