forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmbStrlen.php
More file actions
91 lines (85 loc) · 2.4 KB
/
mbStrlen.php
File metadata and controls
91 lines (85 loc) · 2.4 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
<?php
/**
* @group compat
* @group security-153
*
* @covers ::mb_strlen
* @covers ::_mb_strlen
*/
class Tests_Compat_mbStrlen extends WP_UnitTestCase {
/**
* Test that mb_strlen() is always available (either from PHP or WP).
*/
public function test_mb_strlen_availability() {
$this->assertTrue( function_exists( 'mb_strlen' ) );
}
/**
* @dataProvider data_utf8_string_lengths
*/
public function test_mb_strlen( $input_string, $expected_character_length ) {
$this->assertSame( $expected_character_length, _mb_strlen( $input_string, 'UTF-8' ) );
}
/**
* @dataProvider data_utf8_string_lengths
*/
public function test_mb_strlen_via_regex( $input_string, $expected_character_length ) {
_wp_can_use_pcre_u( false );
$this->assertSame( $expected_character_length, _mb_strlen( $input_string, 'UTF-8' ) );
_wp_can_use_pcre_u( 'reset' );
}
/**
* @dataProvider data_utf8_string_lengths
*/
public function test_8bit_mb_strlen( $input_string, $expected_character_length, $expected_byte_length ) {
$this->assertSame( $expected_byte_length, _mb_strlen( $input_string, '8bit' ) );
}
/**
* Data provider.
*
* @return array
*/
public function data_utf8_string_lengths() {
return array(
array(
'input_string' => 'баба',
'expected_character_length' => 4,
'expected_byte_length' => 8,
),
array(
'input_string' => 'баб',
'expected_character_length' => 3,
'expected_byte_length' => 6,
),
array(
'input_string' => 'I am your б',
'expected_character_length' => 11,
'expected_byte_length' => 12,
),
array(
'input_string' => '1111111111',
'expected_character_length' => 10,
'expected_byte_length' => 10,
),
array(
'input_string' => '²²²²²²²²²²',
'expected_character_length' => 10,
'expected_byte_length' => 20,
),
array(
'input_string' => '3333333333',
'expected_character_length' => 10,
'expected_byte_length' => 30,
),
array(
'input_string' => '𝟜𝟜𝟜𝟜𝟜𝟜𝟜𝟜𝟜𝟜',
'expected_character_length' => 10,
'expected_byte_length' => 40,
),
array(
'input_string' => '1²3𝟜1²3𝟜1²3𝟜',
'expected_character_length' => 12,
'expected_byte_length' => 30,
),
);
}
}