Skip to content

Tests: Replace the manual post type unset in link tests with unregister_post_type() - #14950

Closed
rejaulalomkhan wants to merge 3 commits into
WordPress:trunkfrom
rejaulalomkhan:tests/65893-isolate-link-general
Closed

rejaulalomkhan wants to merge 3 commits into
WordPress:trunkfrom
rejaulalomkhan:tests/65893-isolate-link-general

Conversation

@rejaulalomkhan

@rejaulalomkhan rejaulalomkhan commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Description

test_attachment_attached_to_non_existent_post_type_has_a_pretty_permalink() removes not_a_post_type by unsetting it from $wp_post_types, which bypasses the cleanup in unregister_post_type().

  • Replaces the manual unset with unregister_post_type( 'not_a_post_type' ).
  • Removes the now-unused global $wp_post_types.

The test still covers an attachment whose parent's post type no longer exists.

Testing

vendor/bin/phpunit --filter 'Tests_Link::'
vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'Tests_Link::'
vendor/bin/phpcs tests/phpunit/tests/link.php

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.

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.
@github-actions

github-actions Bot commented Oct 27, 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 rejaulalomkhan, lancewillett, mukesh27.

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.

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.

🟡 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 unregister wptests_pt and not_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

Comment thread tests/phpunit/tests/link.php Resolved

@lancewillett lancewillett 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.

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

Comment thread tests/phpunit/tests/link.php Outdated

public function tear_down() {
unregister_post_type( 'wptests_pt' );
unregister_post_type( 'not_a_post_type' );

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 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.
@rejaulalomkhan

Copy link
Copy Markdown
Member Author

@lancewillett Replaced the unset loop with unregister_post_type( 'not_a_post_type' ) and dropped the now-unused global $wp_post_types (bdc1d1b). Checked after teardown: the supports, permastruct and rewrite tag for not_a_post_type were left behind before, and are removed now. Tests_Link passes on single site, multisite and random order.

@lancewillett lancewillett 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.

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().
@rejaulalomkhan rejaulalomkhan changed the title Tests: Unregister custom post types in link tests teardown Tests: Replace the manual post type unset in link tests with unregister_post_type() Nov 2, 2026
@rejaulalomkhan

Copy link
Copy Markdown
Member Author

@lancewillett Removed tear_down() in c0b038d. The PR now only replaces the manual $wp_post_types unset with unregister_post_type() and removes the unused global. Tests_Link passes on single site and multisite.

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 were identified for the attachment permalink test cleanup change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@lancewillett lancewillett 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.

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

wporg-sync pushed a commit that referenced this pull request Nov 2, 2026
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
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Nov 2, 2026
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
@lancewillett

Copy link
Copy Markdown
Member

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.

4 participants