Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 23 additions & 45 deletions tests/phpunit/tests/query/parseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,39 @@
*/
class Tests_Query_ParseQuery extends WP_UnitTestCase {
/**
* @ticket 29736
* Data provider for test_parse_query_s_type.
*
* @return array[]
*/
public function test_parse_query_s_array() {
$q = new WP_Query();
$q->parse_query(
array(
's' => array( 'foo' ),
)
public function data_parse_query_s_types() {
return array(
'array input returns empty string' => array( array( 'foo' ), '' ),
'string input returns string' => array( 'foo', 'foo' ),
'float input returns float' => array( 3.5, 3.5 ),
'int input returns int' => array( 3, 3 ),
'bool input returns bool' => array( true, true ),
);

$this->assertSame( '', $q->query_vars['s'] );
}

public function test_parse_query_s_string() {
$q = new WP_Query();
$q->parse_query(
array(
's' => 'foo',
)
);

$this->assertSame( 'foo', $q->query_vars['s'] );
}

public function test_parse_query_s_float() {
$q = new WP_Query();
$q->parse_query(
array(
's' => 3.5,
)
);

$this->assertSame( 3.5, $q->query_vars['s'] );
}

public function test_parse_query_s_int() {
$q = new WP_Query();
$q->parse_query(
array(
's' => 3,
)
);

$this->assertSame( 3, $q->query_vars['s'] );
}

public function test_parse_query_s_bool() {
/**
* Tests that WP_Query::parse_query() handles various types for the 's' parameter.
*
* @ticket 29736
*
* @dataProvider data_parse_query_s_types
*
* @param mixed $input The value to pass as 's'.
* @param mixed $expected The expected value of query_vars['s'].
*/
public function test_parse_query_s_type( $input, $expected ) {
$q = new WP_Query();
$q->parse_query(
array(
's' => true,
's' => $input,
)
);

$this->assertTrue( $q->query_vars['s'] );
$this->assertSame( $expected, $q->query_vars['s'] );
}

/**
Expand Down
Loading