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

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

See #54725.

git-svn-id: https://develop.svn.wordpress.org/trunk@52778 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2022-02-19 13:43:53 +00:00
parent 3d0607f0df
commit 109953c1fb

View File

@ -10,31 +10,55 @@
*/
class Tests_Functions_wpToKebabCase extends WP_UnitTestCase {
public function test_wp_to_kebab_case() {
$this->assertSame( 'white', _wp_to_kebab_case( 'white' ) );
$this->assertSame( 'white-black', _wp_to_kebab_case( 'white+black' ) );
$this->assertSame( 'white-black', _wp_to_kebab_case( 'white:black' ) );
$this->assertSame( 'white-black', _wp_to_kebab_case( 'white*black' ) );
$this->assertSame( 'white-black', _wp_to_kebab_case( 'white.black' ) );
$this->assertSame( 'white-black', _wp_to_kebab_case( 'white black' ) );
$this->assertSame( 'white-black', _wp_to_kebab_case( 'white black' ) );
$this->assertSame( 'white-to-black', _wp_to_kebab_case( 'white-to-black' ) );
$this->assertSame( 'white-2-white', _wp_to_kebab_case( 'white2white' ) );
$this->assertSame( 'white-2nd', _wp_to_kebab_case( 'white2nd' ) );
$this->assertSame( 'white-2-ndcolor', _wp_to_kebab_case( 'white2ndcolor' ) );
$this->assertSame( 'white-2nd-color', _wp_to_kebab_case( 'white2ndColor' ) );
$this->assertSame( 'white-2nd-color', _wp_to_kebab_case( 'white2nd_color' ) );
$this->assertSame( 'white-23-color', _wp_to_kebab_case( 'white23color' ) );
$this->assertSame( 'white-23', _wp_to_kebab_case( 'white23' ) );
$this->assertSame( '23-color', _wp_to_kebab_case( '23color' ) );
$this->assertSame( 'white-4th', _wp_to_kebab_case( 'white4th' ) );
$this->assertSame( 'font-2-xl', _wp_to_kebab_case( 'font2xl' ) );
$this->assertSame( 'white-to-white', _wp_to_kebab_case( 'whiteToWhite' ) );
$this->assertSame( 'white-t-owhite', _wp_to_kebab_case( 'whiteTOwhite' ) );
$this->assertSame( 'whit-eto-white', _wp_to_kebab_case( 'WHITEtoWHITE' ) );
$this->assertSame( '42', _wp_to_kebab_case( 42 ) );
$this->assertSame( 'ive-done', _wp_to_kebab_case( "i've done" ) );
$this->assertSame( 'ffffff', _wp_to_kebab_case( '#ffffff' ) );
$this->assertSame( 'ffffff', _wp_to_kebab_case( '$ffffff' ) );
/**
* Test _wp_to_kebab_case().
*
* @dataProvider data_wp_to_kebab_case
*
* @ticket 53397
*
* @param string $test_value Test value.
* @param string $expected Expected return value.
*/
public function test_wp_to_kebab_case( $test_value, $expected ) {
$this->assertSame( $expected, _wp_to_kebab_case( $test_value ) );
}
/**
* Data provider for test_wp_to_kebab_case().
*
* @return array[] Test parameters {
* @type string $test_value Test value.
* @type string $expected Expected return value.
* }
*/
public function data_wp_to_kebab_case() {
return array(
array( 'white', 'white' ),
array( 'white+black', 'white-black' ),
array( 'white:black', 'white-black' ),
array( 'white*black', 'white-black' ),
array( 'white.black', 'white-black' ),
array( 'white black', 'white-black' ),
array( 'white black', 'white-black' ),
array( 'white-to-black', 'white-to-black' ),
array( 'white2white', 'white-2-white' ),
array( 'white2nd', 'white-2nd' ),
array( 'white2ndcolor', 'white-2-ndcolor' ),
array( 'white2ndColor', 'white-2nd-color' ),
array( 'white2nd_color', 'white-2nd-color' ),
array( 'white23color', 'white-23-color' ),
array( 'white23', 'white-23' ),
array( '23color', '23-color' ),
array( 'white4th', 'white-4th' ),
array( 'font2xl', 'font-2-xl' ),
array( 'whiteToWhite', 'white-to-white' ),
array( 'whiteTOwhite', 'white-t-owhite' ),
array( 'WHITEtoWHITE', 'whit-eto-white' ),
array( 42, '42' ),
array( "i've done", 'ive-done' ),
array( '#ffffff', 'ffffff' ),
array( '$ffffff', 'ffffff' ),
);
}
}