From 3ffa536fd7a1f3c5e7f3a065f0eeecabab4a0c26 Mon Sep 17 00:00:00 2001 From: rejaulalomkhan Date: Tue, 27 Oct 2026 11:08:11 +0600 Subject: [PATCH 1/5] Tests: Unregister custom taxonomies and post type in taxonomy tests teardown In Tests_Taxonomy, tests register various custom taxonomies ('wptests_tax', 'wptests_tax_1', 'wptests_tax_2', 'taxonomy53212', 'random', 'foo', 'test_tax', 'tax_default_term_1', 'tax_default_term_2') and custom post type 'cpt_default_term'. Add tear_down() to unregister these taxonomies and post type after each test to ensure test isolation and prevent taxonomy pollution across test suites. See #65893. --- tests/phpunit/tests/taxonomy.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/phpunit/tests/taxonomy.php b/tests/phpunit/tests/taxonomy.php index 21b9977a85366..c5d7a56547ca2 100644 --- a/tests/phpunit/tests/taxonomy.php +++ b/tests/phpunit/tests/taxonomy.php @@ -16,6 +16,23 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) ); } + /** + * Tear down after each test. + */ + public function tear_down() { + unregister_taxonomy( 'wptests_tax' ); + unregister_taxonomy( 'wptests_tax_1' ); + unregister_taxonomy( 'wptests_tax_2' ); + unregister_taxonomy( 'taxonomy53212' ); + unregister_taxonomy( 'random' ); + unregister_taxonomy( 'foo' ); + unregister_taxonomy( 'test_tax' ); + unregister_taxonomy( 'tax_default_term_1' ); + unregister_taxonomy( 'tax_default_term_2' ); + unregister_post_type( 'cpt_default_term' ); + parent::tear_down(); + } + public function test_get_post_taxonomies() { $this->assertSame( array( 'category', 'post_tag', 'post_format' ), get_object_taxonomies( 'post' ) ); } From 36ffc7dd2293ef3a75b46915cc20dd4c7c0797fa Mon Sep 17 00:00:00 2001 From: rejaulalomkhan Date: Tue, 27 Oct 2026 13:57:56 +0600 Subject: [PATCH 2/5] Tests: Unregister test_cpt in Tests_Taxonomy teardown Follow-up to address review feedback on PR #14952 by unregistering test_cpt in tear_down(). See #65893. --- tests/phpunit/tests/taxonomy.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/phpunit/tests/taxonomy.php b/tests/phpunit/tests/taxonomy.php index c5d7a56547ca2..c050c3d390bb2 100644 --- a/tests/phpunit/tests/taxonomy.php +++ b/tests/phpunit/tests/taxonomy.php @@ -30,6 +30,7 @@ public function tear_down() { unregister_taxonomy( 'tax_default_term_1' ); unregister_taxonomy( 'tax_default_term_2' ); unregister_post_type( 'cpt_default_term' ); + unregister_post_type( 'test_cpt' ); parent::tear_down(); } From 370a3542e522a41398331efb16a45de94a8c3c8e Mon Sep 17 00:00:00 2001 From: rejaulalomkhan Date: Sat, 31 Oct 2026 10:30:25 +0600 Subject: [PATCH 3/5] Tests: Fix the cleanup list in Tests_Taxonomy::tear_down(). Unregister the taxonomies and post types the tests actually register, and drop names that are never registered in this class. Replace the manual $wp_taxonomies unsets with unregister_taxonomy() so their rewrite tags and permastructs are removed, and drop the wptests_conflict test's cleanup of the wrong post type. See #65893. --- tests/phpunit/tests/taxonomy.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/phpunit/tests/taxonomy.php b/tests/phpunit/tests/taxonomy.php index c050c3d390bb2..e81f38f53dbcc 100644 --- a/tests/phpunit/tests/taxonomy.php +++ b/tests/phpunit/tests/taxonomy.php @@ -23,14 +23,20 @@ public function tear_down() { unregister_taxonomy( 'wptests_tax' ); unregister_taxonomy( 'wptests_tax_1' ); unregister_taxonomy( 'wptests_tax_2' ); + unregister_taxonomy( 'wptests_conflict' ); unregister_taxonomy( 'taxonomy53212' ); unregister_taxonomy( 'random' ); unregister_taxonomy( 'foo' ); + unregister_taxonomy( 'tax_new' ); unregister_taxonomy( 'test_tax' ); - unregister_taxonomy( 'tax_default_term_1' ); - unregister_taxonomy( 'tax_default_term_2' ); - unregister_post_type( 'cpt_default_term' ); + unregister_taxonomy( 'custom-tax' ); + unregister_taxonomy( 'test_tax1' ); + unregister_taxonomy( 'test_tax2' ); unregister_post_type( 'test_cpt' ); + unregister_post_type( 'wptests_pt' ); + unregister_post_type( 'wptests_conflict' ); + unregister_post_type( 'post-custom-tax' ); + unregister_post_type( 'test_post_type' ); parent::tear_down(); } @@ -230,7 +236,7 @@ public function test_register_taxonomy() { $this->assertFalse( is_taxonomy_hierarchical( $tax ) ); // Clean up. - unset( $GLOBALS['wp_taxonomies'][ $tax ] ); + unregister_taxonomy( $tax ); } public function test_register_hierarchical_taxonomy() { @@ -244,7 +250,7 @@ public function test_register_hierarchical_taxonomy() { $this->assertTrue( is_taxonomy_hierarchical( $tax ) ); // Clean up. - unset( $GLOBALS['wp_taxonomies'][ $tax ] ); + unregister_taxonomy( $tax ); } /** @@ -359,7 +365,7 @@ public function test_registering_taxonomies_to_object_types() { $this->assertFalse( register_taxonomy_for_object_type( $tax, 'user' ) ); $this->assertFalse( unregister_taxonomy_for_object_type( $tax, 'user' ) ); - unset( $GLOBALS['wp_taxonomies'][ $tax ] ); + unregister_taxonomy( $tax ); _unregister_post_type( $post_type ); } @@ -664,7 +670,6 @@ public function test_get_ancestors_taxonomy_post_type_conflict_resource_type_tax $this->assertSameSets( array( $p1 ), get_ancestors( $p2, 'wptests_conflict', 'post_type' ) ); $this->assertSameSets( array( $t1 ), get_ancestors( $t2, 'wptests_conflict', 'taxonomy' ) ); $this->assertSameSets( array( $t1 ), get_ancestors( $t2, 'wptests_conflict' ) ); - _unregister_post_type( 'wptests_pt' ); } /** From 29238baff13ac99e424cc03f8d2b16f85b74a05d Mon Sep 17 00:00:00 2001 From: rejaulalomkhan Date: Mon, 2 Nov 2026 09:29:26 +0600 Subject: [PATCH 4/5] Tests: Remove the broad tear_down() from Tests_Taxonomy. The shared per-test reset in WP_UnitTestCase_Base already unregisters surviving custom taxonomies and post types. Keep only the replacements of raw registry unsets and the removal of the wrong-name wptests_pt cleanup. --- tests/phpunit/tests/taxonomy.php | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/tests/phpunit/tests/taxonomy.php b/tests/phpunit/tests/taxonomy.php index e81f38f53dbcc..62ccf00edc79b 100644 --- a/tests/phpunit/tests/taxonomy.php +++ b/tests/phpunit/tests/taxonomy.php @@ -16,30 +16,6 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) ); } - /** - * Tear down after each test. - */ - public function tear_down() { - unregister_taxonomy( 'wptests_tax' ); - unregister_taxonomy( 'wptests_tax_1' ); - unregister_taxonomy( 'wptests_tax_2' ); - unregister_taxonomy( 'wptests_conflict' ); - unregister_taxonomy( 'taxonomy53212' ); - unregister_taxonomy( 'random' ); - unregister_taxonomy( 'foo' ); - unregister_taxonomy( 'tax_new' ); - unregister_taxonomy( 'test_tax' ); - unregister_taxonomy( 'custom-tax' ); - unregister_taxonomy( 'test_tax1' ); - unregister_taxonomy( 'test_tax2' ); - unregister_post_type( 'test_cpt' ); - unregister_post_type( 'wptests_pt' ); - unregister_post_type( 'wptests_conflict' ); - unregister_post_type( 'post-custom-tax' ); - unregister_post_type( 'test_post_type' ); - parent::tear_down(); - } - public function test_get_post_taxonomies() { $this->assertSame( array( 'category', 'post_tag', 'post_format' ), get_object_taxonomies( 'post' ) ); } From 3f02923d9778e165156c8f09e53a752682f3d9fd Mon Sep 17 00:00:00 2001 From: rejaulalomkhan Date: Tue, 3 Nov 2026 09:58:01 +0600 Subject: [PATCH 5/5] Tests: Remove the final taxonomy cleanup from Tests_Taxonomy. These removals run after the final assertions, so leave the registrations in place for the inherited reset_taxonomies() to unregister before the next test. Remove the two stale comments as well. --- tests/phpunit/tests/taxonomy.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/phpunit/tests/taxonomy.php b/tests/phpunit/tests/taxonomy.php index 62ccf00edc79b..e17d9088901f5 100644 --- a/tests/phpunit/tests/taxonomy.php +++ b/tests/phpunit/tests/taxonomy.php @@ -210,9 +210,6 @@ public function test_register_taxonomy() { register_taxonomy( $tax, 'post' ); $this->assertTrue( taxonomy_exists( $tax ) ); $this->assertFalse( is_taxonomy_hierarchical( $tax ) ); - - // Clean up. - unregister_taxonomy( $tax ); } public function test_register_hierarchical_taxonomy() { @@ -224,9 +221,6 @@ public function test_register_hierarchical_taxonomy() { register_taxonomy( $tax, 'post', array( 'hierarchical' => true ) ); $this->assertTrue( taxonomy_exists( $tax ) ); $this->assertTrue( is_taxonomy_hierarchical( $tax ) ); - - // Clean up. - unregister_taxonomy( $tax ); } /** @@ -341,7 +335,6 @@ public function test_registering_taxonomies_to_object_types() { $this->assertFalse( register_taxonomy_for_object_type( $tax, 'user' ) ); $this->assertFalse( unregister_taxonomy_for_object_type( $tax, 'user' ) ); - unregister_taxonomy( $tax ); _unregister_post_type( $post_type ); }