Skip to content

Commit d5cdabe

Browse files
committed
adding unit testcases and modifying solution to check only drafts
1 parent f880327 commit d5cdabe

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

src/wp-includes/class-wp-query.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ public function parse_query( $query = '' ) {
10891089

10901090
if ( 'page' === get_option( 'show_on_front' ) && isset( $this->queried_object_id ) && get_option( 'page_for_posts' ) == $this->queried_object_id ) {
10911091
$posts_page = get_post( $this->queried_object_id );
1092-
if ( ! $posts_page || 'publish' !== $posts_page->post_status ) {
1092+
if ( ! $posts_page || 'draft' == $posts_page->post_status ) {
10931093
$this->set_404();
10941094
return;
10951095
}
@@ -1106,7 +1106,7 @@ public function parse_query( $query = '' ) {
11061106
if ( $query_vars['page_id'] ) {
11071107
if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == $query_vars['page_id'] ) {
11081108
$posts_page = get_post( $query_vars['page_id'] );
1109-
if ( ! $posts_page || 'publish' !== $posts_page->post_status ) {
1109+
if ( ! $posts_page || 'draft' == $posts_page->post_status ) {
11101110
$this->set_404();
11111111
return;
11121112
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
class pageOnFront extends WP_UnitTestCase {
4+
5+
private $posts_page_id;
6+
public function set_up() {
7+
parent::set_up();
8+
9+
update_option( 'show_on_front', 'page' );
10+
$this->posts_page_id = self::factory()->post->create(
11+
array(
12+
'post_title' => 'blog-page',
13+
'post_type' => 'page',
14+
)
15+
);
16+
update_option('page_for_posts', $this->posts_page_id);
17+
update_option(
18+
'page_on_front',
19+
self::factory()->post->create(
20+
array(
21+
'post_title' => 'front-page',
22+
'post_type' => 'page',
23+
'post_content' => "Page 1\n<!--nextpage-->\nPage 2",
24+
)
25+
)
26+
);
27+
}
28+
29+
/**
30+
* Ensure unpublished posts page returns 404.
31+
*
32+
* @ticket 60566
33+
*/
34+
public function test_unpublished_posts_page_returns_404() {
35+
36+
wp_update_post( array(
37+
'ID' => $this->posts_page_id,
38+
'post_status' => 'draft',
39+
) );
40+
41+
$q = new WP_Query( array(
42+
'pagename' => 'blog-page',
43+
) );
44+
45+
$this->assertTrue(
46+
$q->is_404(),
47+
"Unpublished posts page with status should return 404"
48+
);
49+
}
50+
}

0 commit comments

Comments
 (0)