[wp-trac] [WordPress Trac] #51154: sitemaps should be initialized before each test is run
WordPress Trac
noreply at wordpress.org
Thu Aug 27 03:21:21 UTC 2020
#51154: sitemaps should be initialized before each test is run
------------------------------+-----------------------------
Reporter: pbiron | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Build/Test Tools | Version:
Severity: normal | Keywords:
Focuses: |
------------------------------+-----------------------------
While working on #50910, both @peterwilsoncc and I came across some odd
cases where unit tests were passing/failing when run in isolation but had
the opposite result when run as part of a larger group of tests. See
[#50910:comment:15] and [#50910:comment:21].
When handling a normal WP request, sitemaps are initialized on `init`. As
part of that initialization, 3 rewrite tags are added: `sitemap`,
`sitemap-subtype` `and sitemap-stylesheet`. That in turn, adds those to
`$wp->public_query_vars`.
However, `wp_sitemaps_get_server()` (which is hooked to `init`) checks
whether the `$wp_sitemaps` global is set and if is then sitemaps aren't
"re-initialized". During a normal WP request that's desired behavior, but
when multiple unit tests are run it can cause incorrect test results.
For example, `testPublicQueryVarsAreAsExpected()` (in
`tests/phpunit/tests/query/vars.php`) should have been updated as part of
the core merge to include the sitemaps-related `public_query_vars` but it
was missed because the test was passing on Travis since sitemaps weren't
being reinitialized before each test.
That test can be run by itself with `phpunit --group 35115` (it was added
as part of #35115, in [36045]) and it will fail...as it should, since it
was never updated with the sitemaps-related query vars. But when run as
with all the other `phpunit --group query` tests, it incorrectly succeeds.
So, here's what I propose: I'll open a PR that sets
`$GLOBALS['wp_sitemaps'] = null;` in `WP_UnitTestCase_Base::tearDown()`
(where other globals are reset). When Travis runs, at the very least
`testPublicQueryVarsAreAsExpected()` should fail. I'll then update the PR
by adding the sitemap-related query vars to the `$expected` value in that
test.
Well see how that goes and if necessary I'll correct any other tests that
have been incorrectly passing on Travis.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51154>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list