From 7bb34dc5d96fc2d6f451ba98d73d0132e8a43255 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sun, 28 Aug 2016 02:01:53 +0000 Subject: [PATCH] Query: Add and improve tests for query conditionals on the front page and home page. See #37851 git-svn-id: https://develop.svn.wordpress.org/trunk@38413 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/query/conditionals.php | 27 +++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/query/conditionals.php b/tests/phpunit/tests/query/conditionals.php index 8b5820e953..21963c7c81 100644 --- a/tests/phpunit/tests/query/conditionals.php +++ b/tests/phpunit/tests/query/conditionals.php @@ -32,6 +32,28 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { $this->assertQueryTrue( 'is_home', 'is_front_page' ); } + function test_page_on_front() { + $page_on_front = self::factory()->post->create( array( + 'post_type' => 'page', + ) ); + $page_for_posts = self::factory()->post->create( array( + 'post_type' => 'page', + ) ); + update_option( 'show_on_front', 'page' ); + update_option( 'page_on_front', $page_on_front ); + update_option( 'page_for_posts', $page_for_posts ); + + $this->go_to( '/' ); + $this->assertQueryTrue( 'is_front_page', 'is_page', 'is_singular' ); + + $this->go_to( get_permalink( $page_for_posts ) ); + $this->assertQueryTrue( 'is_home', 'is_posts_page' ); + + update_option( 'show_on_front', 'posts' ); + delete_option( 'page_on_front' ); + delete_option( 'page_for_posts' ); + } + function test_404() { $this->go_to('/'.rand_str()); $this->assertQueryTrue('is_404'); @@ -198,7 +220,6 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { $this->assertEquals( $page_id, $wp_query->get_queried_object()->ID ); } - // FIXME: what is this for? // '(about)(/[0-9]+)?/?$' => 'index.php?pagename=$matches[1]&page=$matches[2]' function test_pagination_of_posts_page() { $page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'about', 'post_content' => 'Page 1 Page 2' ) ); @@ -212,6 +233,9 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { // make sure the correct page was fetched global $wp_query; $this->assertEquals( $page_id, $wp_query->get_queried_object()->ID ); + + update_option( 'show_on_front', 'posts' ); + delete_option( 'page_for_posts' ); } // FIXME: no tests for these yet @@ -329,6 +353,7 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { // 'category/(.+?)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?category_name=$matches[1]&feed=$matches[2]', function test_category_feed() { self::factory()->term->create( array( 'name' => 'cat-a', 'taxonomy' => 'category' ) ); + // check the long form $types = array('feed', 'rdf', 'rss', 'rss2', 'atom'); foreach ($types as $type) {