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

See #33728, #24853


git-svn-id: https://develop.svn.wordpress.org/trunk@35259 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn 2015-10-18 06:23:48 +00:00
parent a314c6c234
commit 219b56a6a4
1 changed files with 48 additions and 2 deletions

View File

@ -5,9 +5,25 @@
*/
class Tests_Rewrite_AddRewriteEndpoint extends WP_UnitTestCase {
private $qvs;
protected static $test_page_id;
protected static $test_post_id;
public static function wpSetUpBeforeClass( $factory ) {
self::$test_page_id = $factory->post->create( array(
'post_type' => 'page',
) );
self::$test_post_id = $factory->post->create();
}
public static function wpTearDownAfterClass() {
wp_delete_post( self::$test_page_id, true );
}
public function setUp() {
parent::setUp();
$this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
$this->qvs = $GLOBALS['wp']->public_query_vars;
}
@ -53,9 +69,8 @@ class Tests_Rewrite_AddRewriteEndpoint extends WP_UnitTestCase {
*/
public function test_is_home_should_be_false_when_visiting_custom_endpoint_without_a_registered_query_var_and_page_on_front_is_set() {
$page_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
update_option( 'show_on_front', 'page' );
update_option( 'page_on_front', $page_id );
update_option( 'page_on_front', self::$test_page_id );
add_rewrite_endpoint( 'test', EP_ALL, false );
flush_rewrite_rules();
@ -65,4 +80,35 @@ class Tests_Rewrite_AddRewriteEndpoint extends WP_UnitTestCase {
$this->assertQueryTrue( 'is_front_page', 'is_page', 'is_singular' );
$this->assertFalse( is_home() );
}
public function test_permalink_endpoint_only_applies_on_permalink() {
add_rewrite_endpoint( 'permalink_endpoint', EP_PERMALINK );
flush_rewrite_rules();
$this->go_to( get_permalink( self::$test_post_id ) . 'permalink_endpoint/foo/' );
$this->assertTrue( is_single( self::$test_post_id ) );
$this->assertSame( 'foo', get_query_var( 'permalink_endpoint' ) );
$this->go_to( home_url( 'permalink_endpoint/foo/' ) );
$this->assertTrue( is_404() );
$this->assertSame( '', get_query_var( 'permalink_endpoint' ) );
}
public function test_page_endpoint_only_applies_on_page() {
add_rewrite_endpoint( 'page_endpoint', EP_PAGES );
flush_rewrite_rules();
$this->go_to( get_permalink( self::$test_page_id ) . 'page_endpoint/foo/' );
$this->assertTrue( is_page( self::$test_page_id ) );
$this->assertSame( 'foo', get_query_var( 'page_endpoint' ) );
$this->go_to( home_url( 'page_endpoint/foo/' ) );
$this->assertTrue( is_404() );
$this->assertSame( '', get_query_var( 'page_endpoint' ) );
}
}