Implement canonical and url_to_postid() tests for child pages which share a post name with other child pages.

See #32759


git-svn-id: https://develop.svn.wordpress.org/trunk@32918 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn 2015-06-24 00:40:45 +00:00
parent 06ed4c4d0f
commit 8c22c526bd
3 changed files with 60 additions and 0 deletions

View File

@ -80,6 +80,31 @@ class WP_Canonical_UnitTestCase extends WP_UnitTestCase {
array( 'import_id' => 144, 'post_type' => 'page', 'post_title' => 'child-page-1', 'post_parent' => $post_id,
) );
self::$post_ids[] = $parent_id = $factory->post->create( array(
'post_name' => 'parent',
'post_type' => 'page',
) );
self::$post_ids[] = $child_id_1 = $factory->post->create( array(
'post_name' => 'child1',
'post_type' => 'page',
'post_parent' => $parent_id,
) );
self::$post_ids[] = $child_id_2 = $factory->post->create( array(
'post_name' => 'child2',
'post_type' => 'page',
'post_parent' => $parent_id,
) );
self::$post_ids[] = $grandchild_id_1 = $factory->post->create( array(
'post_name' => 'grandchild',
'post_type' => 'page',
'post_parent' => $child_id_1,
) );
self::$post_ids[] = $grandchild_id_2 = $factory->post->create( array(
'post_name' => 'grandchild',
'post_type' => 'page',
'post_parent' => $child_id_2,
) );
$cat1 = $factory->term->create( array( 'taxonomy' => 'category', 'name' => 'parent' ) );
self::$terms['/category/parent/'] = $cat1;
self::$term_ids[ $cat1 ] = 'category';

View File

@ -79,6 +79,8 @@ class Tests_Canonical extends WP_Canonical_UnitTestCase {
array( '/child-page-1/', '/parent-page/child-page-1/'),
array( '/?page_id=144', '/parent-page/child-page-1/'),
array( '/abo', '/about/' ),
array( '/parent/child1/grandchild/', '/parent/child1/grandchild/' ),
array( '/parent/child2/grandchild/', '/parent/child2/grandchild/' ),
// Posts
array( '?p=587', '/2008/06/02/post-format-test-audio/'),

View File

@ -61,6 +61,39 @@ class Tests_Rewrite extends WP_UnitTestCase {
$this->assertEquals( $child_id, url_to_postid( get_permalink( $child_id ) ) );
}
function test_url_to_postid_hierarchical_with_matching_leaves() {
$parent_id = $this->factory->post->create( array(
'post_name' => 'parent',
'post_type' => 'page',
) );
$child_id_1 = $this->factory->post->create( array(
'post_name' => 'child1',
'post_type' => 'page',
'post_parent' => $parent_id,
) );
$child_id_2 = $this->factory->post->create( array(
'post_name' => 'child2',
'post_type' => 'page',
'post_parent' => $parent_id,
) );
$grandchild_id_1 = $this->factory->post->create( array(
'post_name' => 'grandchild',
'post_type' => 'page',
'post_parent' => $child_id_1,
) );
$grandchild_id_2 = $this->factory->post->create( array(
'post_name' => 'grandchild',
'post_type' => 'page',
'post_parent' => $child_id_2,
) );
$this->assertEquals( home_url( 'parent/child1/grandchild/' ), get_permalink( $grandchild_id_1 ) );
$this->assertEquals( home_url( 'parent/child2/grandchild/' ), get_permalink( $grandchild_id_2 ) );
$this->assertEquals( $grandchild_id_1, url_to_postid( get_permalink( $grandchild_id_1 ) ) );
$this->assertEquals( $grandchild_id_2, url_to_postid( get_permalink( $grandchild_id_2 ) ) );
}
function test_url_to_postid_home_has_path() {
update_option( 'home', home_url( '/example/' ) );