Skip to content

Tests: Add unit tests for wp_doing_sitemap() and the DOING_SITEMAP constant#3

Merged
masteradhoc merged 1 commit into
masteradhoc:56954-doing_sitemapfrom
nimesh-xecurify:56954-unit-tests
Jun 21, 2026
Merged

Tests: Add unit tests for wp_doing_sitemap() and the DOING_SITEMAP constant#3
masteradhoc merged 1 commit into
masteradhoc:56954-doing_sitemapfrom
nimesh-xecurify:56954-unit-tests

Conversation

@nimesh-xecurify

Copy link
Copy Markdown

Adds the unit test coverage requested in review on WordPress#12150 for the DOING_SITEMAP constant and wp_doing_sitemap() function.

wp_doing_sitemap() (tests/phpunit/tests/load/wpDoingSitemap.php)

  • Returns false on a regular request.
  • The wp_doing_sitemap filter can force a true result.
  • Returns true when the DOING_SITEMAP constant is defined.
  • The wp_doing_sitemap filter can override the constant (returns false even when DOING_SITEMAP is true).

WP_Sitemaps::render_sitemaps() (tests/phpunit/tests/sitemaps/sitemaps.php)

  • Defines DOING_SITEMAP (and wp_doing_sitemap() returns true) while rendering a sitemap.
  • Does not define DOING_SITEMAP when sitemaps are disabled, confirming the constant is only set after the preliminary checks pass.

Tests that depend on defining the constant run in a separate process so the constant does not leak across tests.

All new tests pass, and the full Tests_Sitemaps_Sitemaps suite (21 tests) remains green. phpcs passes against the WordPress-Core ruleset.

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

…nstant.

Adds coverage for the wp_doing_sitemap() function introduced for #56954,
including the default false result, the DOING_SITEMAP constant path, and
the wp_doing_sitemap filter overriding both the default and the constant.

Also adds integration tests asserting that WP_Sitemaps::render_sitemaps()
defines the DOING_SITEMAP constant while rendering a sitemap, and that the
constant is not defined when sitemaps are disabled.

See #56954.
@masteradhoc masteradhoc merged commit d24a1df into masteradhoc:56954-doing_sitemap Jun 21, 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.

2 participants