mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
As these are not user-defined functions, they cause notices when generating the code coverage report:
{{{
"@covers ::array_key_first" is invalid
"@covers ::array_key_last" is invalid
"@covers ::hash_hmac" is invalid
"@covers ::is_countable" is invalid
"@covers ::is_iterable" is invalid
"@covers ::mb_strlen" is invalid
"@covers ::mb_substr" is invalid
"@covers ::str_contains" is invalid
"@covers ::str_ends_with" is invalid
"@covers ::str_starts_with" is invalid
}}}
Follow-up to [51852], [52038], [52039], [52040].
See #39265, #55652.
git-svn-id: https://develop.svn.wordpress.org/trunk@54049 602fd350-edb4-49c9-b593-d223f7449a82
114 lines
2.7 KiB
PHP
114 lines
2.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group compat
|
|
*/
|
|
class Tests_Compat_StrEndsWith extends WP_UnitTestCase {
|
|
|
|
/**
|
|
* Test that str_ends_with() is always available (either from PHP or WP).
|
|
*
|
|
* @ticket 54377
|
|
*/
|
|
public function test_str_ends_with_availability() {
|
|
$this->assertTrue( function_exists( 'str_ends_with' ) );
|
|
}
|
|
|
|
/**
|
|
* @dataProvider data_str_ends_with
|
|
*
|
|
* @ticket 54377
|
|
*
|
|
* @param bool $expected Whether or not `$haystack` is expected to end with `$needle`.
|
|
* @param string $haystack The string to search in.
|
|
* @param string $needle The substring to search for at the end of `$haystack`.
|
|
*/
|
|
public function test_str_ends_with( $expected, $haystack, $needle ) {
|
|
if ( ! function_exists( 'str_ends_with' ) ) {
|
|
$this->markTestSkipped( 'str_ends_with() is not available.' );
|
|
} else {
|
|
$this->assertSame(
|
|
$expected,
|
|
str_ends_with( $haystack, $needle )
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Data provider.
|
|
*
|
|
* @return array[]
|
|
*/
|
|
public function data_str_ends_with() {
|
|
return array(
|
|
'empty needle' => array(
|
|
'expected' => true,
|
|
'haystack' => 'This is a test',
|
|
'needle' => '',
|
|
),
|
|
'empty haystack and needle' => array(
|
|
'expected' => true,
|
|
'haystack' => '',
|
|
'needle' => '',
|
|
),
|
|
'empty haystack' => array(
|
|
'expected' => false,
|
|
'haystack' => '',
|
|
'needle' => 'test',
|
|
),
|
|
'lowercase' => array(
|
|
'expected' => true,
|
|
'haystack' => 'This is a test',
|
|
'needle' => 'test',
|
|
),
|
|
'uppercase' => array(
|
|
'expected' => true,
|
|
'haystack' => 'This is a TEST',
|
|
'needle' => 'TEST',
|
|
),
|
|
'first letter uppercase' => array(
|
|
'expected' => true,
|
|
'haystack' => 'This is a Test',
|
|
'needle' => 'Test',
|
|
),
|
|
'camelCase' => array(
|
|
'expected' => true,
|
|
'haystack' => 'This is a camelCase',
|
|
'needle' => 'camelCase',
|
|
),
|
|
'null' => array(
|
|
'expected' => true,
|
|
'haystack' => 'This is a null \x00test',
|
|
'needle' => '\x00test',
|
|
),
|
|
'trademark' => array(
|
|
'expected' => true,
|
|
'haystack' => 'This is a trademark\x2122',
|
|
'needle' => 'trademark\x2122',
|
|
),
|
|
'not camelCase' => array(
|
|
'expected' => false,
|
|
'haystack' => 'This is a cammelcase',
|
|
'needle' => 'cammelCase',
|
|
),
|
|
'missing' => array(
|
|
'expected' => false,
|
|
'haystack' => 'This is a cammelcase',
|
|
'needle' => 'cammelCase',
|
|
),
|
|
'not end' => array(
|
|
'expected' => false,
|
|
'haystack' => 'This is a test extra',
|
|
'needle' => 'test',
|
|
),
|
|
'extra space' => array(
|
|
'expected' => false,
|
|
'haystack' => 'This is a test ',
|
|
'needle' => 'test',
|
|
),
|
|
|
|
);
|
|
}
|
|
}
|