Make WordPress Core

Changeset 52778


Ignore:
Timestamp:
02/19/2022 01:43:53 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Tests: Convert _wp_to_kebab_case() tests to use a data provider.

Follow-up to [51198], [51225].

See #54725.

File:
1 edited

Legend:

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

    r51246 r52778  
    1111class Tests_Functions_wpToKebabCase extends WP_UnitTestCase {
    1212
    13     public function test_wp_to_kebab_case() {
    14         $this->assertSame( 'white', _wp_to_kebab_case( 'white' ) );
    15         $this->assertSame( 'white-black', _wp_to_kebab_case( 'white+black' ) );
    16         $this->assertSame( 'white-black', _wp_to_kebab_case( 'white:black' ) );
    17         $this->assertSame( 'white-black', _wp_to_kebab_case( 'white*black' ) );
    18         $this->assertSame( 'white-black', _wp_to_kebab_case( 'white.black' ) );
    19         $this->assertSame( 'white-black', _wp_to_kebab_case( 'white black' ) );
    20         $this->assertSame( 'white-black', _wp_to_kebab_case( 'white black' ) );
    21         $this->assertSame( 'white-to-black', _wp_to_kebab_case( 'white-to-black' ) );
    22         $this->assertSame( 'white-2-white', _wp_to_kebab_case( 'white2white' ) );
    23         $this->assertSame( 'white-2nd', _wp_to_kebab_case( 'white2nd' ) );
    24         $this->assertSame( 'white-2-ndcolor', _wp_to_kebab_case( 'white2ndcolor' ) );
    25         $this->assertSame( 'white-2nd-color', _wp_to_kebab_case( 'white2ndColor' ) );
    26         $this->assertSame( 'white-2nd-color', _wp_to_kebab_case( 'white2nd_color' ) );
    27         $this->assertSame( 'white-23-color', _wp_to_kebab_case( 'white23color' ) );
    28         $this->assertSame( 'white-23', _wp_to_kebab_case( 'white23' ) );
    29         $this->assertSame( '23-color', _wp_to_kebab_case( '23color' ) );
    30         $this->assertSame( 'white-4th', _wp_to_kebab_case( 'white4th' ) );
    31         $this->assertSame( 'font-2-xl', _wp_to_kebab_case( 'font2xl' ) );
    32         $this->assertSame( 'white-to-white', _wp_to_kebab_case( 'whiteToWhite' ) );
    33         $this->assertSame( 'white-t-owhite', _wp_to_kebab_case( 'whiteTOwhite' ) );
    34         $this->assertSame( 'whit-eto-white', _wp_to_kebab_case( 'WHITEtoWHITE' ) );
    35         $this->assertSame( '42', _wp_to_kebab_case( 42 ) );
    36         $this->assertSame( 'ive-done', _wp_to_kebab_case( "i've done" ) );
    37         $this->assertSame( 'ffffff', _wp_to_kebab_case( '#ffffff' ) );
    38         $this->assertSame( 'ffffff', _wp_to_kebab_case( '$ffffff' ) );
     13    /**
     14     * Test _wp_to_kebab_case().
     15     *
     16     * @dataProvider data_wp_to_kebab_case
     17     *
     18     * @ticket 53397
     19     *
     20     * @param string $test_value Test value.
     21     * @param string $expected   Expected return value.
     22     */
     23    public function test_wp_to_kebab_case( $test_value, $expected ) {
     24        $this->assertSame( $expected, _wp_to_kebab_case( $test_value ) );
     25    }
     26
     27    /**
     28     * Data provider for test_wp_to_kebab_case().
     29     *
     30     * @return array[] Test parameters {
     31     *     @type string $test_value Test value.
     32     *     @type string $expected   Expected return value.
     33     * }
     34     */
     35    public function data_wp_to_kebab_case() {
     36        return array(
     37            array( 'white', 'white' ),
     38            array( 'white+black', 'white-black' ),
     39            array( 'white:black', 'white-black' ),
     40            array( 'white*black', 'white-black' ),
     41            array( 'white.black', 'white-black' ),
     42            array( 'white black', 'white-black' ),
     43            array( 'white   black', 'white-black' ),
     44            array( 'white-to-black', 'white-to-black' ),
     45            array( 'white2white', 'white-2-white' ),
     46            array( 'white2nd', 'white-2nd' ),
     47            array( 'white2ndcolor', 'white-2-ndcolor' ),
     48            array( 'white2ndColor', 'white-2nd-color' ),
     49            array( 'white2nd_color', 'white-2nd-color' ),
     50            array( 'white23color', 'white-23-color' ),
     51            array( 'white23', 'white-23' ),
     52            array( '23color', '23-color' ),
     53            array( 'white4th', 'white-4th' ),
     54            array( 'font2xl', 'font-2-xl' ),
     55            array( 'whiteToWhite', 'white-to-white' ),
     56            array( 'whiteTOwhite', 'white-t-owhite' ),
     57            array( 'WHITEtoWHITE', 'whit-eto-white' ),
     58            array( 42, '42' ),
     59            array( "i've done", 'ive-done' ),
     60            array( '#ffffff', 'ffffff' ),
     61            array( '$ffffff', 'ffffff' ),
     62        );
    3963    }
    4064}
Note: See TracChangeset for help on using the changeset viewer.