From 8be1de325677441e6b5b8fcba85c4393d290059f Mon Sep 17 00:00:00 2001 From: Aaron Jorbin <622599+aaronjorbin@users.noreply.github.com> Date: Sat, 30 May 2026 10:48:36 -0500 Subject: [PATCH] Tests: Convert repetitive s-type methods to use @dataProvider in parseQuery.php --- tests/phpunit/tests/query/parseQuery.php | 68 ++++++++---------------- 1 file changed, 23 insertions(+), 45 deletions(-) diff --git a/tests/phpunit/tests/query/parseQuery.php b/tests/phpunit/tests/query/parseQuery.php index 7830b6723dfa5..974357f167791 100644 --- a/tests/phpunit/tests/query/parseQuery.php +++ b/tests/phpunit/tests/query/parseQuery.php @@ -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'] ); } /**