forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrContains.php
More file actions
96 lines (92 loc) · 2.33 KB
/
strContains.php
File metadata and controls
96 lines (92 loc) · 2.33 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
<?php
/**
* @group compat
*
* @covers ::str_contains
*/
class Tests_Compat_strContains extends WP_UnitTestCase {
/**
* Test that str_contains() is always available (either from PHP or WP).
*
* @ticket 49652
*/
public function test_is_str_contains_availability() {
$this->assertTrue( function_exists( 'str_contains' ) );
}
/**
* @dataProvider data_str_contains
*
* @ticket 49652
*
* @param bool $expected Whether or not `$haystack` is expected to contain `$needle`.
* @param string $haystack The string to search in.
* @param string $needle The substring to search for in `$haystack`.
*/
public function test_str_contains( $expected, $haystack, $needle ) {
$this->assertSame( $expected, str_contains( $haystack, $needle ) );
}
/**
* Data provider.
*
* @return array
*/
public function data_str_contains() {
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',
),
'start of string' => array(
'expected' => true,
'haystack' => 'This is a Test',
'needle' => 'This',
),
'middle of string' => array(
'expected' => true,
'haystack' => 'The needle in middle of string.',
'needle' => 'middle',
),
'end of string' => array(
'expected' => true,
'string' => 'The needle is at end.',
'needle' => 'end',
),
'lowercase' => array(
'expected' => true,
'string' => 'This is a test',
'needle' => 'test',
),
'uppercase' => array(
'expected' => true,
'string' => 'This is a TEST',
'needle' => 'TEST',
),
'camelCase' => array(
'expected' => true,
'string' => 'String contains camelCase.',
'needle' => 'camelCase',
),
'with hyphen' => array(
'expected' => true,
'string' => 'String contains foo-bar needle.',
'needle' => 'foo-bar',
),
'missing' => array(
'expected' => false,
'haystack' => 'This is a camelcase',
'needle' => 'camelCase',
),
);
}
}