Skip to content

Tests: Add unit tests for the failures of WP_REST_Plugins_Controller - #15741

Closed
hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:66562-rest-plugins-controller-error-tests
Closed

hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:66562-rest-plugins-controller-error-tests

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

Summary

Adds tests for the paths of WP_REST_Plugins_Controller where installing or deleting a plugin fails, in a new file. rest-plugins-controller.php already tests the routes, the permissions, the activation and the successful requests, so these tests add what was left. The part of create_item() that installs language packs is not tested here, because ticket #65240 changes it.

  • create_item() returns the errors of an installation that failed (the download fails) with the status 500, and nothing is installed.
  • create_item() returns an error of the Plugin Installation API that is not about a plugin that is not found with the status 500.
  • create_item() and delete_item() fail with fs_unavailable when the filesystem needs credentials that are not stored, and a plugin is not deleted then.
  • is_filesystem_available() is true when the credentials are stored.
  • validate_plugin_param() rejects a value that is not a string, an empty string and a path that goes up, and accepts the path of a plugin in a folder, a single file plugin and one with dashes and numbers.
  • sanitize_plugin_param() adds the .php extension.

Testing

vendor/bin/phpunit --filter 'WP_REST_Plugins_Controller_Failures_Test::'
vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'WP_REST_Plugins_Controller_Failures_Test::'
vendor/bin/phpcs tests/phpunit/tests/rest-api/rest-plugins-controller-failures.php

Mutation check: 12 changes to create_item(), delete_item(), is_filesystem_available(), validate_plugin_param() and sanitize_plugin_param() were each caught by a test.

validate_plugin_param() matches its pattern without anchors, so it also accepts a value such as plugin/plugin.php. The route has its own anchored pattern, so this is only visible when the method is called directly. The tests do not assert this.

The upgrader leaves an output buffer open when an installation fails, and the test closes it.

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

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5.5
Used for: Written with AI and manually reviewed by me.


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.

@hmbashar
hmbashar marked this pull request as ready for review November 6, 2026 16:24
@github-actions

github-actions Bot commented Nov 6, 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 hmbashar.

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.

@hmbashar hmbashar closed this Nov 12, 2026
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