Skip to content

Commit b4ce056

Browse files
committed
Build/Test Tools: Convert repetitive s-type methods to use a @dataProvider
Make it easier to add additional test cases for parse_query and query_var[s] tests. See #64894. git-svn-id: https://develop.svn.wordpress.org/trunk@62462 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 8bed69c commit b4ce056

1 file changed

Lines changed: 23 additions & 45 deletions

File tree

tests/phpunit/tests/query/parseQuery.php

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,39 @@
55
*/
66
class Tests_Query_ParseQuery extends WP_UnitTestCase {
77
/**
8-
* @ticket 29736
8+
* Data provider for test_parse_query_s_type.
9+
*
10+
* @return array[]
911
*/
10-
public function test_parse_query_s_array() {
11-
$q = new WP_Query();
12-
$q->parse_query(
13-
array(
14-
's' => array( 'foo' ),
15-
)
12+
public function data_parse_query_s_types() {
13+
return array(
14+
'array input returns empty string' => array( array( 'foo' ), '' ),
15+
'string input returns string' => array( 'foo', 'foo' ),
16+
'float input returns float' => array( 3.5, 3.5 ),
17+
'int input returns int' => array( 3, 3 ),
18+
'bool input returns bool' => array( true, true ),
1619
);
17-
18-
$this->assertSame( '', $q->query_vars['s'] );
1920
}
2021

21-
public function test_parse_query_s_string() {
22-
$q = new WP_Query();
23-
$q->parse_query(
24-
array(
25-
's' => 'foo',
26-
)
27-
);
28-
29-
$this->assertSame( 'foo', $q->query_vars['s'] );
30-
}
31-
32-
public function test_parse_query_s_float() {
33-
$q = new WP_Query();
34-
$q->parse_query(
35-
array(
36-
's' => 3.5,
37-
)
38-
);
39-
40-
$this->assertSame( 3.5, $q->query_vars['s'] );
41-
}
42-
43-
public function test_parse_query_s_int() {
44-
$q = new WP_Query();
45-
$q->parse_query(
46-
array(
47-
's' => 3,
48-
)
49-
);
50-
51-
$this->assertSame( 3, $q->query_vars['s'] );
52-
}
53-
54-
public function test_parse_query_s_bool() {
22+
/**
23+
* Tests that WP_Query::parse_query() handles various types for the 's' parameter.
24+
*
25+
* @ticket 29736
26+
*
27+
* @dataProvider data_parse_query_s_types
28+
*
29+
* @param mixed $input The value to pass as 's'.
30+
* @param mixed $expected The expected value of query_vars['s'].
31+
*/
32+
public function test_parse_query_s_type( $input, $expected ) {
5533
$q = new WP_Query();
5634
$q->parse_query(
5735
array(
58-
's' => true,
36+
's' => $input,
5937
)
6038
);
6139

62-
$this->assertTrue( $q->query_vars['s'] );
40+
$this->assertSame( $expected, $q->query_vars['s'] );
6341
}
6442

6543
/**

0 commit comments

Comments
 (0)