Fix comment_order for single page comment threads.

The old comment pagination logic had a separate block for comment threads that
appeared on a single page. After the refactoring in [34561], all comment
pagination logic is unified.

This change ensures that 'comment_order' is respected in all scenarios.

Fixes #8071.

git-svn-id: https://develop.svn.wordpress.org/trunk@34669 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2015-09-28 19:29:22 +00:00
parent ac85963ad4
commit f261d3ac8a
2 changed files with 327 additions and 42 deletions

View File

@@ -0,0 +1,288 @@
<?php
/**
* @group comment
*
* Testing items that are only testable by grabbing the markup of `comments_template()` from the output buffer.
*/
class Tests_Comment_CommentsTemplate extends WP_UnitTestCase {
/**
* @ticket 8071
*/
public function test_should_respect_comment_order_asc_when_default_comments_page_is_newest() {
$now = time();
$p = $this->factory->post->create();
$comment_1 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '1',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
) );
$comment_2 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '2',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
) );
update_option( 'comment_order', 'asc' );
update_option( 'default_comments_page', 'newest' );
$this->go_to( get_permalink( $p ) );
$found = get_echo( 'comments_template' );
// Life in the fast lane.
$comments = preg_match_all( '/id="comment-([0-9]+)"/', $found, $matches );
$found_cids = array_map( 'intval', $matches[1] );
$this->assertSame( array( $comment_1, $comment_2 ), $found_cids );
}
/**
* @ticket 8071
*/
public function test_should_respect_comment_order_desc_when_default_comments_page_is_newest() {
$now = time();
$p = $this->factory->post->create();
$comment_1 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '1',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
) );
$comment_2 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '2',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
) );
update_option( 'comment_order', 'desc' );
update_option( 'default_comments_page', 'newest' );
$this->go_to( get_permalink( $p ) );
$found = get_echo( 'comments_template' );
// Life in the fast lane.
$comments = preg_match_all( '/id="comment-([0-9]+)"/', $found, $matches );
$found_cids = array_map( 'intval', $matches[1] );
$this->assertSame( array( $comment_2, $comment_1 ), $found_cids );
}
/**
* @ticket 8071
*/
public function test_should_respect_comment_order_asc_when_default_comments_page_is_oldest() {
$now = time();
$p = $this->factory->post->create();
$comment_1 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '1',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
) );
$comment_2 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '2',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
) );
update_option( 'comment_order', 'asc' );
update_option( 'default_comments_page', 'oldest' );
$this->go_to( get_permalink( $p ) );
$found = get_echo( 'comments_template' );
// Life in the fast lane.
$comments = preg_match_all( '/id="comment-([0-9]+)"/', $found, $matches );
$found_cids = array_map( 'intval', $matches[1] );
$this->assertSame( array( $comment_1, $comment_2 ), $found_cids );
}
/**
* @ticket 8071
*/
public function test_should_respect_comment_order_desc_when_default_comments_page_is_oldest() {
$now = time();
$p = $this->factory->post->create();
$comment_1 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '1',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
) );
$comment_2 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '2',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
) );
update_option( 'comment_order', 'desc' );
update_option( 'default_comments_page', 'oldest' );
$this->go_to( get_permalink( $p ) );
$found = get_echo( 'comments_template' );
// Life in the fast lane.
$comments = preg_match_all( '/id="comment-([0-9]+)"/', $found, $matches );
$found_cids = array_map( 'intval', $matches[1] );
$this->assertSame( array( $comment_2, $comment_1 ), $found_cids );
}
/**
* @ticket 8071
*/
public function test_should_respect_comment_order_asc_when_default_comments_page_is_newest_on_subsequent_pages() {
$now = time();
$p = $this->factory->post->create();
$comment_1 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '1',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
) );
$comment_2 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '2',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
) );
$comment_3 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '3',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
) );
$comment_4 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '4',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 400 ),
) );
update_option( 'comment_order', 'asc' );
update_option( 'default_comments_page', 'newest' );
$this->go_to( get_permalink( $p ) . '?cpage=2&comments_per_page=2' );
$found = get_echo( 'comments_template' );
// Life in the fast lane.
$comments = preg_match_all( '/id="comment-([0-9]+)"/', $found, $matches );
$found_cids = array_map( 'intval', $matches[1] );
$this->assertSame( array( $comment_3, $comment_4 ), $found_cids );
}
/**
* @ticket 8071
*/
public function test_should_respect_comment_order_desc_when_default_comments_page_is_newest_on_subsequent_pages() {
$now = time();
$p = $this->factory->post->create();
$comment_1 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '1',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
) );
$comment_2 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '2',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
) );
$comment_3 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '3',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
) );
$comment_4 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '4',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 400 ),
) );
update_option( 'comment_order', 'desc' );
update_option( 'default_comments_page', 'newest' );
$this->go_to( get_permalink( $p ) . '?cpage=2&comments_per_page=2' );
$found = get_echo( 'comments_template' );
// Life in the fast lane.
$comments = preg_match_all( '/id="comment-([0-9]+)"/', $found, $matches );
$found_cids = array_map( 'intval', $matches[1] );
$this->assertSame( array( $comment_4, $comment_3 ), $found_cids );
}
/**
* @ticket 8071
*/
public function test_should_respect_comment_order_asc_when_default_comments_page_is_oldest_on_subsequent_pages() {
$now = time();
$p = $this->factory->post->create();
$comment_1 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '1',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
) );
$comment_2 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '2',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
) );
$comment_3 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '3',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
) );
$comment_4 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '4',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 400 ),
) );
update_option( 'comment_order', 'asc' );
update_option( 'default_comments_page', 'oldest' );
$this->go_to( get_permalink( $p ) . '?cpage=2&comments_per_page=2' );
$found = get_echo( 'comments_template' );
// Life in the fast lane.
$comments = preg_match_all( '/id="comment-([0-9]+)"/', $found, $matches );
$found_cids = array_map( 'intval', $matches[1] );
$this->assertSame( array( $comment_1, $comment_2 ), $found_cids );
}
/**
* @ticket 8071
*/
public function test_should_respect_comment_order_desc_when_default_comments_page_is_oldest_on_subsequent_pages() {
$now = time();
$p = $this->factory->post->create();
$comment_1 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '1',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
) );
$comment_2 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '2',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
) );
$comment_3 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '3',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
) );
$comment_4 = $this->factory->comment->create( array(
'comment_post_ID' => $p,
'comment_content' => '4',
'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 400 ),
) );
update_option( 'comment_order', 'desc' );
update_option( 'default_comments_page', 'oldest' );
$this->go_to( get_permalink( $p ) . '?cpage=2&comments_per_page=2' );
$found = get_echo( 'comments_template' );
// Life in the fast lane.
$comments = preg_match_all( '/id="comment-([0-9]+)"/', $found, $matches );
$found_cids = array_map( 'intval', $matches[1] );
$this->assertSame( array( $comment_2, $comment_1 ), $found_cids );
}
}