Changeset 38398
- Timestamp:
- 08/27/2016 08:35:16 AM (8 years ago)
- Location:
- trunk/tests/phpunit
- Files:
-
- 51 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/functions.php
r38285 r38398 49 49 } 50 50 51 function _delete_all_data() { 52 global $wpdb; 53 54 foreach ( array( 55 $wpdb->posts, 56 $wpdb->postmeta, 57 $wpdb->comments, 58 $wpdb->commentmeta, 59 $wpdb->term_relationships, 60 $wpdb->termmeta 61 ) as $table ) { 62 $wpdb->query( "DELETE FROM {$table}" ); 63 } 64 65 foreach ( array( 66 $wpdb->terms, 67 $wpdb->term_taxonomy 68 ) as $table ) { 69 $wpdb->query( "DELETE FROM {$table} WHERE term_id != 1" ); 70 } 71 72 $wpdb->query( "UPDATE {$wpdb->term_taxonomy} SET count = 0" ); 73 74 $wpdb->query( "DELETE FROM {$wpdb->users} WHERE ID != 1" ); 75 $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE user_id != 1" ); 76 } 77 51 78 function _delete_all_posts() { 52 79 global $wpdb; 53 80 54 $all_posts = $wpdb->get_col("SELECT ID from {$wpdb->posts}"); 55 if ($all_posts) { 56 foreach ($all_posts as $id) 57 wp_delete_post( $id, true ); 81 $all_posts = $wpdb->get_results( "SELECT ID, post_type from {$wpdb->posts}", ARRAY_A ); 82 if ( ! $all_posts ) { 83 return; 84 } 85 86 foreach ( $all_posts as $data ) { 87 if ( 'attachment' === $data['post_type'] ) { 88 wp_delete_attachment( $data['ID'], true ); 89 } else { 90 wp_delete_post( $data['ID'], true ); 91 } 58 92 } 59 93 } -
trunk/tests/phpunit/includes/testcase-canonical.php
r36236 r38398 16 16 public $structure = '/%year%/%monthnum%/%day%/%postname%/'; 17 17 18 public static function wpSetUpBeforeClass( $factory ) { 19 self::generate_shared_fixtures( $factory ); 20 } 21 22 public static function wpTearDownAfterClass() { 23 self::delete_shared_fixtures(); 24 } 25 18 26 public function setUp() { 19 27 parent::setUp(); … … 135 143 */ 136 144 public static function delete_shared_fixtures() { 137 self::delete_user( self::$author_id );138 139 foreach ( self::$post_ids as $pid ) {140 wp_delete_post( $pid, true );141 }142 143 foreach ( self::$comment_ids as $cid ) {144 wp_delete_comment( $cid, true );145 }146 147 foreach ( self::$term_ids as $tid => $tax ) {148 wp_delete_term( $tid, $tax );149 }150 151 145 self::$author_id = null; 152 146 self::$post_ids = array(); -
trunk/tests/phpunit/includes/testcase.php
r37861 r38398 62 62 $c = self::get_called_class(); 63 63 if ( ! method_exists( $c, 'wpSetUpBeforeClass' ) ) { 64 self::commit_transaction(); 64 65 return; 65 66 } … … 73 74 parent::tearDownAfterClass(); 74 75 76 _delete_all_data(); 77 self::flush_cache(); 78 75 79 $c = self::get_called_class(); 76 80 if ( ! method_exists( $c, 'wpTearDownAfterClass' ) ) { 81 self::commit_transaction(); 77 82 return; 78 83 } … … 159 164 $_GET = array(); 160 165 $_POST = array(); 161 $this->flush_cache();166 self::flush_cache(); 162 167 } 163 168 … … 244 249 } 245 250 246 function flush_cache() {251 static function flush_cache() { 247 252 global $wp_object_cache; 248 253 $wp_object_cache->group_ops = array(); … … 446 451 unset($_SERVER['PATH_INFO']); 447 452 448 $this->flush_cache();453 self::flush_cache(); 449 454 unset($GLOBALS['wp_query'], $GLOBALS['wp_the_query']); 450 455 $GLOBALS['wp_the_query'] = new WP_Query(); -
trunk/tests/phpunit/tests/admin/includesComment.php
r38372 r38398 43 43 44 44 /** 45 * Delete the post and comments for the tests.46 */47 public static function wpTearDownAfterClass() {48 foreach ( self::$comment_ids as $comment_id ) {49 wp_delete_comment( $comment_id, true );50 }51 52 wp_delete_post( self::$post_id, true );53 }54 55 /**56 45 * Verify that both the comment date and author must match for a comment to exist. 57 46 */ -
trunk/tests/phpunit/tests/admin/includesFile.php
r25002 r38398 6 6 */ 7 7 class Tests_Admin_includesFile extends WP_UnitTestCase { 8 9 function setUp() {10 parent::setUp();11 }12 8 13 9 /** -
trunk/tests/phpunit/tests/admin/includesListTable.php
r35186 r38398 5 5 */ 6 6 class Tests_Admin_includesListTable extends WP_UnitTestCase { 7 protected static $top ;8 protected static $children ;9 protected static $grandchildren ;10 protected static $post_ids ;7 protected static $top = array(); 8 protected static $children = array(); 9 protected static $grandchildren = array(); 10 protected static $post_ids = array(); 11 11 12 12 function setUp() { … … 62 62 } 63 63 } 64 }65 }66 67 public static function wpTearDownAfterClass() {68 foreach ( self::$post_ids as $post_id ) {69 wp_delete_post( $post_id, true );70 64 } 71 65 } -
trunk/tests/phpunit/tests/admin/includesPost.php
r37914 r38398 21 21 22 22 self::$post_id = $factory->post->create(); 23 }24 25 public static function wpTearDownAfterClass() {26 foreach ( self::$user_ids as $id ) {27 self::delete_user( $id );28 }29 30 wp_delete_post( self::$post_id, true );31 23 } 32 24 -
trunk/tests/phpunit/tests/adminbar.php
r38035 r38398 27 27 } 28 28 29 public static function wpTearDownAfterClass() {30 foreach ( self::$user_ids as $id ) {31 self::delete_user( $id );32 }33 }34 35 29 /** 36 30 * @ticket 21117 -
trunk/tests/phpunit/tests/ajax/Autosave.php
r35311 r38398 34 34 self::$post_id = $factory->post->create( array( 'post_status' => 'draft' ) ); 35 35 self::$post = get_post( self::$post_id ); 36 }37 38 public static function wpTearDownAfterClass() {39 foreach ( self::$user_ids as $user_id ) {40 self::delete_user( $user_id );41 }42 43 wp_delete_post( self::$post_id, true );44 36 } 45 37 -
trunk/tests/phpunit/tests/ajax/DeleteComment.php
r37404 r38398 35 35 } 36 36 37 public static function wpTearDownAfterClass() {38 wp_delete_post( self::$post_id, true );39 40 foreach ( self::$comments as $c ) {41 wp_delete_comment( $c->ID, true );42 }43 }44 45 37 /** 46 38 * Clear the POST actions in between requests -
trunk/tests/phpunit/tests/ajax/GetComments.php
r35311 r38398 34 34 self::$comment_ids = $factory->comment->create_post_comments( self::$comment_post->ID, 5 ); 35 35 self::$no_comment_post = $factory->post->create_and_get(); 36 }37 38 public static function wpTearDownAfterClass() {39 foreach ( self::$comment_ids as $comment_id ) {40 wp_delete_comment( $comment_id, true );41 }42 43 wp_delete_post( self::$comment_post->ID, true );44 wp_delete_post( self::$no_comment_post->ID, true );45 36 } 46 37 -
trunk/tests/phpunit/tests/ajax/ReplytoComment.php
r35311 r38398 36 36 } 37 37 38 public static function wpTearDownAfterClass() {39 foreach ( self::$comment_ids as $comment_id ) {40 wp_delete_comment( $comment_id, true );41 }42 43 wp_delete_post( self::$comment_post->ID, true );44 wp_delete_post( self::$draft_post->ID, true );45 }46 47 38 public function tearDown() { 48 39 remove_filter( 'query', array( $this, '_block_comments' ) ); -
trunk/tests/phpunit/tests/ajax/TagSearch.php
r35311 r38398 29 29 foreach ( self::$terms as $t ) { 30 30 self::$term_ids[] = wp_insert_term( $t, 'post_tag' ); 31 }32 }33 34 public static function wpTearDownAfterClass() {35 foreach ( self::$term_ids as $t ) {36 wp_delete_term( $t, 'post_tag' );37 31 } 38 32 } -
trunk/tests/phpunit/tests/auth.php
r36617 r38398 27 27 } 28 28 29 public static function wpTearDownAfterClass() {30 self::delete_user( self::$user_id );31 }32 33 29 function setUp() { 34 30 parent::setUp(); -
trunk/tests/phpunit/tests/canonical.php
r38063 r38398 10 10 */ 11 11 class Tests_Canonical extends WP_Canonical_UnitTestCase { 12 public static function wpSetUpBeforeClass( $factory ) {13 self::generate_shared_fixtures( $factory );14 }15 16 public static function wpTearDownAfterClass() {17 self::delete_shared_fixtures();18 }19 12 20 13 public function setUp() { -
trunk/tests/phpunit/tests/canonical/category.php
r38216 r38398 21 21 wp_set_post_categories( self::$posts[0], self::$cats[0] ); 22 22 wp_set_post_categories( self::$posts[1], self::$cats[1] ); 23 }24 25 public static function wpTearDownAfterClass() {26 foreach ( self::$posts as $post_id ) {27 wp_delete_post( $post_id, true );28 }29 30 foreach ( self::$cats as $cat ) {31 wp_delete_term( $cat, 'category' );32 }33 23 } 34 24 -
trunk/tests/phpunit/tests/canonical/noRewrite.php
r35191 r38398 11 11 12 12 // These test cases are run against the test handler in WP_Canonical 13 public static function wpSetUpBeforeClass( $factory ) {14 self::generate_shared_fixtures( $factory );15 }16 17 public static function wpTearDownAfterClass() {18 self::delete_shared_fixtures();19 }20 13 21 14 public function setUp() { -
trunk/tests/phpunit/tests/canonical/pageOnFront.php
r36238 r38398 7 7 */ 8 8 class Tests_Canonical_PageOnFront extends WP_Canonical_UnitTestCase { 9 public static function wpSetUpBeforeClass( $factory ) {10 self::generate_shared_fixtures( $factory );11 }12 13 public static function wpTearDownAfterClass() {14 self::delete_shared_fixtures();15 }16 9 17 10 function setUp() { -
trunk/tests/phpunit/tests/comment.php
r37954 r38398 24 24 'post_author' => self::$user_id 25 25 ) ); 26 }27 28 public static function wpTearDownAfterClass() {29 wp_delete_post( self::$post_id, true );30 31 self::delete_user( self::$user_id );32 26 } 33 27 -
trunk/tests/phpunit/tests/comment/getCommentAuthorEmailLink.php
r37348 r38398 27 27 'comment_author_email' => 'foo@example.org' 28 28 ) ); 29 }30 31 public static function wpTearDownAfterClass() {32 wp_delete_comment( self::$comment->comment_ID, true );33 29 } 34 30 -
trunk/tests/phpunit/tests/comment/getCommentAuthorUrlLink.php
r37305 r38398 12 12 $comment_ids = $factory->comment->create_post_comments( 0, 1 ); 13 13 self::$comments = array_map( 'get_comment', $comment_ids ); 14 }15 16 public static function wpTearDownAfterClass() {17 foreach ( self::$comments as $comment ) {18 wp_delete_comment( $comment, true );19 }20 14 } 21 15 -
trunk/tests/phpunit/tests/comment/getCommentLink.php
r35933 r38398 43 43 ) ); 44 44 45 }46 47 public static function wpTearDownAfterClass() {48 foreach ( self::$comments as $c ) {49 wp_delete_comment( $c, true );50 }51 52 wp_delete_post( self::$p, true );53 45 } 54 46 -
trunk/tests/phpunit/tests/comment/query.php
r38001 r38398 12 12 public static function wpSetUpBeforeClass( $factory ) { 13 13 self::$post_id = $factory->post->create(); 14 }15 16 public static function wpTearDownAfterClass() {17 wp_delete_post( self::$post_id, true );18 14 } 19 15 -
trunk/tests/phpunit/tests/comment/wpComment.php
r38381 r38398 21 21 22 22 self::$comment_id = self::factory()->comment->create(); 23 }24 25 public static function wpTearDownAfterClass() {26 wp_delete_comment( 1, true );27 wp_delete_comment( self::$comment_id, true );28 23 } 29 24 -
trunk/tests/phpunit/tests/customize/section.php
r35249 r38398 12 12 public static function wpSetUpBeforeClass( $factory ) { 13 13 self::$user_ids[] = self::$admin_id = $factory->user->create( array( 'role' => 'administrator' ) ); 14 }15 16 public static function wpTearDownAfterClass() {17 foreach ( self::$user_ids as $id ) {18 self::delete_user( $id );19 }20 14 } 21 15 -
trunk/tests/phpunit/tests/feed/atom.php
r36519 r38398 43 43 } 44 44 45 }46 47 /**48 * Destroy the user we created and related posts.49 */50 public static function wpTearDownAfterClass() {51 // Delete our user52 self::delete_user( self::$user_id );53 54 // Delete all of our posts55 foreach ( self::$posts as $post ) {56 wp_delete_post( $post, true );57 }58 59 // Delete our taxonomy60 wp_delete_category( self::$category->term_id );61 45 } 62 46 -
trunk/tests/phpunit/tests/feed/rss2.php
r36519 r38398 45 45 46 46 /** 47 * Destroy the user we created and related posts.48 */49 public static function wpTearDownAfterClass() {50 // Delete our user51 self::delete_user( self::$user_id );52 53 // Delete all of our posts54 foreach ( self::$posts as $post ) {55 wp_delete_post( $post, true );56 }57 58 // Delete our taxonomy59 wp_delete_category( self::$category->term_id );60 }61 62 /**63 47 * Setup. 64 48 */ -
trunk/tests/phpunit/tests/functions/getArchives.php
r37271 r38398 22 22 public static function wpSetUpBeforeClass( $factory ) { 23 23 self::$post_ids = $factory->post->create_many( 8, array( 'post_type' => 'post', 'post_author' => '1' ) ); 24 }25 26 public static function wpTearDownAfterClass() {27 foreach ( self::$post_ids as $post_id ) {28 wp_delete_post( $post_id, true );29 }30 24 } 31 25 -
trunk/tests/phpunit/tests/link/wpGetCanonicalURL.php
r37685 r38398 13 13 'post_status' => 'publish', 14 14 ) ); 15 }16 17 public static function wpTearDownAfterClass() {18 wp_delete_post( self::$post_id, true );19 15 } 20 16 -
trunk/tests/phpunit/tests/media.php
r38383 r38398 18 18 19 19 public static function wpTearDownAfterClass() { 20 wp_delete_attachment( self::$large_id );21 22 20 $GLOBALS['_wp_additional_image_sizes'] = self::$_sizes; 23 21 } -
trunk/tests/phpunit/tests/meta/registerMeta.php
r38095 r38398 8 8 public static function wpSetUpBeforeClass( $factory ) { 9 9 self::$post_id = $factory->post->create(); 10 }11 12 public static function wpTearDownAfterClass() {13 wp_delete_post( self::$post_id, true );14 10 } 15 11 -
trunk/tests/phpunit/tests/meta/slashes.php
r36787 r38398 15 15 self::$post_id = $factory->post->create(); 16 16 self::$comment_id = $factory->comment->create( array( 'comment_post_ID' => self::$post_id ) ); 17 }18 19 public static function wpTearDownAfterClass() {20 self::delete_user( self::$editor_id );21 wp_delete_comment( self::$comment_id, true );22 wp_delete_post( self::$post_id, true );23 17 } 24 18 -
trunk/tests/phpunit/tests/post.php
r38143 r38398 24 24 25 25 public static function wpTearDownAfterClass() { 26 $ids = array( self::$editor_id, self::$grammarian_id );27 foreach ( $ids as $id ) {28 self::delete_user( $id );29 }30 26 remove_role( 'grammarian' ); 31 27 } -
trunk/tests/phpunit/tests/post/revisions.php
r36659 r38398 14 14 self::$editor_user_id = $factory->user->create( array( 'role' => 'editor' ) ); 15 15 self::$author_user_id = $factory->user->create( array( 'role' => 'author' ) ); 16 }17 18 public static function wpTearDownAfterClass() {19 $ids = array( self::$admin_user_id, self::$editor_user_id, self::$author_user_id );20 foreach ( $ids as $id ) {21 self::delete_user( $id );22 }23 16 } 24 17 -
trunk/tests/phpunit/tests/post/thumbnails.php
r38263 r38398 17 17 } 18 18 19 public static function wpTearDownAfterClass() {20 wp_delete_post( self::$post->ID, true );21 wp_delete_attachment( self::$attachment_id, true );22 }23 24 19 function test_has_post_thumbnail() { 25 20 $this->assertFalse( has_post_thumbnail( self::$post ) ); -
trunk/tests/phpunit/tests/post/wpPost.php
r38381 r38398 19 19 20 20 self::$post_id = self::factory()->post->create(); 21 }22 23 public static function wpTearDownAfterClass() {24 wp_delete_post( 1, true );25 wp_delete_post( self::$post_id, true );26 21 } 27 22 -
trunk/tests/phpunit/tests/query/date.php
r37324 r38398 46 46 } 47 47 48 public static function wpTearDownAfterClass() {49 foreach ( self::$post_ids as $post_id ) {50 wp_delete_post( $post_id, true );51 }52 }53 54 48 public function setUp() { 55 49 parent::setUp(); -
trunk/tests/phpunit/tests/query/postStatus.php
r35242 r38398 26 26 } 27 27 28 public static function wpTearDownAfterClass() {29 $ids = array( self::$editor_user_id, self::$author_user_id );30 foreach ( $ids as $id ) {31 self::delete_user( $id );32 }33 34 wp_delete_post( self::$editor_private_post, true );35 wp_delete_post( self::$author_private_post, true );36 wp_delete_post( self::$editor_privatefoo_post, true );37 wp_delete_post( self::$author_privatefoo_post, true );38 }39 40 28 public function test_any_should_not_include_statuses_where_exclude_from_search_is_true() { 41 29 register_post_status( 'foo', array( 'exclude_from_search' => true ) ); -
trunk/tests/phpunit/tests/query/results.php
r38382 r38398 68 68 } 69 69 70 public static function wpTearDownAfterClass() {71 foreach ( self::$cat_ids as $cat_id ) {72 wp_delete_term( $cat_id, 'category' );73 }74 75 foreach ( self::$tag_ids as $tag_id ) {76 wp_delete_term( $tag_id, 'post_tag' );77 }78 79 foreach ( self::$post_ids as $post_id ) {80 wp_delete_post( $post_id, true );81 }82 }83 84 70 function setUp() { 85 71 parent::setUp(); -
trunk/tests/phpunit/tests/query/stickies.php
r35186 r38398 22 22 stick_post( self::$posts[14] ); 23 23 stick_post( self::$posts[8] ); 24 }25 26 public static function wpTearDownAfterClass() {27 foreach ( self::$posts as $p ) {28 wp_delete_post( $p, true );29 }30 24 } 31 25 -
trunk/tests/phpunit/tests/rewrite/addRewriteEndpoint.php
r35260 r38398 14 14 ) ); 15 15 self::$test_post_id = $factory->post->create(); 16 }17 18 public static function wpTearDownAfterClass() {19 wp_delete_post( self::$test_page_id, true );20 wp_delete_post( self::$test_post_id, true );21 16 } 22 17 -
trunk/tests/phpunit/tests/term.php
r37644 r38398 10 10 public static function wpSetUpBeforeClass( $factory ) { 11 11 self::$post_ids = $factory->post->create_many( 5 ); 12 }13 14 public static function wpTearDownAfterClass() {15 foreach ( self::$post_ids as $post_id ) {16 wp_delete_post( $post_id, true );17 }18 12 } 19 13 -
trunk/tests/phpunit/tests/term/getTheTerms.php
r37573 r38398 10 10 public static function wpSetUpBeforeClass( $factory ) { 11 11 self::$post_ids = $factory->post->create_many( 5 ); 12 }13 14 public static function wpTearDownAfterClass() {15 foreach ( self::$post_ids as $post_id ) {16 wp_delete_post( $post_id, true );17 }18 12 } 19 13 -
trunk/tests/phpunit/tests/term/wpSetObjectTerms.php
r38382 r38398 10 10 public static function wpSetUpBeforeClass( $factory ) { 11 11 self::$post_ids = $factory->post->create_many( 5 ); 12 }13 14 public static function wpTearDownAfterClass() {15 foreach ( self::$post_ids as $post_id ) {16 wp_delete_post( $post_id, true );17 }18 12 } 19 13 -
trunk/tests/phpunit/tests/term/wpTerm.php
r38381 r38398 32 32 33 33 self::$term_id = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) ); 34 }35 36 public static function wpTearDownAfterClass() {37 wp_delete_term( 1, 'wptests_tax' );38 wp_delete_term( self::$term_id, 'wptests_tax' );39 34 } 40 35 -
trunk/tests/phpunit/tests/user.php
r38382 r38398 45 45 46 46 self::$_author = get_user_by( 'ID', self::$author_id ); 47 }48 49 public static function wpTearDownAfterClass() {50 foreach ( self::$user_ids as $id ) {51 self::delete_user( $id );52 }53 47 } 54 48 -
trunk/tests/phpunit/tests/user/capabilities.php
r38096 r38398 19 19 'subscriber' => $factory->user->create_and_get( array( 'role' => 'subscriber' ) ), 20 20 ); 21 }22 23 public static function wpTearDownAfterClass() {24 foreach ( self::$users as $role => $user ) {25 self::delete_user( $user->ID );26 }27 21 } 28 22 … … 1192 1186 foreach ( $caps as $cap => $roles ) { 1193 1187 $this->assertFalse( current_user_can( $cap ), "Non-logged-in user should not have the {$cap} capability" ); 1194 } 1188 } 1195 1189 1196 1190 } -
trunk/tests/phpunit/tests/user/countUserPosts.php
r35244 r38398 28 28 'post_type' => 'wptests_pt', 29 29 ) ) ); 30 30 31 31 self::$post_ids[] = $factory->post->create( array( 32 32 'post_author' => 12345, 33 33 'post_type' => 'wptests_pt', 34 34 ) ); 35 }36 37 public static function wpTearDownAfterClass() {38 self::delete_user( self::$user_id );39 40 foreach ( self::$post_ids as $post_id ) {41 wp_delete_post( $post_id, true );42 }43 35 } 44 36 -
trunk/tests/phpunit/tests/user/listAuthors.php
r35244 r38398 38 38 39 39 self::$user_urls[] = get_author_posts_url( $userid ); 40 }41 }42 43 public static function wpTearDownAfterClass() {44 self::$user_ids[] = self::$fred_id;45 46 foreach ( self::$user_ids as $user_id ) {47 self::delete_user( $user_id );48 }49 50 foreach ( self::$posts as $post_id ) {51 wp_delete_post( $post_id, true );52 40 } 53 41 } -
trunk/tests/phpunit/tests/user/query.php
r37360 r38398 34 34 'role' => 'administrator', 35 35 ) ); 36 }37 38 public static function wpTearDownAfterClass() {39 $sets = array(40 self::$author_ids,41 self::$sub_ids,42 self::$editor_ids,43 array( self::$contrib_id ),44 self::$admin_ids45 );46 47 foreach ( $sets as $set ) {48 foreach ( $set as $id ) {49 self::delete_user( $id );50 }51 }52 36 } 53 37 -
trunk/tests/phpunit/tests/user/wpSetCurrentUser.php
r35248 r38398 12 12 self::$user_ids[] = self::$user_id = $factory->user->create(); 13 13 self::$user_ids[] = self::$user_id2 = $factory->user->create( array( 'user_login' => 'foo', ) ); 14 }15 16 public static function wpTearDownAfterClass() {17 foreach ( self::$user_ids as $id ) {18 self::delete_user( $id );19 }20 14 } 21 15
Note: See TracChangeset
for help on using the changeset viewer.