Skip to content

Commit

Permalink
Add PHPUnit tests for wp_parse_slug_list function
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pbearne committed Jan 9, 2024
1 parent 52720ef commit 18500b1
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/phpunit/tests/functions/wpParseSlugList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* Tests for the wp_parse_slug_list function.
*
* @group functions
*
* @covers ::wp_parse_slug_list
*/
class Tests_functions_wpParseSlugList extends WP_UnitTestCase {

/**
* @ticket 60217
*
* @dataProvider data_wp_parse_slug_list
*/
public function test_wp_parse_slug_list( $list, $expected ) {

Check warning on line 17 in tests/phpunit/tests/functions/wpParseSlugList.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

It is recommended not to use reserved keyword "list" as function parameter name. Found: $list

$this->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 <strong>with</strong> <h1>HEADING</h1>' ),
'expected' => array( '1', '2', 'string-with-heading' ),
),
'simple_html_spaces' => array(
'list' => '1 2 string <strong>with</strong> <h1>HEADING</h1>',
'expected' => array( '1', '2', 'string', 'with', 'heading' ),
),
);
}
}

0 comments on commit 18500b1

Please sign in to comment.