Skip to content

Tests: Clean up custom post type in Tests_AdminBar - #15455

Open
devmuhib009 wants to merge 2 commits into
WordPress:trunkfrom
devmuhib009:test/cleanup-cpt-adminbar
Open

devmuhib009 wants to merge 2 commits into
WordPress:trunkfrom
devmuhib009:test/cleanup-cpt-adminbar

Conversation

@devmuhib009

Copy link
Copy Markdown
Member

Trac ticket: https://core.trac.wordpress.org/ticket/65893

This PR unregisters the content custom post type registered during Tests_AdminBar::test_content_post_type() in tear_down() using the public unregister_post_type() function, preventing fixture leakage and removing the internal mid-test unregistration call.

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props devmuhib, huzaifaalmesbah.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@huzaifaalmesbah huzaifaalmesbah left a comment

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.

Hi @devmuhib009,

Nice work cleaning up the content custom post type in tear_down()!

While reviewing Tests_AdminBar, I noticed that foo-non-public is also registered across three test methods (test_admin_bar_has_no_archives_link_for_non_public_cpt, test_admin_bar_has_no_archives_link_for_cpt_without_archive, and test_admin_bar_has_no_archives_link_for_cpt_not_shown_in_admin_bar) with mid-test unregister_post_type() calls. If any assertion fails prior to those lines, foo-non-public will leak into subsequent test runs.

Could we unregister foo-non-public in tear_down() as well and remove the mid-test unregister calls?

	public function tear_down() {
		unregister_post_type( 'content' );
		unregister_post_type( 'foo-non-public' );

		parent::tear_down();
	}

AI Review: Gemini 3.8 Flash

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the change that moves custom post type cleanup into teardown.

No open issues 🎉

What changed in this PR

This PR improves test isolation in Tests_AdminBar by ensuring the content custom post type is cleaned up during teardown, even if a test assertion fails.

Changes:

  • Adds tear_down() cleanup using the public unregister_post_type() function before calling the parent teardown.
  • Removes the internal _unregister_post_type() call from test_content_post_type().
File Description
tests/​phpunit/​tests/​adminbar.php Moves custom post type cleanup into teardown using the public API.

Review effort: Balanced

@devmuhib009

Copy link
Copy Markdown
Member Author

Updated! Added unregister_post_type( 'foo-non-public' ); to tear_down() and removed the mid-test unregistration calls across all three test methods. Thanks @huzaifaalmesbah!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants