forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrEndsWith.php
More file actions
107 lines (102 loc) · 2.62 KB
/
strEndsWith.php
File metadata and controls
107 lines (102 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/**
* @group compat
*
* @covers ::str_ends_with
*/
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 ) {
$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',
),
);
}
}