Skip to content

Tests: Add unit tests for wp_is_maintenance_mode() - #14474

Open
shail-mehta wants to merge 1 commit into
WordPress:trunkfrom
shail-mehta:65819-add-wp-is-maintenance-mode-tests
Open

shail-mehta wants to merge 1 commit into
WordPress:trunkfrom
shail-mehta:65819-add-wp-is-maintenance-mode-tests

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

What

Trac ticket: #65819

Adds unit tests for wp_is_maintenance_mode() in tests/phpunit/tests/load/wpIsMaintenanceMode.php.

Covers a missing/expired .maintenance file, a fresh file, installing mode, scrape credentials, and the enable_maintenance_mode filter.

Test-only change.

Why

This helper has had no dedicated PHPUnit coverage. Fits the #65819 missing-coverage track, and no open PR covers it.

How

  • Write and delete a temporary .maintenance file in tear_down()
  • Assert fresh timestamps enable maintenance mode, and missing/expired files do not
  • Cover installing mode, scrape key/nonce bypass, and the enable_maintenance_mode filter

Testing instructions

npm run test:php -- --filter Tests_Load_WpIsMaintenanceMode

Use of AI Tools

  • Cursor

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.

🟢 Approval recommended

The tests match the helper’s behavior, include cleanup, and have no identified blocking issues.

No open issues 🎉

What changed in this PR

Adds dedicated PHPUnit coverage for wp_is_maintenance_mode() as part of ticket #65819, without changing production code.

Changes:

  • Tests missing, fresh, and expired maintenance files.
  • Covers installation mode, scrape credentials, and filter behavior.
  • Adds fixture cleanup and state restoration.
File Description
tests/​phpunit/​tests/​load/​wpIsMaintenanceMode.php Adds maintenance-mode tests and fixture lifecycle helpers.

Review effort: Balanced

@shail-mehta
shail-mehta marked this pull request as ready for review October 19, 2026 08:42
@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 shailu25.

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

* @param int $upgrading Unix timestamp.
*/
private function write_maintenance_file( $upgrading ) {
file_put_contents( ABSPATH . '.maintenance', '<?php $upgrading = ' . (int) $upgrading . ";\n" );

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.

Optional note: this writes a real .maintenance file into ABSPATH, because wp_is_maintenance_mode() hard-codes that path. tear_down() removes it. If a run stops partway, though, the file stays, and the next bootstrap would stop in maintenance mode for up to 10 minutes. A short comment here would help the next person who sees that.

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.

3 participants