Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 4 years ago

#25818 closed defect (bug) (fixed)

`WP_UnitTestCase::go_to()` drops query vars

Reported by: wonderboymusic's profile wonderboymusic Owned by: wonderboymusic's profile 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 (4)

#1 @wonderboymusic
11 years ago

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

#2 @jdgrimes
11 years ago

  • Cc jdg@… added

#3 @wonderboymusic
11 years 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.

This ticket was mentioned in Slack in #core by noisysocks. View the logs.


4 years ago

Note: See TracTickets for help on using tickets.