WordPress.org

Make WordPress Core

Changeset 35259


Ignore:
Timestamp:
10/18/2015 06:23:48 AM (4 years ago)
Author:
johnbillion
Message:

Some rewrite endpoint tests in preparation for new endpoint masks. More to come.

See #33728, #24853

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rewrite/addRewriteEndpoint.php

    r35256 r35259  
    66class Tests_Rewrite_AddRewriteEndpoint extends WP_UnitTestCase {
    77    private $qvs;
     8    protected static $test_page_id;
     9    protected static $test_post_id;
     10
     11    public static function wpSetUpBeforeClass( $factory ) {
     12        self::$test_page_id = $factory->post->create( array(
     13            'post_type' => 'page',
     14        ) );
     15        self::$test_post_id = $factory->post->create();
     16    }
     17
     18    public static function wpTearDownAfterClass() {
     19        wp_delete_post( self::$test_page_id, true );
     20    }
    821
    922    public function setUp() {
    1023        parent::setUp();
     24
     25        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
     26
    1127        $this->qvs = $GLOBALS['wp']->public_query_vars;
    1228    }
     
    5470    public function test_is_home_should_be_false_when_visiting_custom_endpoint_without_a_registered_query_var_and_page_on_front_is_set() {
    5571
    56         $page_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
    5772        update_option( 'show_on_front', 'page' );
    58         update_option( 'page_on_front', $page_id );
     73        update_option( 'page_on_front', self::$test_page_id );
    5974
    6075        add_rewrite_endpoint( 'test', EP_ALL, false );
     
    6681        $this->assertFalse( is_home() );
    6782    }
     83
     84    public function test_permalink_endpoint_only_applies_on_permalink() {
     85        add_rewrite_endpoint( 'permalink_endpoint', EP_PERMALINK );
     86        flush_rewrite_rules();
     87
     88        $this->go_to( get_permalink( self::$test_post_id ) . 'permalink_endpoint/foo/' );
     89
     90        $this->assertTrue( is_single( self::$test_post_id ) );
     91        $this->assertSame( 'foo', get_query_var( 'permalink_endpoint' ) );
     92
     93        $this->go_to( home_url( 'permalink_endpoint/foo/' ) );
     94
     95        $this->assertTrue( is_404() );
     96        $this->assertSame( '', get_query_var( 'permalink_endpoint' ) );
     97    }
     98
     99    public function test_page_endpoint_only_applies_on_page() {
     100        add_rewrite_endpoint( 'page_endpoint', EP_PAGES );
     101        flush_rewrite_rules();
     102
     103        $this->go_to( get_permalink( self::$test_page_id ) . 'page_endpoint/foo/' );
     104
     105        $this->assertTrue( is_page( self::$test_page_id ) );
     106        $this->assertSame( 'foo', get_query_var( 'page_endpoint' ) );
     107
     108        $this->go_to( home_url( 'page_endpoint/foo/' ) );
     109
     110        $this->assertTrue( is_404() );
     111        $this->assertSame( '', get_query_var( 'page_endpoint' ) );
     112    }
     113
    68114}
Note: See TracChangeset for help on using the changeset viewer.