From 8c22c526bdecce68efb7b255d707c63abb8459ec Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 24 Jun 2015 00:40:45 +0000 Subject: [PATCH] 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 --- tests/phpunit/includes/testcase-canonical.php | 25 ++++++++++++++ tests/phpunit/tests/canonical.php | 2 ++ tests/phpunit/tests/rewrite.php | 33 +++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/tests/phpunit/includes/testcase-canonical.php b/tests/phpunit/includes/testcase-canonical.php index 3c6e45d948..35a2d9728e 100644 --- a/tests/phpunit/includes/testcase-canonical.php +++ b/tests/phpunit/includes/testcase-canonical.php @@ -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'; diff --git a/tests/phpunit/tests/canonical.php b/tests/phpunit/tests/canonical.php index d69abcc757..b4fe50f4e1 100644 --- a/tests/phpunit/tests/canonical.php +++ b/tests/phpunit/tests/canonical.php @@ -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/'), diff --git a/tests/phpunit/tests/rewrite.php b/tests/phpunit/tests/rewrite.php index 34f0828e8d..cba783740d 100644 --- a/tests/phpunit/tests/rewrite.php +++ b/tests/phpunit/tests/rewrite.php @@ -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/' ) );