forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmoji.php
More file actions
149 lines (123 loc) · 3.73 KB
/
Emoji.php
File metadata and controls
149 lines (123 loc) · 3.73 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
/**
* @group formatting
* @group emoji
*/
class Tests_Formatting_Emoji extends WP_UnitTestCase {
private $png_cdn = 'https://s.w.org/images/core/emoji/13.0.1/72x72/';
private $svn_cdn = 'https://s.w.org/images/core/emoji/13.0.1/svg/';
/**
* @ticket 36525
*/
public function test_unfiltered_emoji_cdns() {
$output = get_echo( '_print_emoji_detection_script' );
$this->assertContains( wp_json_encode( $this->png_cdn ), $output );
$this->assertContains( wp_json_encode( $this->svn_cdn ), $output );
}
public function _filtered_emoji_svn_cdn( $cdn = '' ) {
return 'https://s.wordpress.org/images/core/emoji/svg/';
}
/**
* @ticket 36525
*/
public function test_filtered_emoji_svn_cdn() {
$filtered_svn_cdn = $this->_filtered_emoji_svn_cdn();
add_filter( 'emoji_svg_url', array( $this, '_filtered_emoji_svn_cdn' ) );
$output = get_echo( '_print_emoji_detection_script' );
$this->assertContains( wp_json_encode( $this->png_cdn ), $output );
$this->assertNotContains( wp_json_encode( $this->svn_cdn ), $output );
$this->assertContains( wp_json_encode( $filtered_svn_cdn ), $output );
remove_filter( 'emoji_svg_url', array( $this, '_filtered_emoji_svn_cdn' ) );
}
public function _filtered_emoji_png_cdn( $cdn = '' ) {
return 'https://s.wordpress.org/images/core/emoji/png_cdn/';
}
/**
* @ticket 36525
*/
public function test_filtered_emoji_png_cdn() {
$filtered_png_cdn = $this->_filtered_emoji_png_cdn();
add_filter( 'emoji_url', array( $this, '_filtered_emoji_png_cdn' ) );
$output = get_echo( '_print_emoji_detection_script' );
$this->assertContains( wp_json_encode( $filtered_png_cdn ), $output );
$this->assertNotContains( wp_json_encode( $this->png_cdn ), $output );
$this->assertContains( wp_json_encode( $this->svn_cdn ), $output );
remove_filter( 'emoji_url', array( $this, '_filtered_emoji_png_cdn' ) );
}
/**
* @ticket 41501
*/
public function test_wp_emoji_list_returns_data() {
$default = _wp_emoji_list();
$this->assertNotEmpty( $default );
$entities = _wp_emoji_list( 'entities' );
$this->assertNotEmpty( $entities );
$this->assertSame( $default, $entities );
$partials = _wp_emoji_list( 'partials' );
$this->assertNotEmpty( $partials );
$this->assertNotSame( $default, $partials );
}
public function data_wp_encode_emoji() {
return array(
array(
// Not emoji.
'’',
'’',
),
array(
// Simple emoji.
'🙂',
'🙂',
),
array(
// Skin tone, gender, ZWJ, emoji selector.
'👮🏼♀️',
'👮🏼‍♀️',
),
array(
// Unicode 10.
'🧚',
'🧚',
),
);
}
/**
* @ticket 35293
* @dataProvider data_wp_encode_emoji
*/
public function test_wp_encode_emoji( $emoji, $expected ) {
$this->assertSame( $expected, wp_encode_emoji( $emoji ) );
}
public function data_wp_staticize_emoji() {
$data = array(
array(
// Not emoji.
'’',
'’',
),
array(
// Simple emoji.
'🙂',
'<img src="' . $this->png_cdn . '1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
),
array(
// Skin tone, gender, ZWJ, emoji selector.
'👮🏼♀️',
'<img src="' . $this->png_cdn . '1f46e-1f3fc-200d-2640-fe0f.png" alt="👮🏼♀️" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
),
array(
// Unicode 10.
'🧚',
'<img src="' . $this->png_cdn . '1f9da.png" alt="🧚" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
),
);
return $data;
}
/**
* @ticket 35293
* @dataProvider data_wp_staticize_emoji
*/
public function test_wp_staticize_emoji( $emoji, $expected ) {
$this->assertSame( $expected, wp_staticize_emoji( $emoji ) );
}
}