From 18500b15fc201902779d023afb3c9047f6c9584d Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Tue, 9 Jan 2024 18:15:51 -0500 Subject: [PATCH 1/3] Add PHPUnit tests for wp_parse_slug_list function A new phpunit test file is added specifically for testing the 'wp_parse_slug_list' function. Different scenarios are covered including handling of plain numbers, strings with spaces, strings with commas, and HTML. This ensures that the function responds correctly to a wide array of inputs, improving overall software reliability and stability. --- .../tests/functions/wpParseSlugList.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/phpunit/tests/functions/wpParseSlugList.php diff --git a/tests/phpunit/tests/functions/wpParseSlugList.php b/tests/phpunit/tests/functions/wpParseSlugList.php new file mode 100644 index 0000000000000..dfc5091af1b9a --- /dev/null +++ b/tests/phpunit/tests/functions/wpParseSlugList.php @@ -0,0 +1,50 @@ +assertSameSets( $expected, wp_parse_slug_list( $list ) ); + } + + public function data_wp_parse_slug_list() { + return array( + 'simple' => array( + 'list' => array( '1', 2, 'string with spaces' ), + 'expected' => array( '1', '2', 'string-with-spaces' ), + ), + 'simple_with_comma' => array( + 'list' => '1,2,string with spaces', + 'expected' => array( '1', '2', 'string', 'with', 'spaces' ), + ), + 'array_with_spaces' => array( + 'list' => array( '1 2 string with spaces' ), + 'expected' => array( '1-2-string-with-spaces' ), + ), + 'simple_with_spaces' => array( + 'list' => '1 2 string with spaces', + 'expected' => array( '1', '2', 'string', 'with', 'spaces' ), + ), + 'array_html' => array( + 'list' => array( '1', 2, 'string with

HEADING

' ), + 'expected' => array( '1', '2', 'string-with-heading' ), + ), + 'simple_html_spaces' => array( + 'list' => '1 2 string with

HEADING

', + 'expected' => array( '1', '2', 'string', 'with', 'heading' ), + ), + ); + } +} From 966fd5fcbd27f01151a674da7275c587349e14ea Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Tue, 9 Jan 2024 19:13:34 -0500 Subject: [PATCH 2/3] Refactor variable names and add new tests in wpParseSlugList.php Updated the variable name 'list' to 'input_list' to get a more descriptive and precise meaning in wpParseSlugList.php. Also, a new test 'dup_id' is added to cover a scenario with duplicate identifiers in the input list. This will improve the comprehensiveness of the tests. --- .../tests/functions/wpParseSlugList.php | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/tests/phpunit/tests/functions/wpParseSlugList.php b/tests/phpunit/tests/functions/wpParseSlugList.php index dfc5091af1b9a..a71205346def5 100644 --- a/tests/phpunit/tests/functions/wpParseSlugList.php +++ b/tests/phpunit/tests/functions/wpParseSlugList.php @@ -14,36 +14,40 @@ class Tests_functions_wpParseSlugList extends WP_UnitTestCase { * * @dataProvider data_wp_parse_slug_list */ - public function test_wp_parse_slug_list( $list, $expected ) { + public function test_wp_parse_slug_list( $input_list, $expected ) { - $this->assertSameSets( $expected, wp_parse_slug_list( $list ) ); + $this->assertSameSets( $expected, wp_parse_slug_list( $input_list ) ); } public function data_wp_parse_slug_list() { return array( 'simple' => array( - 'list' => array( '1', 2, 'string with spaces' ), - 'expected' => array( '1', '2', 'string-with-spaces' ), + 'input_list' => array( '1', 2, 'string with spaces' ), + 'expected' => array( '1', '2', 'string-with-spaces' ), ), 'simple_with_comma' => array( - 'list' => '1,2,string with spaces', - 'expected' => array( '1', '2', 'string', 'with', 'spaces' ), + 'input_list' => '1,2,string with spaces', + 'expected' => array( '1', '2', 'string', 'with', 'spaces' ), ), 'array_with_spaces' => array( - 'list' => array( '1 2 string with spaces' ), - 'expected' => array( '1-2-string-with-spaces' ), + 'input_list' => array( '1 2 string with spaces' ), + 'expected' => array( '1-2-string-with-spaces' ), ), 'simple_with_spaces' => array( - 'list' => '1 2 string with spaces', - 'expected' => array( '1', '2', 'string', 'with', 'spaces' ), + 'input_list' => '1 2 string with spaces', + 'expected' => array( '1', '2', 'string', 'with', 'spaces' ), ), 'array_html' => array( - 'list' => array( '1', 2, 'string with

HEADING

' ), - 'expected' => array( '1', '2', 'string-with-heading' ), + 'input_list' => array( '1', 2, 'string with

HEADING

' ), + 'expected' => array( '1', '2', 'string-with-heading' ), ), 'simple_html_spaces' => array( - 'list' => '1 2 string with

HEADING

', - 'expected' => array( '1', '2', 'string', 'with', 'heading' ), + 'input_list' => '1 2 string with

HEADING

', + 'expected' => array( '1', '2', 'string', 'with', 'heading' ), + ), + 'dup_id' => array( + 'input_list' => '1 1 string string', + 'expected' => array( '1', 'string' ), ), ); } From 1f22aabb3d485a0faceaf982fc7f0b2455f954ab Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Tue, 9 Jan 2024 19:16:22 -0500 Subject: [PATCH 3/3] Add test data annotation to wpParseSlugList.php Added a comment block to annotate the 'data_wp_parse_slug_list' function, providing information on its associated ticket 60217. This enhances the readability and traceability of the code within the 'wpParseSlugList.php' test file. --- tests/phpunit/tests/functions/wpParseSlugList.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/phpunit/tests/functions/wpParseSlugList.php b/tests/phpunit/tests/functions/wpParseSlugList.php index a71205346def5..0ef632cb1945d 100644 --- a/tests/phpunit/tests/functions/wpParseSlugList.php +++ b/tests/phpunit/tests/functions/wpParseSlugList.php @@ -19,6 +19,13 @@ public function test_wp_parse_slug_list( $input_list, $expected ) { $this->assertSameSets( $expected, wp_parse_slug_list( $input_list ) ); } + /** + * data for test_wp_parse_slug_list + * + * @ticket 60217 + * + * @return array[] + */ public function data_wp_parse_slug_list() { return array( 'simple' => array(