[wp-trac] [WordPress Trac] #37207: Multiple unit tests for add_rewrite_endpoint lose custom endpoints

WordPress Trac noreply at wordpress.org
Tue Jun 28 02:47:29 UTC 2016


#37207: Multiple unit tests for add_rewrite_endpoint lose custom endpoints
------------------------------+-----------------------------
 Reporter:  ericdaams         |      Owner:
     Type:  defect (bug)      |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Build/Test Tools  |    Version:  4.5.3
 Severity:  normal            |   Keywords:
  Focuses:                    |
------------------------------+-----------------------------
 When registering multiple endpoints through `add_rewrite_endpoint()`,
 tests for the existence of each endpoint in
 `$GLOBALS['wp']->public_query_vars` fails.

 I have attached a simple plugin that illustrates the problem. Steps to
 reproduce:

 1. Download the plugin.
 2. Run `phpunit` inside of it.
 3. Test #1 succeeds while test #2 fails.

 The relevant excerpts from the plugin are included below.

 Endpoint registration:
 {{{
 add_action( 'init', function() {
         add_rewrite_endpoint( 'custom-endpoint', EP_ROOT );
         add_rewrite_endpoint( 'custom-endpoint-2', EP_ROOT );
 });
 }}}

 Tests:
 {{{
 class TestRewriteEndpoint extends WP_UnitTestCase {
         public function setUp() {
                 parent::setUp();
                 $this->set_permalink_structure(
 '/%year%/%monthnum%/%day%/%postname%/' );
                 $this->qvs = $GLOBALS['wp']->public_query_vars;
                 // print_r( $this->qvs );
         }
         public function tearDown() {
                 $GLOBALS['wp']->public_query_vars = $this->qvs;
                 parent::tearDown();
         }
         public function test_is_custom_endpoint_added() {
                 $this->assertContains( 'custom-endpoint',
 $GLOBALS['wp']->public_query_vars );
         }
         public function test_is_custom_endpoint_2_added() {
                 $this->assertContains( 'custom-endpoint-2',
 $GLOBALS['wp']->public_query_vars );
         }
 }
 }}}

 This may possibly be related to #34346, though in this case I am not using
 `go_to()`.

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


More information about the wp-trac mailing list