From 5fdf2b4b44b2fab4a7d8fdcbe9e01192344390fc Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Tue, 31 May 2016 19:28:46 +0000 Subject: [PATCH] Add tests for `no_found_rows` behavior of `WP_Query`. See #29952. git-svn-id: https://develop.svn.wordpress.org/trunk@37600 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/query/noFoundRows.php | 89 +++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 tests/phpunit/tests/query/noFoundRows.php diff --git a/tests/phpunit/tests/query/noFoundRows.php b/tests/phpunit/tests/query/noFoundRows.php new file mode 100644 index 0000000000..7762ded9b3 --- /dev/null +++ b/tests/phpunit/tests/query/noFoundRows.php @@ -0,0 +1,89 @@ + 'post', + ) ); + + $this->assertContains( 'SQL_CALC_FOUND_ROWS', $q->request ); + } + + public function test_no_found_rows_false() { + $q = new WP_Query( array( + 'post_type' => 'post', + 'no_found_rows' => false, + ) ); + + $this->assertContains( 'SQL_CALC_FOUND_ROWS', $q->request ); + } + + public function test_no_found_rows_0() { + $q = new WP_Query( array( + 'post_type' => 'post', + 'no_found_rows' => 0, + ) ); + + $this->assertContains( 'SQL_CALC_FOUND_ROWS', $q->request ); + } + + public function test_no_found_rows_empty_string() { + $q = new WP_Query( array( + 'post_type' => 'post', + 'no_found_rows' => '', + ) ); + + $this->assertContains( 'SQL_CALC_FOUND_ROWS', $q->request ); + } + + public function test_no_found_rows_true() { + $q = new WP_Query( array( + 'post_type' => 'post', + 'no_found_rows' => true, + ) ); + + $this->assertNotContains( 'SQL_CALC_FOUND_ROWS', $q->request ); + } + + public function test_no_found_rows_non_bool_cast_to_true() { + $q = new WP_Query( array( + 'post_type' => 'post', + 'no_found_rows' => 'foo', + ) ); + + $this->assertNotContains( 'SQL_CALC_FOUND_ROWS', $q->request ); + } + + /** + * @ticket 29552 + */ + public function test_no_found_rows_default_with_nopaging_true() { + $p = $this->factory->post->create(); + + $q = new WP_Query( array( + 'post_type' => 'post', + 'nopaging' => true, + ) ); + + $this->assertNotContains( 'SQL_CALC_FOUND_ROWS', $q->request ); + $this->assertSame( 1, $q->found_posts ); + } + + /** + * @ticket 29552 + */ + public function test_no_found_rows_default_with_postsperpage_minus1() { + $p = $this->factory->post->create(); + + $q = new WP_Query( array( + 'post_type' => 'post', + 'posts_per_page' => -1, + ) ); + + $this->assertNotContains( 'SQL_CALC_FOUND_ROWS', $q->request ); + $this->assertSame( 1, $q->found_posts ); + } +}