Repository navigation
Tests: Replace the manual post type unset in link tests with unregister_post_type() - #14950
rejaulalomkhan wants to merge 3 commits into
Conversation
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.
|
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: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
There was a problem hiding this comment.
🟡 Changes recommended
The attachment test unsets not_a_post_type before teardown, causing cleanup to fail and leave post-type supports and rewrite registration behind.
1 open issue
What changed in this PR
This PR adds teardown cleanup to WordPress’s link tests to improve isolation between tests that register custom post types.
Changes:
- Adds
Tests_Link::tear_down()to unregisterwptests_ptandnot_a_post_type. - Calls the parent teardown after the custom cleanup.
| File | Description |
|---|---|
tests/phpunit/tests/link.php |
Adds custom post-type cleanup to the link test teardown. |
Review effort: Balanced
lancewillett
left a comment
There was a problem hiding this comment.
One cleanup gap remains in the attachment test, as Copilot noted. I reproduced it in single-site and multisite: the existing manual unset removes the post-type object before teardown, leaving supports, the permastruct, and the rewrite tag behind. Replacing that unset loop with unregister_post_type() preserved the original assertions and removed the leaked state. Please make that change before landing.
AI review · gpt-6
|
|
||
| public function tear_down() { | ||
| unregister_post_type( 'wptests_pt' ); | ||
| unregister_post_type( 'not_a_post_type' ); |
There was a problem hiding this comment.
Please replace the manual $wp_post_types unset loop in test_attachment_attached_to_non_existent_post_type_has_a_pretty_permalink() with unregister_post_type( 'not_a_post_type' ) at the same point. The object is already gone when this teardown call runs, so it returns invalid_post_type and cannot remove the remaining supports and rewrite state. The replacement keeps the nonexistent-post-type scenario intact.
AI review · gpt-6
…chment 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.
|
@lancewillett Replaced the unset loop with |
lancewillett
left a comment
There was a problem hiding this comment.
Please drop the broad tear_down() list and keep this focused on replacing the manual post-type unset with unregister_post_type(), including removal of the unused global. The shared per-test reset already unregisters surviving custom types. Raw registry removal is a distinct cleanup bypass, so retain that narrow correction for review. Residue probes do not establish a separate failing-test regression.
AI review · gpt-6
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().
|
@lancewillett Removed |
lancewillett
left a comment
There was a problem hiding this comment.
The narrowed change is supported. Removing the post type between the pretty and plain permalink assertions is part of the behavior being tested; the public unregistration API replaces the manual loop clearly. No broad teardown is needed.
The existing link class passes before and after in randomized single-site and multisite runs (7 tests, 28 assertions each). PHPCS, CI and the fresh Copilot review are clear. This is a simplification of the existing test, not a claim of a separately demonstrated downstream isolation failure.
AI review · gpt-6
Use `unregister_post_type()` instead of manually removing the registry entry when testing an attachment whose parent post type no longer exists. Remove the unused global declaration. Developed in: #14950 Props rejaulalomkhan, mukesh27. See #65893. git-svn-id: https://develop.svn.wordpress.org/trunk@65186 602fd350-edb4-49c9-b593-d223f7449a82
Use `unregister_post_type()` instead of manually removing the registry entry when testing an attachment whose parent post type no longer exists. Remove the unused global declaration. Developed in: WordPress/wordpress-develop#14950 Props rejaulalomkhan, mukesh27. See #65893. Built from https://develop.svn.wordpress.org/trunk@65186 git-svn-id: http://core.svn.wordpress.org/trunk@64335 1a063a9b-81f0-0310-95a4-ce76da25c4cd
|
PR #14950 landed in https://core.trac.wordpress.org/changeset/65186 |

Description
test_attachment_attached_to_non_existent_post_type_has_a_pretty_permalink()removesnot_a_post_typeby unsetting it from$wp_post_types, which bypasses the cleanup inunregister_post_type().unregister_post_type( 'not_a_post_type' ).global $wp_post_types.The test still covers an attachment whose parent's post type no longer exists.
Testing
All pass (7 tests, 28 assertions); PHPCS: no errors.
Trac ticket: https://core.trac.wordpress.org/ticket/65893
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.
Use of AI Tools
AI assistance: Yes
Tool(s): Google Antigravity (original change), Claude Code (review follow-up)
Model(s): claude-3-7-sonnet / gemini-2.5-pro (original change, as disclosed), Claude Opus 5.5
Used for: Finding the manual unset and replacing it, then narrowing the change after review. I reviewed every line and take responsibility for the change.