77class Tests_Formatting_Emoji extends WP_UnitTestCase {
88
99 private $ png_cdn = 'https://s.w.org/images/core/emoji/16.0.1/72x72/ ' ;
10- private $ svn_cdn = 'https://s.w.org/images/core/emoji/16.0.1/svg/ ' ;
10+ private $ svg_cdn = 'https://s.w.org/images/core/emoji/16.0.1/svg/ ' ;
11+
12+ /**
13+ * @ticket 63842
14+ *
15+ * @covers ::_print_emoji_detection_script
16+ */
17+ public function test_script_tag_printing () {
18+ // `_print_emoji_detection_script()` assumes `wp-includes/js/wp-emoji-loader.js` is present:
19+ self ::touch ( ABSPATH . WPINC . '/js/wp-emoji-loader.js ' );
20+ $ output = get_echo ( '_print_emoji_detection_script ' );
21+
22+ $ processor = new WP_HTML_Tag_Processor ( $ output );
23+ $ this ->assertTrue ( $ processor ->next_tag () );
24+ $ this ->assertSame ( 'SCRIPT ' , $ processor ->get_tag () );
25+ $ this ->assertSame ( 'wp-emoji-settings ' , $ processor ->get_attribute ( 'id ' ) );
26+ $ this ->assertSame ( 'application/json ' , $ processor ->get_attribute ( 'type ' ) );
27+ $ text = $ processor ->get_modifiable_text ();
28+ $ settings = json_decode ( $ text , true );
29+ $ this ->assertIsArray ( $ settings );
30+
31+ $ this ->assertEqualSets (
32+ array ( 'baseUrl ' , 'ext ' , 'svgUrl ' , 'svgExt ' , 'source ' ),
33+ array_keys ( $ settings )
34+ );
35+ $ this ->assertSame ( $ this ->png_cdn , $ settings ['baseUrl ' ] );
36+ $ this ->assertSame ( '.png ' , $ settings ['ext ' ] );
37+ $ this ->assertSame ( $ this ->svg_cdn , $ settings ['svgUrl ' ] );
38+ $ this ->assertSame ( '.svg ' , $ settings ['svgExt ' ] );
39+ $ this ->assertIsArray ( $ settings ['source ' ] );
40+ $ this ->assertArrayHasKey ( 'wpemoji ' , $ settings ['source ' ] );
41+ $ this ->assertArrayHasKey ( 'twemoji ' , $ settings ['source ' ] );
42+ $ this ->assertTrue ( $ processor ->next_tag () );
43+ $ this ->assertSame ( 'SCRIPT ' , $ processor ->get_tag () );
44+ $ this ->assertSame ( 'module ' , $ processor ->get_attribute ( 'type ' ) );
45+ $ this ->assertNull ( $ processor ->get_attribute ( 'src ' ) );
46+ $ this ->assertFalse ( $ processor ->next_tag () );
47+ }
1148
1249 /**
1350 * @ticket 36525
@@ -20,7 +57,7 @@ public function test_unfiltered_emoji_cdns() {
2057 $ output = get_echo ( '_print_emoji_detection_script ' );
2158
2259 $ this ->assertStringContainsString ( wp_json_encode ( $ this ->png_cdn , JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $ output );
23- $ this ->assertStringContainsString ( wp_json_encode ( $ this ->svn_cdn , JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $ output );
60+ $ this ->assertStringContainsString ( wp_json_encode ( $ this ->svg_cdn , JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $ output );
2461 }
2562
2663 public function _filtered_emoji_svn_cdn ( $ cdn = '' ) {
@@ -42,7 +79,7 @@ public function test_filtered_emoji_svn_cdn() {
4279 $ output = get_echo ( '_print_emoji_detection_script ' );
4380
4481 $ this ->assertStringContainsString ( wp_json_encode ( $ this ->png_cdn , JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $ output );
45- $ this ->assertStringNotContainsString ( wp_json_encode ( $ this ->svn_cdn , JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $ output );
82+ $ this ->assertStringNotContainsString ( wp_json_encode ( $ this ->svg_cdn , JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $ output );
4683 $ this ->assertStringContainsString ( wp_json_encode ( $ filtered_svn_cdn , JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $ output );
4784
4885 remove_filter ( 'emoji_svg_url ' , array ( $ this , '_filtered_emoji_svn_cdn ' ) );
@@ -68,7 +105,7 @@ public function test_filtered_emoji_png_cdn() {
68105
69106 $ this ->assertStringContainsString ( wp_json_encode ( $ filtered_png_cdn , JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $ output );
70107 $ this ->assertStringNotContainsString ( wp_json_encode ( $ this ->png_cdn , JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $ output );
71- $ this ->assertStringContainsString ( wp_json_encode ( $ this ->svn_cdn , JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $ output );
108+ $ this ->assertStringContainsString ( wp_json_encode ( $ this ->svg_cdn , JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $ output );
72109
73110 remove_filter ( 'emoji_url ' , array ( $ this , '_filtered_emoji_png_cdn ' ) );
74111 }
0 commit comments