@@ -996,6 +996,8 @@ static function( $templates ) {
996996 * @covers AMP_Theme_Support::add_hooks()
997997 */
998998 public function test_add_hooks () {
999+ add_theme_support ( 'amp ' );
1000+ $ this ->go_to ( '/ ' );
9991001 AMP_Theme_Support::add_hooks ();
10001002 $ this ->assertFalse ( has_action ( 'wp_head ' , 'wp_post_preview_js ' ) );
10011003 $ this ->assertFalse ( has_action ( 'wp_head ' , 'wp_oembed_add_host_js ' ) );
@@ -1016,6 +1018,8 @@ public function test_add_hooks() {
10161018 $ this ->assertEquals ( 10 , has_filter ( 'customize_partial_render ' , [ self ::TESTED_CLASS , 'filter_customize_partial_render ' ] ) );
10171019 $ this ->assertEquals ( 10 , has_action ( 'wp_footer ' , 'amp_print_analytics ' ) );
10181020 $ this ->assertEquals ( 10 , has_action ( 'admin_bar_init ' , [ self ::TESTED_CLASS , 'init_admin_bar ' ] ) );
1021+ $ this ->assertEquals ( 10 , has_filter ( 'style_loader_tag ' , [ 'AMP_Theme_Support ' , 'filter_style_loader_tag_for_dev_mode ' ] ) );
1022+ $ this ->assertEquals ( 10 , has_filter ( 'script_loader_tag ' , [ 'AMP_Theme_Support ' , 'filter_script_loader_tag_for_dev_mode ' ] ) );
10191023 $ priority = defined ( 'PHP_INT_MIN ' ) ? PHP_INT_MIN : ~PHP_INT_MAX ; // phpcs:ignore PHPCompatibility.Constants.NewConstants.php_int_minFound
10201024 $ this ->assertEquals ( $ priority , has_action ( 'template_redirect ' , [ self ::TESTED_CLASS , 'start_output_buffering ' ] ) );
10211025
@@ -1237,8 +1241,8 @@ public function test_filter_cancel_comment_reply_link() {
12371241 * Test init_admin_bar.
12381242 *
12391243 * @covers \AMP_Theme_Support::init_admin_bar()
1240- * @covers \AMP_Theme_Support::filter_admin_bar_style_loader_tag ()
1241- * @covers \AMP_Theme_Support::filter_admin_bar_script_loader_tag ()
1244+ * @covers \AMP_Theme_Support::filter_style_loader_tag_for_dev_mode ()
1245+ * @covers \AMP_Theme_Support::filter_script_loader_tag_for_dev_mode ()
12421246 */
12431247 public function test_init_admin_bar () {
12441248 require_once ABSPATH . WPINC . '/class-wp-admin-bar.php ' ;
@@ -1269,8 +1273,7 @@ function() {
12691273 $ this ->assertEquals ( 10 , has_action ( 'wp_head ' , $ callback ) );
12701274
12711275 AMP_Theme_Support::init_admin_bar ();
1272- $ this ->assertEquals ( 10 , has_filter ( 'style_loader_tag ' , [ 'AMP_Theme_Support ' , 'filter_admin_bar_style_loader_tag ' ] ) );
1273- $ this ->assertEquals ( 10 , has_filter ( 'script_loader_tag ' , [ 'AMP_Theme_Support ' , 'filter_admin_bar_script_loader_tag ' ] ) );
1276+ AMP_Theme_Support::add_hooks ();
12741277 $ this ->assertFalse ( has_action ( 'wp_head ' , $ callback ) );
12751278 ob_start ();
12761279 wp_print_styles ();
@@ -1310,7 +1313,10 @@ public function assert_queried_element_exists( DOMXPath $xpath, $query ) {
13101313 public function assert_dev_mode_is_on_queried_element ( DOMXPath $ xpath , $ query ) {
13111314 $ element = $ xpath ->query ( $ query )->item ( 0 );
13121315 $ this ->assertInstanceOf ( 'DOMElement ' , $ element , 'Expected element for query: ' . $ query );
1313- $ this ->assertTrue ( $ element ->hasAttribute ( AMP_Rule_Spec::DEV_MODE_ATTRIBUTE ), 'Expected dev mode to be enabled on element for query: ' . $ query );
1316+ $ this ->assertTrue (
1317+ $ element ->hasAttribute ( AMP_Rule_Spec::DEV_MODE_ATTRIBUTE ),
1318+ 'Expected dev mode to be enabled on element for query: ' . $ query . "\nDocument: " . $ element ->ownerDocument ->saveHTML ()
1319+ );
13141320 }
13151321
13161322 /**
@@ -1326,7 +1332,7 @@ public function assert_dev_mode_is_not_on_queried_element( DOMXPath $xpath, $que
13261332 }
13271333
13281334 /**
1329- * Get data to test AMP_Theme_Support::filter_admin_bar_style_loader_tag ().
1335+ * Get data to test AMP_Theme_Support::filter_style_loader_tag_for_dev_mode ().
13301336 *
13311337 * @return array
13321338 */
@@ -1396,10 +1402,10 @@ function ( DOMXPath $xpath ) {
13961402 }
13971403
13981404 /**
1399- * Test filter_admin_bar_style_loader_tag .
1405+ * Test filter_style_loader_tag_for_dev_mode .
14001406 *
14011407 * @dataProvider get_data_to_test_filtering_admin_bar_style_loader_tag_data
1402- * @covers \AMP_Theme_Support::filter_admin_bar_style_loader_tag ()
1408+ * @covers \AMP_Theme_Support::filter_style_loader_tag_for_dev_mode ()
14031409 * @covers \AMP_Theme_Support::is_exclusively_dependent()
14041410 *
14051411 * @param callable $setup_callback Setup callback.
@@ -1409,7 +1415,7 @@ public function test_filter_admin_bar_style_loader_tag( $setup_callback, $assert
14091415 add_theme_support ( 'amp ' );
14101416 $ this ->go_to ( '/ ' );
14111417 add_filter ( 'amp_dev_mode_enabled ' , '__return_true ' );
1412- add_filter ( 'style_loader_tag ' , [ 'AMP_Theme_Support ' , 'filter_admin_bar_style_loader_tag ' ], 10 , 2 );
1418+ add_filter ( 'style_loader_tag ' , [ 'AMP_Theme_Support ' , 'filter_style_loader_tag_for_dev_mode ' ], 10 , 2 );
14131419 $ setup_callback ();
14141420 ob_start ();
14151421 echo '<html><head> ' ;
@@ -1424,7 +1430,7 @@ public function test_filter_admin_bar_style_loader_tag( $setup_callback, $assert
14241430 }
14251431
14261432 /**
1427- * Get data to test AMP_Theme_Support::filter_admin_bar_script_loader_tag ().
1433+ * Get data to test AMP_Theme_Support::filter_script_loader_tag_for_dev_mode ().
14281434 *
14291435 * @return array
14301436 */
@@ -1434,10 +1440,14 @@ public function get_data_to_test_filtering_admin_bar_script_loader_tag_data() {
14341440 static function () {
14351441 wp_enqueue_script ( 'admin-bar ' );
14361442 wp_enqueue_script ( 'example-admin-bar ' , 'https://example.com/example-admin-bar.js ' , [ 'admin-bar ' ], '0.1 ' , false );
1443+ wp_add_inline_script ( 'example-admin-bar ' , '/* inline-example-admin-bar */ ' );
1444+ wp_localize_script ( 'example-admin-bar ' , 'exampleAdminBar ' , [ 'hello ' => 'world ' ] );
14371445 },
14381446 function ( DOMXPath $ xpath ) {
14391447 $ this ->assert_dev_mode_is_on_queried_element ( $ xpath , '//script[ contains( @src, "/example-admin-bar" ) ] ' );
14401448 $ this ->assert_dev_mode_is_on_queried_element ( $ xpath , '//script[ contains( @src, "/admin-bar" ) ] ' );
1449+ $ this ->assert_dev_mode_is_on_queried_element ( $ xpath , '//script[ contains( text(), "inline-example-admin-bar" ) ] ' );
1450+ $ this ->assert_dev_mode_is_on_queried_element ( $ xpath , '//script[ contains( text(), "exampleAdminBar" ) ] ' );
14411451 if ( wp_script_is ( 'hoverintent-js ' , 'registered ' ) ) {
14421452 $ this ->assert_dev_mode_is_on_queried_element ( $ xpath , '//script[ contains( @src, "/hoverintent-js" ) ] ' );
14431453 }
@@ -1496,10 +1506,10 @@ function ( DOMXPath $xpath ) {
14961506 }
14971507
14981508 /**
1499- * Test filter_admin_bar_script_loader_tag .
1509+ * Test filter_script_loader_tag_for_dev_mode .
15001510 *
15011511 * @dataProvider get_data_to_test_filtering_admin_bar_script_loader_tag_data
1502- * @covers \AMP_Theme_Support::filter_admin_bar_script_loader_tag ()
1512+ * @covers \AMP_Theme_Support::filter_script_loader_tag_for_dev_mode ()
15031513 * @covers \AMP_Theme_Support::is_exclusively_dependent()
15041514 *
15051515 * @param callable $setup_callback Setup callback.
@@ -1509,7 +1519,7 @@ public function test_filter_admin_bar_script_loader_tag( $setup_callback, $asser
15091519 add_theme_support ( 'amp ' );
15101520 $ this ->go_to ( '/ ' );
15111521 add_filter ( 'amp_dev_mode_enabled ' , '__return_true ' );
1512- add_filter ( 'script_loader_tag ' , [ 'AMP_Theme_Support ' , 'filter_admin_bar_script_loader_tag ' ], 10 , 2 );
1522+ add_filter ( 'script_loader_tag ' , [ 'AMP_Theme_Support ' , 'filter_script_loader_tag_for_dev_mode ' ], 10 , 2 );
15131523 $ setup_callback ();
15141524 ob_start ();
15151525 echo '<html><head> ' ;
@@ -1519,8 +1529,14 @@ public function test_filter_admin_bar_script_loader_tag( $setup_callback, $asser
15191529 echo '</body></html> ' ;
15201530 $ output = ob_get_clean ();
15211531
1522- $ dom = new DOMDocument ();
1523- @$ dom ->loadHTML ( $ output ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
1532+ $ dom = new Document ();
1533+ $ dom ->loadHTML ( $ output );
1534+
1535+ AMP_Content_Sanitizer::sanitize_document (
1536+ $ dom ,
1537+ wp_array_slice_assoc ( amp_get_content_sanitizers (), [ 'AMP_Dev_Mode_Sanitizer ' ] ),
1538+ [ 'use_document_element ' => true ]
1539+ );
15241540
15251541 $ assert_callback ( new DOMXPath ( $ dom ) );
15261542 }
@@ -1529,15 +1545,18 @@ public function test_filter_admin_bar_script_loader_tag( $setup_callback, $asser
15291545 * Test init_admin_bar to ensure dashicons are not added to dev mode when directly enqueued.
15301546 *
15311547 * @covers \AMP_Theme_Support::init_admin_bar()
1532- * @covers \AMP_Theme_Support::filter_admin_bar_style_loader_tag ()
1548+ * @covers \AMP_Theme_Support::filter_style_loader_tag_for_dev_mode ()
15331549 */
15341550 public function test_init_admin_bar_for_directly_enqueued_dashicons () {
1551+ add_theme_support ( 'amp ' );
1552+ $ this ->go_to ( '/ ' );
15351553 require_once ABSPATH . WPINC . '/class-wp-admin-bar.php ' ;
15361554
15371555 global $ wp_admin_bar ;
15381556 $ wp_admin_bar = new WP_Admin_Bar ();
15391557 $ wp_admin_bar ->initialize ();
15401558 AMP_Theme_Support::init_admin_bar ();
1559+ AMP_Theme_Support::add_hooks ();
15411560
15421561 // Enqueued directly.
15431562 wp_enqueue_style ( 'dashicons ' );
@@ -1555,15 +1574,18 @@ public function test_init_admin_bar_for_directly_enqueued_dashicons() {
15551574 * Test init_admin_bar to ensure dashicons are not added to dev mode when indirectly enqueued.
15561575 *
15571576 * @covers \AMP_Theme_Support::init_admin_bar()
1558- * @covers \AMP_Theme_Support::filter_admin_bar_style_loader_tag ()
1577+ * @covers \AMP_Theme_Support::filter_style_loader_tag_for_dev_mode ()
15591578 */
15601579 public function test_init_admin_bar_for_indirectly_enqueued_dashicons () {
1580+ add_theme_support ( 'amp ' );
1581+ $ this ->go_to ( '/ ' );
15611582 require_once ABSPATH . WPINC . '/class-wp-admin-bar.php ' ;
15621583
15631584 global $ wp_admin_bar ;
15641585 $ wp_admin_bar = new WP_Admin_Bar ();
15651586 $ wp_admin_bar ->initialize ();
15661587 AMP_Theme_Support::init_admin_bar ();
1588+ AMP_Theme_Support::add_hooks ();
15671589
15681590 // Enqueued indirectly.
15691591 wp_enqueue_style ( 'my-font-pack ' , 'https://example.com/fonts ' , [ 'dashicons ' ], '0.1 ' );
0 commit comments