Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions tests/phpunit/tests/taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,30 @@ 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' );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unregister_taxonomy( 'foo' );
unregister_post_type( 'cpt_default_term' );
unregister_post_type( 'test_cpt' );

unregister_taxonomy( 'tax_new' );
unregister_taxonomy( 'test_tax' );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also replace the manual taxonomy unsets in test_register_taxonomy(), test_register_hierarchical_taxonomy(), and test_registering_taxonomies_to_object_types() with unregister_taxonomy( $tax ). Once the object is unset, teardown cannot unregister it. With pretty permalinks, the actual tests leave tax_new/test_tax rewrite tags and permastructs. The replacement preserved their assertions and cleared that residue in local probes.

AI review · gpt-6

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' ) );
}
Expand Down Expand Up @@ -212,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() {
Expand All @@ -226,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 );
}

/**
Expand Down Expand Up @@ -341,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 );
}

Expand Down Expand Up @@ -646,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' );
}

/**
Expand Down
Loading