From 18500b15fc201902779d023afb3c9047f6c9584d Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Tue, 9 Jan 2024 18:15:51 -0500 Subject: [PATCH] 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' ), + ), + ); + } +}