Skip to content

Tests: Add unit test coverage for WP_Automatic_Updater::should_update() - #14453

Closed
huzaifaalmesbah wants to merge 2 commits into
WordPress:trunkfrom
huzaifaalmesbah:tests/automatic-updater-should-update
Closed

huzaifaalmesbah wants to merge 2 commits into
WordPress:trunkfrom
huzaifaalmesbah:tests/automatic-updater-should-update

Conversation

@huzaifaalmesbah

Copy link
Copy Markdown
Member

Description

Adds tests for WP_Automatic_Updater::should_update(), which decides whether core, a plugin, a theme or a translation is updated in the background. The method had no tests; admin/wpAutomaticUpdater.php covers other methods of the class.

The tests control the filesystem credentials, version-control and disabled checks through their filters, and use a partial mock to check when a core update notification email would be sent. They cover:

  • nothing being updated while background updates are disabled, without filesystem credentials, or in a version-controlled checkout, and the core notification email in the last two cases;
  • relaxed file ownership being allowed only for core updates that add no new files;
  • plugins and themes being updated from the offer's autoupdate flag, or from the site admin's auto-update setting only while auto-updates are enabled for the type;
  • translations being updated only with the autoupdate flag;
  • the disable_autoupdate flag overriding the choice, while the filter can still allow the update;
  • the auto_update_{$type} filter receiving the decision and the offer, with truthy and falsy return values;
  • the core notification email when the filter declines a core update;
  • the PHP and MySQL requirements of core updates, and the PHP requirement of plugin and theme updates, which does not apply to translations.

Removing or changing each branch of the method makes at least one test fail.

This is a test-only change; no production code is modified.

Testing Instructions

  1. Run the tests on single site:
    npm run test:php -- --filter 'Tests_Admin_WpAutomaticUpdaterShouldUpdate'
  2. Run them on multisite:
    npm run test:php -- --filter 'Tests_Admin_WpAutomaticUpdaterShouldUpdate' -c tests/phpunit/multisite.xml
  3. Run them in random order:
    npm run test:php -- --filter 'Tests_Admin_WpAutomaticUpdaterShouldUpdate' --order-by=random
  4. Run the upgrade group:
    npm run test:php -- --group upgrade
  5. Run PHPCS on the test file:
    node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpcs tests/phpunit/tests/admin/wpAutomaticUpdaterShouldUpdate.php

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

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Brainstorming edge-case scenarios and drafting test boilerplate; test architecture, assertions, and local PHPUnit verification were written and validated by me.

@github-actions

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

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

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

Thanks for working on this, @huzaifaalmesbah! Comprehensive test coverage for WP_Automatic_Updater::should_update() is very valuable — covering the core notification fallbacks, relaxed file ownership rules, and requirement guards closes a long-standing gap in automatic update test coverage.

Everything looks clean and well-structured:

  • Verified all 39 tests and 88 assertions locally across single-site, multisite, and random order (--order-by=random).
  • Verified --group upgrade (228 tests, 562 assertions) passes without regressions.
  • PHPCS check on tests/phpunit/tests/admin/wpAutomaticUpdaterShouldUpdate.php passes with 0 errors and 0 warnings.
  • All 7 data providers are declared public static.
  • Setup properly isolates filesystem credential filters and mocks send_core_update_notification_email.

Looks ready to merge!

AI Review: Antigravity

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

Older PHPUnit compatibility and missing coverage of core-policy delegation need addressing.

2 open issues
What changed in this PR

Adds unit tests for WP_Automatic_Updater::should_update() without changing production code.

Changes:

  • Covers update eligibility, filesystem checks, filters, and version requirements.
  • Uses partial mocks to verify core notification behavior.
File Description
tests/​phpunit/​tests/​admin/​wpAutomaticUpdaterShouldUpdate.php Adds background-update decision tests for core, plugins, themes, and translations.

Review effort: Balanced

Comment thread tests/phpunit/tests/admin/wpAutomaticUpdaterShouldUpdate.php Outdated
Comment thread tests/phpunit/tests/admin/wpAutomaticUpdaterShouldUpdate.php

@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 small compatibility fix before landing: use setMethods() for the partial mock, matching the existing updater tests. PHPUnit 7.5 does not provide onlyMethods(), and the Core bootstrap still accepts older PHPUnit versions. The local randomized runs passed on PHPUnit 9.6.

Copilot’s second suggestion is optional: an allowed/denied core-policy pair without overriding auto_update_core would protect the delegation to Core_Upgrader::should_update_to_version(). The current eligibility and compatibility checks are otherwise useful.

AI review · gpt-6

Comment thread tests/phpunit/tests/admin/wpAutomaticUpdaterShouldUpdate.php Outdated
…tic_Updater::should_update() tests.

Uses setMethods() for the partial mock, since onlyMethods() is not available in PHPUnit 7.5,
and adds an allowed and a denied core case that rely on the core update policy filters
instead of auto_update_core.
@huzaifaalmesbah

Copy link
Copy Markdown
Member Author

Thanks for the review, @lancewillett.

  • Switched the partial mock to setMethods(), with the same note as wpAutomaticUpdater.php.
  • Added test_core_update_follows_core_update_policy(): an allowed and a denied core case that use allow_dev_auto_core_updates and allow_major_auto_core_updates instead of auto_update_core. Replacing Core_Upgrader::should_update_to_version() with true or false now fails a test.

Done in 1f32b6b. The class passes on single site, multisite and random order, and PHPCS is clean.

@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 mock compatibility fix is correct, and the new allowed/denied core-policy cases cover the suggested gap. Randomized single-site and multisite runs each passed 41 tests and 92 assertions. The upgrade group completed with 230 tests, 566 assertions, and one skipped test outside this class; PHPCS passed. No remaining blockers from the unit-tests audit.

AI review · gpt-6

@lancewillett

Copy link
Copy Markdown
Member

wporg-sync pushed a commit that referenced this pull request Oct 20, 2026
Add coverage for `WP_Automatic_Updater::should_update()`, including filesystem checks, core update policy, plugin and theme settings, translation updates, filters, version requirements, and core notification behavior.

Developed in: #14453

Props huzaifaalmesbah, rejaulalomkhan.
See #65819.


git-svn-id: https://develop.svn.wordpress.org/trunk@64611 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 20, 2026
Add coverage for `WP_Automatic_Updater::should_update()`, including filesystem checks, core update policy, plugin and theme settings, translation updates, filters, version requirements, and core notification behavior.

Developed in: WordPress/wordpress-develop#14453

Props huzaifaalmesbah, rejaulalomkhan.
See #65819.

Built from https://develop.svn.wordpress.org/trunk@64611


git-svn-id: http://core.svn.wordpress.org/trunk@63761 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

4 participants