[wp-trac] [WordPress Trac] #34346: WP_UnitTestCase::go_to() wipes out custom query vars

WordPress Trac noreply at wordpress.org
Sun Oct 18 04:02:13 UTC 2015


#34346: WP_UnitTestCase::go_to() wipes out custom query vars
------------------------------+-----------------------------
 Reporter:  johnbillion       |      Owner:
     Type:  defect (bug)      |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Build/Test Tools  |    Version:
 Severity:  normal            |   Keywords:  needs-patch
  Focuses:                    |
------------------------------+-----------------------------
 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 );
 flush_rewrite_rules();

 $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
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/34346>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list