@@ -8,6 +8,27 @@ class Tests_Formatting_Emoji extends WP_UnitTestCase {
88
99 private $ png_cdn = 'https://s.w.org/images/core/emoji/15.0.3/72x72/ ' ;
1010 private $ svn_cdn = 'https://s.w.org/images/core/emoji/15.0.3/svg/ ' ;
11+ private $ original_theme_support ;
12+
13+ /**
14+ * Set up test environment for HTML5 script type attribute tests.
15+ */
16+ public function set_up () {
17+ parent ::set_up ();
18+
19+ global $ _wp_theme_features ;
20+ $ this ->original_theme_support = $ _wp_theme_features ;
21+ }
22+
23+ /**
24+ * Tear down test environment for HTML5 script type attribute tests.
25+ */
26+ public function tear_down () {
27+ global $ _wp_theme_features ;
28+ $ _wp_theme_features = $ this ->original_theme_support ;
29+
30+ parent ::tear_down ();
31+ }
1132
1233 /**
1334 * @ticket 36525
@@ -169,4 +190,78 @@ public function data_wp_staticize_emoji() {
169190 public function test_wp_staticize_emoji ( $ emoji , $ expected ) {
170191 $ this ->assertSame ( $ expected , wp_staticize_emoji ( $ emoji ) );
171192 }
193+
194+ /**
195+ * Test emoji detection script typeAttr setting based on HTML5 script support.
196+ *
197+ * @ticket 51837
198+ * @dataProvider data_html5_script_support
199+ */
200+ public function test_emoji_detection_script_html5_type_attribute ( $ html5_features , $ expected_has_type ) {
201+ remove_theme_support ( 'html5 ' );
202+ if ( ! empty ( $ html5_features ) ) {
203+ add_theme_support ( 'html5 ' , $ html5_features );
204+ }
205+
206+ // `_print_emoji_detection_script()` assumes `wp-includes/js/wp-emoji-loader.js` is present.
207+ self ::touch ( ABSPATH . WPINC . '/js/wp-emoji-loader.js ' );
208+ $ output = get_echo ( '_print_emoji_detection_script ' );
209+
210+ if ( $ expected_has_type ) {
211+ $ this ->assertStringContainsString ( '"typeAttr":" type= \\"text\/javascript \\"" ' , $ output );
212+ } else {
213+ $ this ->assertStringContainsString ( '"typeAttr":"" ' , $ output );
214+ }
215+
216+ $ this ->assertStringContainsString ( 'window._wpemojiSettings ' , $ output );
217+ }
218+
219+ /**
220+ * Test zxcvbn settings typeAttr based on HTML5 script support.
221+ *
222+ * @ticket 51837
223+ * @dataProvider data_html5_script_support
224+ */
225+ public function test_zxcvbn_settings_html5_type_attribute ( $ html5_features , $ expected_has_type ) {
226+ remove_theme_support ( 'html5 ' );
227+ if ( ! empty ( $ html5_features ) ) {
228+ add_theme_support ( 'html5 ' , $ html5_features );
229+ }
230+
231+ global $ wp_scripts ;
232+ $ wp_scripts = null ;
233+ wp_default_scripts ( wp_scripts () );
234+
235+ $ script_data = wp_scripts ()->get_data ( 'zxcvbn-async ' , 'data ' );
236+
237+ if ( $ expected_has_type ) {
238+ $ this ->assertStringContainsString ( '"typeAttr":" type= \\"text\/javascript \\"" ' , $ script_data );
239+ } else {
240+ $ this ->assertStringContainsString ( '"typeAttr":"" ' , $ script_data );
241+ }
242+
243+ $ this ->assertStringContainsString ( '"src": ' , $ script_data );
244+ }
245+
246+ /**
247+ * Data provider for HTML5 script support scenarios.
248+ *
249+ * @return array
250+ */
251+ public function data_html5_script_support () {
252+ return array (
253+ 'no html5 support ' => array (
254+ array (),
255+ true ,
256+ ),
257+ 'html5 script support ' => array (
258+ array ( 'script ' ),
259+ false ,
260+ ),
261+ 'html5 other features only ' => array (
262+ array ( 'comment-form ' , 'style ' ),
263+ true ,
264+ ),
265+ );
266+ }
172267}
0 commit comments