- Timestamp:
- 10/18/2015 06:23:48 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rewrite/addRewriteEndpoint.php
r35256 r35259 6 6 class Tests_Rewrite_AddRewriteEndpoint extends WP_UnitTestCase { 7 7 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 } 8 21 9 22 public function setUp() { 10 23 parent::setUp(); 24 25 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 26 11 27 $this->qvs = $GLOBALS['wp']->public_query_vars; 12 28 } … … 54 70 public function test_is_home_should_be_false_when_visiting_custom_endpoint_without_a_registered_query_var_and_page_on_front_is_set() { 55 71 56 $page_id = self::factory()->post->create( array( 'post_type' => 'page' ) );57 72 update_option( 'show_on_front', 'page' ); 58 update_option( 'page_on_front', $page_id );73 update_option( 'page_on_front', self::$test_page_id ); 59 74 60 75 add_rewrite_endpoint( 'test', EP_ALL, false ); … … 66 81 $this->assertFalse( is_home() ); 67 82 } 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 68 114 }
Note: See TracChangeset
for help on using the changeset viewer.