[wp-trac] [WordPress Trac] #37207: Multiple unit tests for add_rewrite_endpoint lose custom endpoints
WordPress Trac
noreply at wordpress.org
Wed Jul 13 17:50:30 UTC 2016
#37207: Multiple unit tests for add_rewrite_endpoint lose custom endpoints
------------------------------+------------------------------
Reporter: ericdaams | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Build/Test Tools | Version: 4.5.3
Severity: normal | Resolution:
Keywords: | Focuses:
------------------------------+------------------------------
Comment (by mboynes):
I ran across this issue today.
In short, it's common practice to call `add_rewrite_tag()` or
`add_rewrite_endpoint()` on `init`. These add public query vars to
`$GLOBALS['wp']` directly (not via the `query_vars` filter). `init` fires
once on load during a run of phpunit, not once per test. In
`WP_UnitTestCase::tearDown()`, `$GLOBALS['wp']` is completely reset, which
includes wiping the public query vars. Because `init` is never run again,
those query vars are never added back.
One potential solution would be to store query vars at the end of the
bootstrap, then reset them in `WP_UnitTestCase::tearDown()` after
`$GLOBALS['wp']` is reset. It would be important to store them on
bootstrap and not `WP_UnitTestCase::setUp()` so that query vars added
during one test don't persist to the next test.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/37207#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list