Skip to content

Tests: Clean up the wp_delete_post() unit tests - #13036

Open
Soean wants to merge 1 commit into
WordPress:trunkfrom
Soean:tests/wp-delete-post-cleanup
Open

Tests: Clean up the wp_delete_post() unit tests#13036
Soean wants to merge 1 commit into
WordPress:trunkfrom
Soean:tests/wp-delete-post-cleanup

Conversation

@Soean

@Soean Soean commented Aug 13, 2026

Copy link
Copy Markdown
Member

Description

Four independent clean-ups in the test file. Follow-up to [60906].

  • Remove the unused $user_ids fixture. The property and its wpSetUpBeforeClass() method were copied over from the wp_insert_post() tests. Nothing in this class references self::$user_ids, so the only effect was creating three users for every test in the class.
  • Rename test_wp_delete_post_returns_false_for_invalid_post() to test_wp_delete_post_returns_null_for_already_deleted_post(). The test asserts assertNull(), and that is the correct expectation: for an ID with no matching row, wp_delete_post() returns the null coming out of $wpdb->get_row(), whereas false is only returned by the $post_id <= 0 guard. The old name described the opposite of what the test covers.
  • Reuse the $actions array in the assertion loop of test_wp_delete_post_actions(). The same six action names were spelled out a second time inline, so the registration loop and the assertion loop could drift apart.
  • Fix the @ticket @63975 annotation. The stray @ made the tag invalid, so the test was not associated with the ticket.
    No assertion was added, removed or changed, and no test behaviour changes.

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


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.

Removes the unused `$user_ids` property and its `wpSetUpBeforeClass()` method. Both were copied over from the `wp_insert_post()` tests and created three users for every test in the class without a single test referencing them.
Renames `test_wp_delete_post_returns_false_for_invalid_post()` to `test_wp_delete_post_returns_null_for_already_deleted_post()`. The test asserts `assertNull()`, which is the correct expectation: for an ID with no matching row, `wp_delete_post()` returns the `null` coming out of `$wpdb->get_row()`, whereas `false` is only returned by the `$post_id <= 0` guard. The previous name described the opposite of what is being covered.
Reuses the existing `$actions` array in the assertion loop of `test_wp_delete_post_actions()` instead of repeating the same six action names inline, so the registration loop and the assertion loop cannot drift apart.
@github-actions

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. You can also manually ask me to refresh this list by adding the props-bot label.

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

Props soean.

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

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

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.

1 participant