From 465e66e2cd771061e4cf11492cc960bb176a3e0b Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Thu, 29 Jan 2015 02:30:22 +0000 Subject: [PATCH] Add basic unit tests for `get_page_of_comment()`. See #11334. Props jeremyfelt. git-svn-id: https://develop.svn.wordpress.org/trunk@31289 602fd350-edb4-49c9-b593-d223f7449a82 --- .../tests/comment/getPageOfComment.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/phpunit/tests/comment/getPageOfComment.php diff --git a/tests/phpunit/tests/comment/getPageOfComment.php b/tests/phpunit/tests/comment/getPageOfComment.php new file mode 100644 index 0000000000..5e03a16780 --- /dev/null +++ b/tests/phpunit/tests/comment/getPageOfComment.php @@ -0,0 +1,41 @@ +factory->post->create(); + + // page 4 + $comment_last = $this->factory->comment->create_post_comments( $p, 1, array( 'comment_date' => '2013-09-24 00:00:00' ) ); + $this->factory->comment->create_post_comments( $p, 1, array( 'comment_date' => '2013-09-23 00:00:00' ) ); + + // page 3 + $this->factory->comment->create_post_comments( $p, 1, array( 'comment_date' => '2013-09-22 00:00:00' ) ); + $this->factory->comment->create_post_comments( $p, 1, array( 'comment_date' => '2013-09-21 00:00:00' ) ); + $this->factory->comment->create_post_comments( $p, 1, array( 'comment_date' => '2013-09-20 00:00:00' ) ); + + // page 2 + $this->factory->comment->create_post_comments( $p, 1, array( 'comment_date' => '2013-09-19 00:00:00' ) ); + $this->factory->comment->create_post_comments( $p, 1, array( 'comment_date' => '2013-09-18 00:00:00' ) ); + $this->factory->comment->create_post_comments( $p, 1, array( 'comment_date' => '2013-09-17 00:00:00' ) ); + + // page 1 + $this->factory->comment->create_post_comments( $p, 1, array( 'comment_date' => '2013-09-16 00:00:00' ) ); + $this->factory->comment->create_post_comments( $p, 1, array( 'comment_date' => '2013-09-15 00:00:00' ) ); + $comment_first = $this->factory->comment->create_post_comments( $p, 1, array( 'comment_date' => '2013-09-14 00:00:00' ) ); + + $this->assertEquals( 4, get_page_of_comment( $comment_last[0], array( 'per_page' => 3 ) ) ); + $this->assertEquals( 2, get_page_of_comment( $comment_last[0], array( 'per_page' => 10 ) ) ); + + $this->assertEquals( 1, get_page_of_comment( $comment_first[0], array( 'per_page' => 3 ) ) ); + $this->assertEquals( 1, get_page_of_comment( $comment_first[0], array( 'per_page' => 10 ) ) ); + } +}