Repository navigation
Tests: Add unit test coverage for WP_Automatic_Updater::should_update() - #14453
huzaifaalmesbah wants to merge 2 commits into
Conversation
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
rejaulalomkhan
left a comment
There was a problem hiding this comment.
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.phppasses 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
There was a problem hiding this comment.
🟡 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
lancewillett
left a comment
There was a problem hiding this comment.
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
…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.
|
Thanks for the review, @lancewillett.
Done in 1f32b6b. The class passes on single site, multisite and random order, and PHPCS is clean. |
lancewillett
left a comment
There was a problem hiding this comment.
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
|
PR #14453 landed in https://core.trac.wordpress.org/changeset/64611 |
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
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


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.phpcovers 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:
autoupdateflag, or from the site admin's auto-update setting only while auto-updates are enabled for the type;autoupdateflag;disable_autoupdateflag overriding the choice, while the filter can still allow the update;auto_update_{$type}filter receiving the decision and the offer, with truthy and falsy return values;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
npm run test:php -- --filter 'Tests_Admin_WpAutomaticUpdaterShouldUpdate'npm run test:php -- --filter 'Tests_Admin_WpAutomaticUpdaterShouldUpdate' -c tests/phpunit/multisite.xmlnpm run test:php -- --filter 'Tests_Admin_WpAutomaticUpdaterShouldUpdate' --order-by=randomnpm run test:php -- --group upgradenode ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpcs tests/phpunit/tests/admin/wpAutomaticUpdaterShouldUpdate.phpTrac 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.