Skip to content

Commit 67f34fb

Browse files
author
boonebgorges
committed
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
1 parent ff48c03 commit 67f34fb

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
/**
4+
* @group query
5+
*/
6+
class Tests_Query_NoFoundRows extends WP_UnitTestCase {
7+
public function test_no_found_rows_default() {
8+
$q = new WP_Query( array(
9+
'post_type' => 'post',
10+
) );
11+
12+
$this->assertContains( 'SQL_CALC_FOUND_ROWS', $q->request );
13+
}
14+
15+
public function test_no_found_rows_false() {
16+
$q = new WP_Query( array(
17+
'post_type' => 'post',
18+
'no_found_rows' => false,
19+
) );
20+
21+
$this->assertContains( 'SQL_CALC_FOUND_ROWS', $q->request );
22+
}
23+
24+
public function test_no_found_rows_0() {
25+
$q = new WP_Query( array(
26+
'post_type' => 'post',
27+
'no_found_rows' => 0,
28+
) );
29+
30+
$this->assertContains( 'SQL_CALC_FOUND_ROWS', $q->request );
31+
}
32+
33+
public function test_no_found_rows_empty_string() {
34+
$q = new WP_Query( array(
35+
'post_type' => 'post',
36+
'no_found_rows' => '',
37+
) );
38+
39+
$this->assertContains( 'SQL_CALC_FOUND_ROWS', $q->request );
40+
}
41+
42+
public function test_no_found_rows_true() {
43+
$q = new WP_Query( array(
44+
'post_type' => 'post',
45+
'no_found_rows' => true,
46+
) );
47+
48+
$this->assertNotContains( 'SQL_CALC_FOUND_ROWS', $q->request );
49+
}
50+
51+
public function test_no_found_rows_non_bool_cast_to_true() {
52+
$q = new WP_Query( array(
53+
'post_type' => 'post',
54+
'no_found_rows' => 'foo',
55+
) );
56+
57+
$this->assertNotContains( 'SQL_CALC_FOUND_ROWS', $q->request );
58+
}
59+
60+
/**
61+
* @ticket 29552
62+
*/
63+
public function test_no_found_rows_default_with_nopaging_true() {
64+
$p = $this->factory->post->create();
65+
66+
$q = new WP_Query( array(
67+
'post_type' => 'post',
68+
'nopaging' => true,
69+
) );
70+
71+
$this->assertNotContains( 'SQL_CALC_FOUND_ROWS', $q->request );
72+
$this->assertSame( 1, $q->found_posts );
73+
}
74+
75+
/**
76+
* @ticket 29552
77+
*/
78+
public function test_no_found_rows_default_with_postsperpage_minus1() {
79+
$p = $this->factory->post->create();
80+
81+
$q = new WP_Query( array(
82+
'post_type' => 'post',
83+
'posts_per_page' => -1,
84+
) );
85+
86+
$this->assertNotContains( 'SQL_CALC_FOUND_ROWS', $q->request );
87+
$this->assertSame( 1, $q->found_posts );
88+
}
89+
}

0 commit comments

Comments
 (0)