WordPress.org

Make WordPress Core

Opened 6 months ago

Closed 6 months ago

#25818 closed defect (bug) (fixed)

`WP_UnitTestCase::go_to()` drops query vars

Reported by: wonderboymusic Owned by: wonderboymusic
Milestone: 3.8 Priority: normal
Severity: normal Version: 3.8
Component: Unit Tests Keywords:
Focuses: Cc:

Description

If you register a custom taxonomy in a unit test case, create a term in it, add it to a post, delete rewrite rules, and then call WP_UnitTestCase::go_to() with a URL for the connected term, the query var is not registered, so the query just goes to home.

It is not very clear what is the proper way to do this. I discovered the issue writing unit tests here: http://core.trac.wordpress.org/attachment/ticket/20767/20767.3.diff

There should be assertions for assertNotEmpty( get_query_var( 'sometax' ) ), they currently fail because the query var isn't registered.

When a custom taxonomy is registered, and then the query is filtered to include a 2nd term in the taxonomy using pre_get_posts, $wp_query->query_vars should include the query var and tax_query, it currently only includes tax_query.

Looking into this.

Change History (3)

comment:1 wonderboymusic6 months ago

  • Owner set to wonderboymusic
  • Status changed from new to assigned

comment:2 jdgrimes6 months ago

  • Cc jdg@… added

comment:3 wonderboymusic6 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 26006:

WP_UnitTestCase::go_to() tried its best to clean up global space, but ultimately fell short. Because it was blowing away WP every time it was called, it was dropping all the query vars that were registered for custom taxonomies and custom post types (ouch).

Introduces _cleanup_query_vars(). This is a prerequisite for the unit tests on #20767. All unit tests pass with this change.

See #20767.
Fixes #25818.

Note: See TracTickets for help on using tickets.