Make WordPress Core


Ignore:
Timestamp:
02/28/2024 06:09:38 PM (13 months ago)
Author:
SergeyBiryukov
Message:

Tests: Expand wp_parse_id_list() unit tests.

Includes:

  • Moving pre-existing wp_parse_id_list() tests to their own file.
  • Merging new and pre-existing wp_parse_slug_list() tests.
  • Using named data provider in wp_parse_list() tests.

Follow-up to [25170], [40044], [44546], [57284], [57725].

Props pbearne, mukesh27, SergeyBiryukov.
Fixes #60218. See #60217, #59647.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/functions/wpParseSlugList.php

    r57735 r57737  
    1111
    1212    /**
     13     * @ticket 35582
    1314     * @ticket 60217
    1415     *
    1516     * @dataProvider data_wp_parse_slug_list
     17     * @dataProvider data_unexpected_input
    1618     */
    1719    public function test_wp_parse_slug_list( $input_list, $expected ) {
    18 
    1920        $this->assertSameSets( $expected, wp_parse_slug_list( $input_list ) );
    2021    }
    2122
    2223    /**
    23      * Data provider for test_wp_parse_slug_list().
     24     * Data provider.
    2425     *
    2526     * @return array[]
     
    2728    public function data_wp_parse_slug_list() {
    2829        return array(
    29             'simple'             => array(
     30            'regular'                    => array(
     31                'input_list' => 'apple,banana,carrot,dog',
     32                'expected'   => array( 'apple', 'banana', 'carrot', 'dog' ),
     33            ),
     34            'double comma'               => array(
     35                'input_list' => 'apple, banana,,carrot,dog',
     36                'expected'   => array( 'apple', 'banana', 'carrot', 'dog' ),
     37            ),
     38            'duplicate slug in a string' => array(
     39                'input_list' => 'apple,banana,carrot,carrot,dog',
     40                'expected'   => array( 'apple', 'banana', 'carrot', 'dog' ),
     41            ),
     42            'duplicate slug in an array' => array(
     43                'input_list' => array( 'apple', 'banana', 'carrot', 'carrot', 'dog' ),
     44                'expected'   => array( 'apple', 'banana', 'carrot', 'dog' ),
     45            ),
     46            'string with spaces'         => array(
     47                'input_list' => 'apple banana carrot dog',
     48                'expected'   => array( 'apple', 'banana', 'carrot', 'dog' ),
     49            ),
     50            'array with spaces'          => array(
     51                'input_list' => array( 'apple ', 'banana carrot', 'd o g' ),
     52                'expected'   => array( 'apple', 'banana-carrot', 'd-o-g' ),
     53            ),
     54        );
     55    }
     56
     57    /**
     58     * Data provider.
     59     *
     60     * @return array[]
     61     */
     62    public function data_unexpected_input() {
     63        return array(
     64            'string with commas' => array(
     65                'input_list' => '1,2,string with spaces',
     66                'expected'   => array( '1', '2', 'string', 'with', 'spaces' ),
     67            ),
     68            'array'              => array(
    3069                'input_list' => array( '1', 2, 'string with spaces' ),
    3170                'expected'   => array( '1', '2', 'string-with-spaces' ),
    3271            ),
    33             'simple_with_comma' => array(
    34                 'input_list' => '1,2,string with spaces',
     72            'string with spaces' => array(
     73                'input_list' => '1 2 string with spaces',
    3574                'expected'   => array( '1', '2', 'string', 'with', 'spaces' ),
    3675            ),
    37             'array_with_spaces'  => array(
     76            'array with spaces'  => array(
    3877                'input_list' => array( '1 2 string with spaces' ),
    3978                'expected'   => array( '1-2-string-with-spaces' ),
    4079            ),
    41             'simple_with_spaces' => array(
    42                 'input_list' => '1 2 string with spaces',
    43                 'expected'   => array( '1', '2', 'string', 'with', 'spaces' ),
     80            'string with html'  => array(
     81                'input_list' => '1 2 string <strong>with</strong> <h1>HEADING</h1>',
     82                'expected'   => array( '1', '2', 'string', 'with', 'heading' ),
    4483            ),
    45             'array_html'         => array(
     84            'array with html'    => array(
    4685                'input_list' => array( '1', 2, 'string <strong>with</strong> <h1>HEADING</h1>' ),
    4786                'expected'   => array( '1', '2', 'string-with-heading' ),
    4887            ),
    49             'simple_html_spaces' => array(
    50                 'input_list' => '1 2 string <strong>with</strong> <h1>HEADING</h1>',
    51                 'expected'   => array( '1', '2', 'string', 'with', 'heading' ),
     88            'array with null'    => array(
     89                'input_list' => array( 1, 2, null ),
     90                'expected'   => array( '1', '2' ),
    5291            ),
    53             'dup_id'             => array(
    54                 'input_list' => '1 1 string string',
    55                 'expected'   => array( '1', 'string' ),
     92            'array with false'   => array(
     93                'input_list' => array( 1, 2, false ),
     94                'expected'   => array( '1', '2', '' ),
    5695            ),
    5796        );
Note: See TracChangeset for help on using the changeset viewer.