diff --git a/tests/phpunit/tests/post/getPageTemplateSlug.php b/tests/phpunit/tests/post/getPageTemplateSlug.php new file mode 100644 index 0000000000..5a735350f5 --- /dev/null +++ b/tests/phpunit/tests/post/getPageTemplateSlug.php @@ -0,0 +1,75 @@ +post->create( + array( + 'post_type' => 'page', + ) + ); + + $this->assertSame( '', get_page_template_slug( $page_id ) ); + + update_post_meta( $page_id, '_wp_page_template', 'default' ); + $this->assertSame( '', get_page_template_slug( $page_id ) ); + + update_post_meta( $page_id, '_wp_page_template', 'example.php' ); + $this->assertSame( 'example.php', get_page_template_slug( $page_id ) ); + } + + /** + * @ticket 31389 + */ + public function test_get_page_template_slug_from_loop() { + $page_id = self::factory()->post->create( + array( + 'post_type' => 'page', + ) + ); + + update_post_meta( $page_id, '_wp_page_template', 'example.php' ); + $this->go_to( get_permalink( $page_id ) ); + + $this->assertSame( 'example.php', get_page_template_slug() ); + } + + /** + * @ticket 31389 + * @ticket 18375 + */ + public function test_get_page_template_slug_non_page() { + $post_id = self::factory()->post->create(); + + $this->assertSame( '', get_page_template_slug( $post_id ) ); + + update_post_meta( $post_id, '_wp_page_template', 'default' ); + + $this->assertSame( '', get_page_template_slug( $post_id ) ); + + update_post_meta( $post_id, '_wp_page_template', 'example.php' ); + $this->assertSame( 'example.php', get_page_template_slug( $post_id ) ); + } + + /** + * @ticket 18375 + */ + public function test_get_page_template_slug_non_page_from_loop() { + $post_id = self::factory()->post->create(); + + update_post_meta( $post_id, '_wp_page_template', 'example.php' ); + + $this->go_to( get_permalink( $post_id ) ); + + $this->assertSame( 'example.php', get_page_template_slug() ); + } +} diff --git a/tests/phpunit/tests/post/getPostParent.php b/tests/phpunit/tests/post/getPostParent.php new file mode 100644 index 0000000000..e66b458513 --- /dev/null +++ b/tests/phpunit/tests/post/getPostParent.php @@ -0,0 +1,72 @@ + 'publish', + 'post_type' => 'page', + ); + + // Insert two initial posts. + $parent_id = self::factory()->post->create( $post ); + $child_id = self::factory()->post->create( $post ); + + // Test if the function returns null by default. + $parent = get_post_parent( $child_id ); + $this->assertNull( $parent ); + + // Update child post with a parent. + wp_update_post( + array( + 'ID' => $child_id, + 'post_parent' => $parent_id, + ) + ); + + // Test if the function returns the parent object. + $parent = get_post_parent( $child_id ); + $this->assertNotNull( $parent ); + $this->assertSame( $parent_id, $parent->ID ); + } + + /** + * @ticket 33045 + */ + public function test_has_post_parent() { + $post = array( + 'post_status' => 'publish', + 'post_type' => 'page', + ); + + // Insert two initial posts. + $parent_id = self::factory()->post->create( $post ); + $child_id = self::factory()->post->create( $post ); + + // Test if the function returns false by default. + $parent = has_post_parent( $child_id ); + $this->assertFalse( $parent ); + + // Update child post with a parent. + wp_update_post( + array( + 'ID' => $child_id, + 'post_parent' => $parent_id, + ) + ); + + // Test if the function returns true for a child post. + $parent = has_post_parent( $child_id ); + $this->assertTrue( $parent ); + } +} diff --git a/tests/phpunit/tests/post/nav-menu.php b/tests/phpunit/tests/post/nav-menu.php index d02a9b1767..918b76e8e1 100644 --- a/tests/phpunit/tests/post/nav-menu.php +++ b/tests/phpunit/tests/post/nav-menu.php @@ -15,6 +15,51 @@ class Tests_Post_Nav_Menu extends WP_UnitTestCase { $this->menu_id = wp_create_nav_menu( 'foo' ); } + /** + * @ticket 11095 + * @ticket 33974 + */ + public function test_wp_page_menu_wp_nav_menu_fallback() { + $pages = self::factory()->post->create_many( 3, array( 'post_type' => 'page' ) ); + + // No menus + wp_nav_menu() falls back to wp_page_menu(). + $menu = wp_nav_menu( array( 'echo' => false ) ); + + // After falling back, the 'before' argument should be set and output as '