Opened 5 years ago
Closed 5 years ago
#48844 closed enhancement (fixed)
Unit test for wp()
Reported by: | pbearne | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 5.4 | Priority: | normal |
Severity: | normal | Version: | 5.4 |
Component: | Bootstrap/Load | Keywords: | has-unit-tests dev-feedback |
Focuses: | Cc: |
Description
Just a simple test for the wp() function in functions.php
It not posable to test fully as the WP object has already been created by the test framework
Attachments (2)
Change History (7)
#1
@
5 years ago
- Component changed from General to Bootstrap/Load
- Milestone changed from Awaiting Review to 5.4
- Owner set to SergeyBiryukov
- Status changed from new to reviewing
#3
@
5 years ago
I will have to dig as the tests should not be changing $wp_query and $wp_the_query we may have found a bug in the tests :-)
#4
@
5 years ago
The last assertion fails because:
wp()
only sets$wp_the_query
if it's not already set.- It is actually already set earlier in wp-settings.php.
- It is then reset in WP_UnitTestCase_Base::go_to(), called by various canonical tests.
- After that, the variable no longer points to the same object, so
assertSame()
fails.
Some history on that code:
- [4460] introduced setting
$wp_the_query
inwp-settings.php
. - [6233] introduced setting
$wp_the_query
inwp()
. However, the commit message on that changeset was wrong, see [6232] / #5121 for the correct commit message.
Note that WP::main()
calls WP::query_posts()
, which produces a fatal error if $wp_the_query
is not set by then (Call to a member function query() on null
), and did so in WP 2.3.3 too.
Given that, I'm not sure if [6232] actually fixed anything, setting $wp_the_query
in wp()
seems redundant. As far as I can tell, that line is never reached, but confirming that would require some more testing.
For now, let's get the unit test in, except for the last assertion, which apparently cannot be reliably tested.
Full test suite failure