Skip to content

Tests: Add unit tests for Plugin_Upgrader::install(), upgrade() and the strings - #15728

Closed
hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:66559-plugin-upgrader-install-upgrade-tests
Closed

hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:66559-plugin-upgrader-install-upgrade-tests

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

Summary

Adds tests for the strings, install() and upgrade() of Plugin_Upgrader. The callbacks (deactivate_plugin_before_upgrade(), active_before(), active_after(), delete_old_plugin()), check_package() and plugin_info() already have tests, so these tests add the rest of the class, except bulk_upgrade().

  • upgrade_strings() and install_strings(), and the strings that the update-plugin and downgrade-plugin modes of the skin change (another mode changes none).
  • install() runs with the package and the plugins directory, does not overwrite files by default, clears the destination to overwrite the package, and adds its hooks (the package check and the cache cleaning) only while it runs, without the cache cleaning when it is not asked for.
  • install() installs the plugin of a package (the zip of the test data), cleans the update information, and announces with upgrader_overwrote_package that it overwrote the package, but not without overwriting.
  • upgrade() tells the skin that a plugin without an update is up to date, and does the same when the update is for another plugin.
  • upgrade() runs with the package of the update, removes the old plugin, passes the plugin and its temporary backup (temp_backup) to the hooks, adds the four hooks (deactivation, maintenance mode, deletion of the old plugin, reactivation) only while it runs, and does not clean the cache when it is not asked for.

Testing

vendor/bin/phpunit --filter 'Tests_Admin_PluginUpgraderInstallUpgrade::'
vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'Tests_Admin_PluginUpgraderInstallUpgrade::'
vendor/bin/phpcs tests/phpunit/tests/admin/pluginUpgraderInstallUpgrade.php

Mutation check: 36 changes to the strings, install() and upgrade() (the defaults, the options, the hooks and their removal, the cache, the announcement and the skin calls) were each caught by a test. One is equivalent: removing the explicit wp_clean_plugins_cache() call after a successful installation changes nothing, because the upgrader_process_complete hook that install() adds has already cleaned the cache.

The tests stop an update with the upgrader_pre_download filter, and the installation tests copy the zip of the test data first, because the upgrader deletes the package it unpacks. The plugin that is installed is removed after each test.

When the download fails, install() and upgrade() return null and not the error, which only the skin gets. The tests do not assert that return value.

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

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 15:32
@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