Make WordPress Core

Changeset 65284


Ignore:
Timestamp:
11/05/2026 11:35:32 PM (33 hours ago)
Author:
lancewillett
Message:

Tests: Remove redundant registration cleanup from post and query tests.

WP_UnitTestCase_Base::set_up() resets post types, taxonomies, and non-built-in post statuses before each test. Per-test unregister calls added to these post, query, comment, and user tests repeated that reset, so remove them.

Keep scenario-specific unregister calls and the class-level callbacks in the query fields and post status tests.

Follow-up to [64839], [64840], [64842], [64861], [64864], [64865], [64975], [65016], [65017], [65019], [65025], [65026].

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/15189

Props peterwilsoncc.
See #65893.

Location:
trunk/tests/phpunit/tests
Files:
27 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/comment/query.php

    r65026 r65284  
    2626
    2727        public function tear_down() {
    28                 unregister_post_type( 'post-type-1' );
    29                 unregister_post_type( 'post-type-2' );
    30                 unregister_post_type( 'post-type-3' );
    31 
    3228                unset( $this->to_exclude );
    3329                parent::tear_down();
  • trunk/tests/phpunit/tests/post.php

    r65243 r65284  
    5959        public static function wpTearDownAfterClass() {
    6060                remove_role( 'grammarian' );
    61         }
    62 
    63         /**
    64          * Tear down after each test.
    65          */
    66         public function tear_down() {
    67                 unregister_post_type( 'restless' );
    68                 unregister_post_type( 'new_post_type' );
    69                 unregister_taxonomy( 'new_tag' );
    70                 _unregister_post_status( 'test' );
    71 
    72                 parent::tear_down();
    7361        }
    7462
  • trunk/tests/phpunit/tests/post/getBodyClass.php

    r64975 r65284  
    2222
    2323        public function tear_down() {
    24                 unregister_taxonomy( 'wptests_tax' );
    25 
    2624                if ( get_stylesheet() !== $this->original_stylesheet ) {
    2725                        switch_theme( $this->original_stylesheet );
  • trunk/tests/phpunit/tests/post/getLastPostDate.php

    r64975 r65284  
    55 */
    66class Tests_Post_GetLastPostDate extends WP_UnitTestCase {
    7 
    8         public function tear_down() {
    9                 unregister_post_type( 'book' );
    10 
    11                 parent::tear_down();
    12         }
    137
    148        /**
  • trunk/tests/phpunit/tests/post/getLastPostModified.php

    r64975 r65284  
    55 */
    66class Tests_Post_GetLastPostModified extends WP_UnitTestCase {
    7 
    8         public function tear_down() {
    9                 unregister_post_type( 'book' );
    10 
    11                 parent::tear_down();
    12         }
    137
    148        /**
  • trunk/tests/phpunit/tests/post/getPageByPath.php

    r65030 r65284  
    55 */
    66class Tests_Post_GetPageByPath extends WP_UnitTestCase {
    7         public function tear_down() {
    8                 unregister_post_type( 'wptests_pt' );
    9 
    10                 parent::tear_down();
    11         }
    12 
    137        /**
    148         * @ticket 15665
  • trunk/tests/phpunit/tests/post/getPages.php

    r65030 r65284  
    4141                        )
    4242                );
    43         }
    44 
    45         public function tear_down() {
    46                 _unregister_post_status( 'foo' );
    47                 unregister_post_type( 'wptests_pt' );
    48 
    49                 parent::tear_down();
    5043        }
    5144
  • trunk/tests/phpunit/tests/post/getPostClass.php

    r64864 r65284  
    1111                parent::set_up();
    1212                $this->post_id = self::factory()->post->create();
    13         }
    14 
    15         /**
    16          * Tear down after each test.
    17          */
    18         public function tear_down() {
    19                 unregister_taxonomy( 'wptests_tax' );
    20                 parent::tear_down();
    2113        }
    2214
  • trunk/tests/phpunit/tests/post/metaRevisions.php

    r65030 r65284  
    1111 */
    1212class Tests_Post_MetaRevisions extends WP_UnitTestCase {
    13         /**
    14          * Tear down after each test.
    15          */
    16         public function tear_down() {
    17                 unregister_post_type( 'custom_type' );
    18                 parent::tear_down();
    19         }
    20 
    2113
    2214        /**
  • trunk/tests/phpunit/tests/post/nav-menu.php

    r65270 r65284  
    1414
    1515                $this->menu_id = wp_create_nav_menu( 'foo' );
    16         }
    17 
    18         public function tear_down() {
    19                 unregister_post_type( 'fooo-bar-baz' );
    20                 unregister_post_type( 'books' );
    21                 unregister_taxonomy( 'wptests_tax' );
    22 
    23                 parent::tear_down();
    2416        }
    2517
  • trunk/tests/phpunit/tests/post/randomablePostType.php

    r65030 r65284  
    2828
    2929        /**
    30          * Tear down after each test.
    31          */
    32         public function tear_down(): void {
    33                 unregister_post_type( 'wptests_pt' );
    34                 unregister_post_type( 'wptests_noarchive' );
    35                 parent::tear_down();
    36         }
    37 
    38         /**
    3930         * @dataProvider data_built_in_post_types
    4031         *
  • trunk/tests/phpunit/tests/post/types.php

    r65270 r65284  
    3737
    3838                $this->post_type = 'foo1';
    39         }
    40 
    41         /**
    42          * Tear down after each test.
    43          */
    44         public function tear_down() {
    45                 unregister_post_type( 'foo' );
    46                 unregister_post_type( 'bar' );
    47                 unregister_post_type( 'book' );
    48                 unregister_post_type( 'magazine' );
    49                 unregister_post_type( 'shelf' );
    50                 unregister_post_type( 'cpt' );
    51                 unregister_post_type( $this->post_type );
    52                 parent::tear_down();
    5339        }
    5440
  • trunk/tests/phpunit/tests/post/updateTermCountOnTransitionPostStatus.php

    r65025 r65284  
    5454
    5555        /**
    56          * Tear down after each test.
    57          */
    58         public function tear_down() {
    59                 unregister_taxonomy( 'category_with_pending' );
    60                 _unregister_post_status( 'counted' );
    61                 parent::tear_down();
    62         }
    63 
    64         /**
    6556         * Test that the term count is updated when a post is published.
    6657         *
  • trunk/tests/phpunit/tests/post/wpPublishPost.php

    r64865 r65284  
    2121        public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
    2222                self::$auto_draft_id = $factory->post->create( array( 'post_status' => 'auto-draft' ) );
    23         }
    24 
    25         /**
    26          * Tear down after each test.
    27          */
    28         public function tear_down() {
    29                 unregister_taxonomy( 'tax_51292' );
    30                 parent::tear_down();
    3123        }
    3224
  • trunk/tests/phpunit/tests/query/cacheResults.php

    r65030 r65284  
    7272                        )
    7373                );
    74         }
    75 
    76         public function tear_down() {
    77                 unregister_taxonomy( 'wptests_tax1' );
    78                 parent::tear_down();
    7974        }
    8075
  • trunk/tests/phpunit/tests/query/conditionals.php

    r65270 r65284  
    3939                create_initial_taxonomies();
    4040                flush_rewrite_rules();
    41         }
    42 
    43         public function tear_down() {
    44                 unregister_post_type( 'ptawtq' );
    45                 unregister_post_type( 'thearray' );
    46                 unregister_post_type( 'test_hierarchical' );
    47                 parent::tear_down();
    4841        }
    4942
  • trunk/tests/phpunit/tests/query/fieldsClause.php

    r64840 r65284  
    4444        }
    4545
    46         public function tear_down() {
    47                 unregister_post_type( 'wptests_pt' );
    48                 parent::tear_down();
    49         }
    50 
    5146        /**
    5247         * Tests limiting the WP_Query fields to the ID and parent sub-set.
  • trunk/tests/phpunit/tests/query/isTerm.php

    r65270 r65284  
    5959        }
    6060
    61         /**
    62          * Tear down after each test.
    63          */
    64         public function tear_down() {
    65                 unregister_taxonomy( 'testtax' );
    66                 unregister_taxonomy( 'testtax2' );
    67                 parent::tear_down();
    68         }
    69 
    7061        public function test_tag_action_tax() {
    7162                // Tag with taxonomy added.
  • trunk/tests/phpunit/tests/query/lazyLoadTermMeta.php

    r64865 r65284  
    3939                        }
    4040                }
    41         }
    42 
    43         public function tear_down() {
    44                 unregister_taxonomy( 'wptests_tax' );
    45                 parent::tear_down();
    4641        }
    4742
  • trunk/tests/phpunit/tests/query/postStatus.php

    r64975 r65284  
    8787                parent::set_up();
    8888                self::register_custom_post_objects();
    89         }
    90 
    91         public function tear_down() {
    92                 unregister_post_type( 'foo_pt' );
    93                 unregister_post_type( 'wptests_pt1' );
    94                 unregister_post_type( 'wptests_pt2' );
    95                 _unregister_post_status( 'foo' );
    96                 _unregister_post_status( 'foo_ps' );
    97                 _unregister_post_status( 'privatefoo' );
    98 
    99                 parent::tear_down();
    10089        }
    10190
  • trunk/tests/phpunit/tests/query/results.php

    r64975 r65284  
    300300                unset( $this->q );
    301301                $this->q = new WP_Query();
    302         }
    303 
    304         public function tear_down() {
    305                 unregister_post_type( 'handbook' );
    306 
    307                 parent::tear_down();
    308302        }
    309303
  • trunk/tests/phpunit/tests/query/search.php

    r64840 r65284  
    1818
    1919        public function tear_down() {
    20                 unregister_post_type( $this->post_type );
    2120                unset( $this->q );
    2221
  • trunk/tests/phpunit/tests/query/taxQuery.php

    r65026 r65284  
    66 */
    77class Tests_Query_TaxQuery extends WP_UnitTestCase {
    8         /**
    9          * Tear down after each test.
    10          */
    11         public function tear_down() {
    12                 unregister_taxonomy( 'wptests_tax' );
    13                 unregister_taxonomy( 'wptests_tax1' );
    14                 unregister_taxonomy( 'wptests_tax2' );
    15                 unregister_taxonomy( 'foo' );
    16                 unregister_taxonomy( 'foo1' );
    17                 unregister_taxonomy( 'bar' );
    18                 unregister_post_type( 'wptests_cpt1' );
    19 
    20                 parent::tear_down();
    21         }
    22 
    238        public function test_tax_query_single_query_single_term_field_slug() {
    249                $t  = self::factory()->term->create(
  • trunk/tests/phpunit/tests/user/countUserPosts.php

    r64839 r65284  
    5959        }
    6060
    61         public function tear_down() {
    62                 unregister_post_type( 'wptests_pt' );
    63                 parent::tear_down();
    64         }
    65 
    6661        public function test_count_user_posts_post_type_should_default_to_post() {
    6762                $this->assertSame( '4', count_user_posts( self::$user_id ) );
  • trunk/tests/phpunit/tests/user/query.php

    r65025 r65284  
    4848                        )
    4949                );
    50         }
    51 
    52         /**
    53          * Tear down after each test.
    54          */
    55         public function tear_down() {
    56                 unregister_post_type( 'wptests_pt_public' );
    57                 unregister_post_type( 'wptests_pt_private' );
    58 
    59                 parent::tear_down();
    6050        }
    6151
  • trunk/tests/phpunit/tests/user/queryCache.php

    r65073 r65284  
    7272                        )
    7373                );
    74         }
    75 
    76         public function tear_down() {
    77                 unregister_post_type( 'wptests_pt_public' );
    78                 parent::tear_down();
    7974        }
    8075
  • trunk/tests/phpunit/tests/user/theAuthorPosts.php

    r64984 r65284  
    7070         */
    7171        public function tear_down() {
    72                 unregister_post_type( 'wptests_cpt' );
    7372                unset( $GLOBALS['post'], $GLOBALS['authordata'] );
    7473
Note: See TracChangeset for help on using the changeset viewer.