From 2a8d2143a389ba54100859df6478de2984ec958e Mon Sep 17 00:00:00 2001 From: rejaulalomkhan Date: Tue, 27 Oct 2026 11:04:00 +0600 Subject: [PATCH 1/3] Tests: Unregister custom post types in link tests teardown Unregister the wptests_pt and not_a_post_type custom post types in Tests_Link::tear_down() to prevent leaking custom post type state into subsequent tests. See #65893. --- tests/phpunit/tests/link.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/phpunit/tests/link.php b/tests/phpunit/tests/link.php index b9576a7a1a16a..c589eae3c21e8 100644 --- a/tests/phpunit/tests/link.php +++ b/tests/phpunit/tests/link.php @@ -4,6 +4,13 @@ */ class Tests_Link extends WP_UnitTestCase { + public function tear_down() { + unregister_post_type( 'wptests_pt' ); + unregister_post_type( 'not_a_post_type' ); + + parent::tear_down(); + } + public function test_wp_get_shortlink() { $post_id = self::factory()->post->create(); $post_id2 = self::factory()->post->create(); From bdc1d1b8d8cc55b8f4a4311df0b8c9e3828587f0 Mon Sep 17 00:00:00 2001 From: rejaulalomkhan Date: Sat, 31 Oct 2026 10:26:01 +0600 Subject: [PATCH 2/3] Tests: Unregister not_a_post_type instead of unsetting it in the attachment permalink test. Unsetting the post type object directly left its supports, permastruct and rewrite tag behind, because the teardown could no longer unregister it. See #65893. --- tests/phpunit/tests/link.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/tests/phpunit/tests/link.php b/tests/phpunit/tests/link.php index c589eae3c21e8..644f9fc1269df 100644 --- a/tests/phpunit/tests/link.php +++ b/tests/phpunit/tests/link.php @@ -157,8 +157,6 @@ public function test_unattached_attachment_has_a_pretty_permalink() { * @ticket 1914 */ public function test_attachment_attached_to_non_existent_post_type_has_a_pretty_permalink() { - global $wp_post_types; - $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); register_post_type( 'not_a_post_type', array( 'public' => true ) ); @@ -182,12 +180,7 @@ public function test_attachment_attached_to_non_existent_post_type_has_a_pretty_ $this->assertSame( get_permalink( $post_id ) . user_trailingslashit( $attachment->post_name ), get_permalink( $attachment_id ) ); - foreach ( $wp_post_types as $id => $pt ) { - if ( 'not_a_post_type' === $pt->name ) { - unset( $wp_post_types[ $id ] ); - break; - } - } + unregister_post_type( 'not_a_post_type' ); $this->assertSame( home_url( "/?attachment_id={$attachment->ID}" ), get_permalink( $attachment_id ) ); // Visit permalink. From c0b038ddbfe1e19124b0aeffada8cb0296c575e5 Mon Sep 17 00:00:00 2001 From: rejaulalomkhan Date: Mon, 2 Nov 2026 09:27:29 +0600 Subject: [PATCH 3/3] Tests: Remove the broad tear_down() from Tests_Link. The shared per-test reset in WP_UnitTestCase_Base already unregisters surviving custom post types. Keep only the replacement of the raw registry unset with unregister_post_type(). --- tests/phpunit/tests/link.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/phpunit/tests/link.php b/tests/phpunit/tests/link.php index 644f9fc1269df..ceb12d0c3900d 100644 --- a/tests/phpunit/tests/link.php +++ b/tests/phpunit/tests/link.php @@ -4,13 +4,6 @@ */ class Tests_Link extends WP_UnitTestCase { - public function tear_down() { - unregister_post_type( 'wptests_pt' ); - unregister_post_type( 'not_a_post_type' ); - - parent::tear_down(); - } - public function test_wp_get_shortlink() { $post_id = self::factory()->post->create(); $post_id2 = self::factory()->post->create();