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
This commit is contained in:
John Blackbourn 2016-08-28 02:01:53 +00:00
parent 20dae52ec9
commit 7bb34dc5d9

View File

@ -32,6 +32,28 @@ class Tests_Query_Conditionals extends WP_UnitTestCase {
$this->assertQueryTrue( 'is_home', 'is_front_page' ); $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() { function test_404() {
$this->go_to('/'.rand_str()); $this->go_to('/'.rand_str());
$this->assertQueryTrue('is_404'); $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 ); $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]' // '(about)(/[0-9]+)?/?$' => 'index.php?pagename=$matches[1]&page=$matches[2]'
function test_pagination_of_posts_page() { function test_pagination_of_posts_page() {
$page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'about', 'post_content' => 'Page 1 <!--nextpage--> Page 2' ) ); $page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'about', 'post_content' => 'Page 1 <!--nextpage--> Page 2' ) );
@ -212,6 +233,9 @@ class Tests_Query_Conditionals extends WP_UnitTestCase {
// make sure the correct page was fetched // make sure the correct page was fetched
global $wp_query; global $wp_query;
$this->assertEquals( $page_id, $wp_query->get_queried_object()->ID ); $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 // 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]', // 'category/(.+?)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?category_name=$matches[1]&feed=$matches[2]',
function test_category_feed() { function test_category_feed() {
self::factory()->term->create( array( 'name' => 'cat-a', 'taxonomy' => 'category' ) ); self::factory()->term->create( array( 'name' => 'cat-a', 'taxonomy' => 'category' ) );
// check the long form // check the long form
$types = array('feed', 'rdf', 'rss', 'rss2', 'atom'); $types = array('feed', 'rdf', 'rss', 'rss2', 'atom');
foreach ($types as $type) { foreach ($types as $type) {