Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#34346 closed defect (bug) (fixed)

WP_UnitTestCase::go_to() wipes out custom query vars

Reported by: johnbillion's profile johnbillion Owned by:
Milestone: 4.4 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords:
Focuses: Cc:


The go_to() method in the test suite re-instantiates the $wp global with a new WP object. This means that any custom query vars that have been added via $wp->add_query_var() get wiped out, making them untestable.

An affected function is add_rewrite_endpoint() which internally calls $wp->add_query_var().

This test demonstrates the problem:

$test_post_id = self::factory()->post->create();

add_rewrite_endpoint( 'foo', EP_PERMALINK );

$this->go_to( get_permalink( $test_post_id ) . 'foo/bar/' );

$this->assertTrue( is_single( $test_post_id ) ); // passes
$this->assertEquals( 'bar', get_query_var( 'foo' ) ); // fails

Change History (3)

#1 @johnbillion
9 years ago

In 35258:

Preserve the public and private query var properties on the global WP instance when using WP_UnitTestCase::go_to(). These properties apply to the application state, not the current request.

See #34346

#2 @johnbillion
9 years ago

  • Keywords needs-patch removed
  • Milestone changed from Awaiting Review to 4.4

#3 @wonderboymusic
9 years ago

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.