Changeset 56687 for trunk/tests/phpunit/tests/dependencies/scripts.php
- Timestamp:
- 09/25/2023 09:03:19 PM (20 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/dependencies/scripts.php
r56559 r56687 43 43 $this->wp_scripts_print_translations_output = <<<JS 44 44 <script type='text/javascript' id='__HANDLE__-js-translations'> 45 /* <![CDATA[ */ 45 46 ( function( domain, translations ) { 46 47 var localeData = translations.locale_data[ domain ] || translations.locale_data.messages; … … 48 49 wp.i18n.setLocaleData( localeData, domain ); 49 50 } )( "__DOMAIN__", __JSON_TRANSLATIONS__ ); 51 /* ]]> */ 50 52 </script> 51 53 JS; … … 78 80 $expected .= "<script type='text/javascript' src='http://example.com' id='empty-deps-null-version-js'></script>\n"; 79 81 80 $this->assert Same( $expected, get_echo( 'wp_print_scripts' ) );82 $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); 81 83 82 84 // No scripts left to print. … … 119 121 $expected = "<script type='text/javascript' src='http://example.org/ms-isa-1.js' id='ms-isa-1-js' data-wp-strategy='{$strategy}'></script>\n"; 120 122 $expected .= wp_get_inline_script_tag( 121 "console.log(\"after one\");\n",123 'console.log("after one");', 122 124 array( 123 125 'id' => 'ms-isa-1-js-after', 124 126 ) 125 127 ); 126 $this->assert Same( $expected, $output, 'Inline scripts in the "after" position, that are attached to a deferred main script, are failing to print/execute.' );128 $this->assertEqualMarkup( $expected, $output, 'Inline scripts in the "after" position, that are attached to a deferred main script, are failing to print/execute.' ); 127 129 } 128 130 … … 147 149 $expected = "<script type='text/javascript' src='http://example.org/ms-insa-3.js' id='ms-insa-3-js'></script>\n"; 148 150 $expected .= wp_get_inline_script_tag( 149 "console.log(\"after one\");\n",151 'console.log("after one");', 150 152 array( 151 153 'id' => 'ms-insa-3-js-after', … … 153 155 ); 154 156 155 $this->assert Same( $expected, $output, 'Inline scripts in the "after" position, that are attached to a blocking main script, are failing to print/execute.' );157 $this->assertEqualMarkup( $expected, $output, 'Inline scripts in the "after" position, that are attached to a blocking main script, are failing to print/execute.' ); 156 158 } 157 159 … … 181 183 182 184 $expected = wp_get_inline_script_tag( 183 "console.log(\"before first\");\n",185 'console.log("before first");', 184 186 array( 185 187 'id' => 'ds-i1-1-js-before', … … 190 192 $expected .= "<script type='text/javascript' src='http://example.org/ds-i1-3.js' id='ds-i1-3-js' $strategy data-wp-strategy='{$strategy}'></script>\n"; 191 193 $expected .= wp_get_inline_script_tag( 192 "console.log(\"before last\");\n",194 'console.log("before last");', 193 195 array( 194 196 'id' => 'ms-i1-1-js-before', … … 198 200 $expected .= "<script type='text/javascript' src='http://example.org/ms-i1-1.js' id='ms-i1-1-js' {$strategy} data-wp-strategy='{$strategy}'></script>\n"; 199 201 200 $this->assert Same( $expected, $output, 'Inline scripts in the "before" position, that are attached to a deferred main script, are failing to print/execute.' );202 $this->assertEqualMarkup( $expected, $output, 'Inline scripts in the "before" position, that are attached to a deferred main script, are failing to print/execute.' ); 201 203 } 202 204 … … 216 218 $output = get_echo( 'wp_print_scripts' ); 217 219 $expected = "<script type='text/javascript' src='/main-script-a1.js' id='main-script-a1-js' async data-wp-strategy='async'></script>\n"; 218 $this->assert Same( $expected, $output, 'Scripts enqueued with an async loading strategy are failing to have the async attribute applied to the script handle when being printed.' );220 $this->assertEqualMarkup( $expected, $output, 'Scripts enqueued with an async loading strategy are failing to have the async attribute applied to the script handle when being printed.' ); 219 221 } 220 222 … … 236 238 wp_enqueue_script( 'dependency-script-a2', '/dependency-script-a2.js', array(), null ); 237 239 wp_enqueue_script( 'main-script-a2', '/main-script-a2.js', array( 'dependency-script-a2' ), null, compact( 'strategy' ) ); 238 $output = get_echo( 'wp_print_scripts' ); 239 $expected = "<script type='text/javascript' src='/main-script-a2.js' id='main-script-a2-js' {$strategy} data-wp-strategy='{$strategy}'></script>"; 240 $this->assertStringContainsString( $expected, $output, 'Dependents of a blocking dependency are free to have any strategy.' ); 240 $output = get_echo( 'wp_print_scripts' ); 241 $expected = "<script id='dependency-script-a2-js' src='/dependency-script-a2.js'></script>\n"; 242 $expected .= "<script type='text/javascript' src='/main-script-a2.js' id='main-script-a2-js' {$strategy} data-wp-strategy='{$strategy}'></script>"; 243 $this->assertEqualMarkup( $expected, $output, 'Dependents of a blocking dependency are free to have any strategy.' ); 241 244 } 242 245 … … 258 261 wp_enqueue_script( 'dependent-script-a3', '/dependent-script-a3.js', array( 'main-script-a3' ), null ); 259 262 $output = get_echo( 'wp_print_scripts' ); 260 $expected = "<script type='text/javascript' src='/main-script-a3.js' id='main-script-a3-js' data-wp-strategy='{$strategy}'></script>";263 $expected = str_replace( "'", '"', "<script type='text/javascript' src='/main-script-a3.js' id='main-script-a3-js' data-wp-strategy='{$strategy}'></script>" ); 261 264 $this->assertStringContainsString( $expected, $output, 'Blocking dependents must force delayed dependencies to become blocking.' ); 262 265 } … … 276 279 */ 277 280 public function test_delayed_dependent_with_blocking_dependency_not_enqueued( $strategy ) { 281 $this->add_html5_script_theme_support(); 278 282 wp_enqueue_script( 'main-script-a4', '/main-script-a4.js', array(), null, compact( 'strategy' ) ); 279 283 // This dependent is registered but not enqueued, so it should not factor into the eligible loading strategy. 280 284 wp_register_script( 'dependent-script-a4', '/dependent-script-a4.js', array( 'main-script-a4' ), null ); 281 285 $output = get_echo( 'wp_print_scripts' ); 282 $expected = "<script type='text/javascript' src='/main-script-a4.js' id='main-script-a4-js' {$strategy} data-wp-strategy='{$strategy}'></script>";286 $expected = str_replace( "'", '"', "<script src='/main-script-a4.js' id='main-script-a4-js' {$strategy} data-wp-strategy='{$strategy}'></script>" ); 283 287 $this->assertStringContainsString( $expected, $output, 'Only enqueued dependents should affect the eligible strategy.' ); 284 288 } … … 965 969 */ 966 970 public function test_loading_strategy_with_defer_having_no_dependents_nor_dependencies() { 971 $this->add_html5_script_theme_support(); 967 972 wp_enqueue_script( 'main-script-d1', 'http://example.com/main-script-d1.js', array(), null, array( 'strategy' => 'defer' ) ); 968 973 $output = get_echo( 'wp_print_scripts' ); 969 $expected = "<script type='text/javascript' src='http://example.com/main-script-d1.js' id='main-script-d1-js' defer data-wp-strategy='defer'></script>\n";974 $expected = str_replace( "'", '"', "<script src='http://example.com/main-script-d1.js' id='main-script-d1-js' defer data-wp-strategy='defer'></script>\n" ); 970 975 $this->assertStringContainsString( $expected, $output, 'Expected defer, as there is no dependent or dependency' ); 971 976 } … … 981 986 */ 982 987 public function test_loading_strategy_with_defer_dependent_and_varied_dependencies() { 988 $this->add_html5_script_theme_support(); 983 989 wp_enqueue_script( 'dependency-script-d2-1', 'http://example.com/dependency-script-d2-1.js', array(), null, array( 'strategy' => 'defer' ) ); 984 990 wp_enqueue_script( 'dependency-script-d2-2', 'http://example.com/dependency-script-d2-2.js', array(), null ); … … 986 992 wp_enqueue_script( 'main-script-d2', 'http://example.com/main-script-d2.js', array( 'dependency-script-d2-1', 'dependency-script-d2-3' ), null, array( 'strategy' => 'defer' ) ); 987 993 $output = get_echo( 'wp_print_scripts' ); 988 $expected = "<script type='text/javascript' src='http://example.com/main-script-d2.js' id='main-script-d2-js' defer data-wp-strategy='defer'></script>\n";994 $expected = '<script src="http://example.com/main-script-d2.js" id="main-script-d2-js" defer data-wp-strategy="defer"></script>'; 989 995 $this->assertStringContainsString( $expected, $output, 'Expected defer, as all dependencies are either deferred or blocking' ); 990 996 } … … 1000 1006 */ 1001 1007 public function test_loading_strategy_with_all_defer_dependencies() { 1008 $this->add_html5_script_theme_support(); 1002 1009 wp_enqueue_script( 'main-script-d3', 'http://example.com/main-script-d3.js', array(), null, array( 'strategy' => 'defer' ) ); 1003 1010 wp_enqueue_script( 'dependent-script-d3-1', 'http://example.com/dependent-script-d3-1.js', array( 'main-script-d3' ), null, array( 'strategy' => 'defer' ) ); … … 1005 1012 wp_enqueue_script( 'dependent-script-d3-3', 'http://example.com/dependent-script-d3-3.js', array( 'dependent-script-d3-2' ), null, array( 'strategy' => 'defer' ) ); 1006 1013 $output = get_echo( 'wp_print_scripts' ); 1007 $expected = "<script type='text/javascript' src='http://example.com/main-script-d3.js' id='main-script-d3-js' defer data-wp-strategy='defer'></script>\n";1014 $expected = '<script src="http://example.com/main-script-d3.js" id="main-script-d3-js" defer data-wp-strategy="defer"></script>'; 1008 1015 $this->assertStringContainsString( $expected, $output, 'Expected defer, as all dependents have defer loading strategy' ); 1009 1016 } … … 1030 1037 $expected .= "<script type='text/javascript' src='/dependent-script-d4-3.js' id='dependent-script-d4-3-js' defer data-wp-strategy='defer'></script>\n"; 1031 1038 1032 $this->assert Same( $expected, $output, 'Scripts registered as defer but that have dependents that are async are expected to have said dependents deferred.' );1039 $this->assertEqualMarkup( $expected, $output, 'Scripts registered as defer but that have dependents that are async are expected to have said dependents deferred.' ); 1033 1040 } 1034 1041 … … 1050 1057 wp_enqueue_script( 'dependent-script-d4-3', '/dependent-script-d4-3.js', array( 'dependent-script-d4-2' ), null, array( 'strategy' => 'defer' ) ); 1051 1058 $output = get_echo( 'wp_print_scripts' ); 1052 $expected = "<script type='text/javascript' src='/main-script-d4.js' id='main-script-d4-js' data-wp-strategy='defer'></script>\n";1059 $expected = str_replace( "'", '"', "<script type='text/javascript' src='/main-script-d4.js' id='main-script-d4-js' data-wp-strategy='defer'></script>\n" ); 1053 1060 $this->assertStringContainsString( $expected, $output, 'Scripts registered as defer but that have all dependents with no strategy, should become blocking (no strategy).' ); 1054 1061 } … … 1068 1075 $output = get_echo( 'wp_print_scripts' ); 1069 1076 $expected = "<script type='text/javascript' src='/main-script-b1.js' id='main-script-b1-js'></script>\n"; 1077 $expected = str_replace( "'", '"', $expected ); 1070 1078 $this->assertSame( $expected, $output, 'Scripts registered with a "blocking" strategy, and who have no dependencies, should have no loading strategy attributes printed.' ); 1071 1079 … … 1074 1082 $output = get_echo( 'wp_print_scripts' ); 1075 1083 $expected = "<script type='text/javascript' src='/main-script-b2.js' id='main-script-b2-js'></script>\n"; 1084 $expected = str_replace( "'", '"', $expected ); 1076 1085 $this->assertSame( $expected, $output, 'Scripts registered with no strategy assigned, and who have no dependencies, should have no loading strategy attributes printed.' ); 1077 1086 } … … 1100 1109 $expected_header .= "<script type='text/javascript' src='/enqueue-header-new.js' id='enqueue-header-new-js'></script>\n"; 1101 1110 1102 $this->assert Same( $expected_header, $actual_header, 'Scripts registered/enqueued using the older $in_footer parameter or the newer $args parameter should have the same outcome.' );1111 $this->assertEqualMarkup( $expected_header, $actual_header, 'Scripts registered/enqueued using the older $in_footer parameter or the newer $args parameter should have the same outcome.' ); 1103 1112 $this->assertEmpty( $actual_footer, 'Expected footer to be empty since all scripts were for head.' ); 1104 1113 } … … 1128 1137 1129 1138 $this->assertEmpty( $actual_header, 'Expected header to be empty since all scripts targeted footer.' ); 1130 $this->assert Same( $expected_footer, $actual_footer, 'Scripts registered/enqueued using the older $in_footer parameter or the newer $args parameter should have the same outcome.' );1139 $this->assertEqualMarkup( $expected_footer, $actual_footer, 'Scripts registered/enqueued using the older $in_footer parameter or the newer $args parameter should have the same outcome.' ); 1131 1140 } 1132 1141 … … 1247 1256 wp_enqueue_script( 'invalid-strategy' ); 1248 1257 1249 $this->assert Same(1258 $this->assertEqualMarkup( 1250 1259 "<script type='text/javascript' src='/defaults.js' id='invalid-strategy-js'></script>\n", 1251 1260 get_echo( 'wp_print_scripts' ) … … 1272 1281 wp_enqueue_script( 'invalid-strategy' ); 1273 1282 1274 $this->assert Same(1283 $this->assertEqualMarkup( 1275 1284 "<script type='text/javascript' src='/defaults.js' id='invalid-strategy-js'></script>\n", 1276 1285 get_echo( 'wp_print_scripts' ) … … 1293 1302 wp_enqueue_script( 'invalid-strategy', '/defaults.js', array(), null, array( 'strategy' => 'random-strategy' ) ); 1294 1303 1295 $this->assert Same(1304 $this->assertEqualMarkup( 1296 1305 "<script type='text/javascript' src='/defaults.js' id='invalid-strategy-js'></script>\n", 1297 1306 get_echo( 'wp_print_scripts' ) … … 1331 1340 $expected .= "<script type='text/javascript' src='/main-script.js' id='main-defer-script-js' defer data-wp-strategy='defer'></script>\n"; 1332 1341 1333 $this->assert Same( $expected, $print_scripts, 'Scripts are being incorrectly concatenated when a main script is registered with a "defer" loading strategy. Deferred scripts should not be part of the script concat loading query.' );1342 $this->assertEqualMarkup( $expected, $print_scripts, 'Scripts are being incorrectly concatenated when a main script is registered with a "defer" loading strategy. Deferred scripts should not be part of the script concat loading query.' ); 1334 1343 } 1335 1344 … … 1366 1375 $expected .= "<script type='text/javascript' src='/main-script.js' id='main-async-script-1-js' async data-wp-strategy='async'></script>\n"; 1367 1376 1368 $this->assert Same( $expected, $print_scripts, 'Scripts are being incorrectly concatenated when a main script is registered with an "async" loading strategy. Async scripts should not be part of the script concat loading query.' );1377 $this->assertEqualMarkup( $expected, $print_scripts, 'Scripts are being incorrectly concatenated when a main script is registered with an "async" loading strategy. Async scripts should not be part of the script concat loading query.' ); 1369 1378 } 1370 1379 … … 1405 1414 $expected .= "<script type='text/javascript' src='/main-script.js' id='deferred-script-2-js' defer data-wp-strategy='defer'></script>\n"; 1406 1415 1407 $this->assert Same( $expected, $print_scripts, 'Scripts are being incorrectly concatenated when a main script is registered as deferred after other blocking scripts are registered. Deferred scripts should not be part of the script concat loader query string. ' );1416 $this->assertEqualMarkup( $expected, $print_scripts, 'Scripts are being incorrectly concatenated when a main script is registered as deferred after other blocking scripts are registered. Deferred scripts should not be part of the script concat loader query string. ' ); 1408 1417 } 1409 1418 … … 1413 1422 public function test_wp_enqueue_script_with_html5_support_does_not_contain_type_attribute() { 1414 1423 global $wp_version; 1415 add_theme_support( 'html5', array( 'script' ) );1416 1424 1417 1425 $GLOBALS['wp_scripts'] = new WP_Scripts(); … … 1422 1430 $expected = "<script src='http://example.com?ver={$wp_version}' id='empty-deps-no-version-js'></script>\n"; 1423 1431 1424 $this->assert Same( $expected, get_echo( 'wp_print_scripts' ) );1432 $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); 1425 1433 } 1426 1434 … … 1461 1469 1462 1470 // Go! 1463 $this->assert Same( $expected, get_echo( 'wp_print_scripts' ) );1471 $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); 1464 1472 1465 1473 // No scripts left to print. … … 1504 1512 1505 1513 // Go! 1506 $this->assert Same( $expected, get_echo( 'wp_print_scripts' ) );1514 $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); 1507 1515 1508 1516 // No scripts left to print. … … 1522 1530 1523 1531 // Go! 1524 $this->assert Same( $expected, get_echo( 'wp_print_scripts' ) );1532 $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); 1525 1533 1526 1534 // No scripts left to print. … … 1540 1548 $expected = "<!--[if lt IE 9]>\n<script type='text/javascript' id='test-conditional-with-data-js-extra'>\n/* <![CDATA[ */\ntesting\n/* ]]> */\n</script>\n<![endif]-->\n"; 1541 1549 $expected .= "<!--[if lt IE 9]>\n<script type='text/javascript' src='http://example.com' id='test-conditional-with-data-js'></script>\n<![endif]-->\n"; 1550 $expected = str_replace( "'", '"', $expected ); 1542 1551 1543 1552 // Go! 1544 $this->assert Same( $expected, get_echo( 'wp_print_scripts' ) );1553 $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); 1545 1554 1546 1555 // No scripts left to print. … … 1560 1569 1561 1570 // Go! 1562 $this->assert Same( $expected, get_echo( 'wp_print_scripts' ) );1571 $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); 1563 1572 1564 1573 // No scripts left to print. 1565 $this->assert Same( '', get_echo( 'wp_print_scripts' ) );1574 $this->assertEqualMarkup( '', get_echo( 'wp_print_scripts' ) ); 1566 1575 } 1567 1576 … … 1589 1598 wp_enqueue_script( 'handle-three' ); 1590 1599 1591 $this->assert Same( $expected, get_echo( 'wp_print_scripts' ) );1600 $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); 1592 1601 } 1593 1602 … … 1677 1686 $expected_footer = "<script type='text/javascript' src='/parent.js' id='parent-js'></script>\n"; 1678 1687 1679 $this->assert Same( $expected_header, $header, 'Expected same header markup.' );1680 $this->assert Same( $expected_footer, $footer, 'Expected same footer markup.' );1688 $this->assertEqualMarkup( $expected_header, $header, 'Expected same header markup.' ); 1689 $this->assertEqualMarkup( $expected_footer, $footer, 'Expected same footer markup.' ); 1681 1690 } 1682 1691 … … 1698 1707 $expected_footer .= "<script type='text/javascript' src='/parent.js' id='parent-js'></script>\n"; 1699 1708 1700 $this->assert Same( $expected_header, $header, 'Expected same header markup.' );1701 $this->assert Same( $expected_footer, $footer, 'Expected same footer markup.' );1709 $this->assertEqualMarkup( $expected_header, $header, 'Expected same header markup.' ); 1710 $this->assertEqualMarkup( $expected_footer, $footer, 'Expected same footer markup.' ); 1702 1711 } 1703 1712 … … 1729 1738 $expected_footer .= "<script type='text/javascript' src='/parent-footer.js' id='parent-footer-js'></script>\n"; 1730 1739 1731 $this->assert Same( $expected_header, $header, 'Expected same header markup.' );1732 $this->assert Same( $expected_footer, $footer, 'Expected same footer markup.' );1740 $this->assertEqualMarkup( $expected_header, $header, 'Expected same header markup.' ); 1741 $this->assertEqualMarkup( $expected_footer, $footer, 'Expected same footer markup.' ); 1733 1742 } 1734 1743 … … 1953 1962 $expected_localized .= "<script type='text/javascript' id='test-example-js-extra'>\n/* <![CDATA[ */\nvar testExample = {\"foo\":\"bar\"};\n/* ]]> */\n</script>\n"; 1954 1963 $expected_localized .= "<![endif]-->\n"; 1964 $expected_localized = str_replace( "'", '"', $expected_localized ); 1955 1965 1956 1966 $expected = "<!--[if gte IE 9]>\n"; … … 1959 1969 $expected .= "<script type='text/javascript' id='test-example-js-after'>\nconsole.log(\"after\");\n</script>\n"; 1960 1970 $expected .= "<![endif]-->\n"; 1971 $expected = str_replace( "'", '"', $expected ); 1961 1972 1962 1973 wp_enqueue_script( 'test-example', 'example.com', array(), null ); … … 2125 2136 $print_scripts = $this->getActualOutput(); 2126 2137 2127 $tail = substr( $print_scripts, strrpos( $print_scripts, "<script type='text/javascript' src='/customize-dependency.js' id='customize-dependency-js'>" ) ); 2138 $tail = substr( $print_scripts, strrpos( $print_scripts, '<script type="text/javascript" src="/customize-dependency.js" id="customize-dependency-js">' ) ); 2139 2128 2140 $this->assertEqualMarkup( $expected_tail, $tail ); 2129 2141 } … … 2305 2317 $expected .= "<script type='text/javascript' src='/wp-includes/js/script.js' id='test-example-js'></script>\n"; 2306 2318 2307 $this->assert SameIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );2319 $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); 2308 2320 } 2309 2321 … … 2332 2344 $expected .= "<script type='text/javascript' src='/wp-content/plugins/my-plugin/js/script.js' id='plugin-example-js'></script>\n"; 2333 2345 2334 $this->assert SameIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );2346 $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); 2335 2347 } 2336 2348 … … 2359 2371 $expected .= "<script type='text/javascript' src='/wp-content/themes/my-theme/js/script.js' id='theme-example-js'></script>\n"; 2360 2372 2361 $this->assert SameIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );2373 $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); 2362 2374 } 2363 2375 … … 2386 2398 $expected .= "<script type='text/javascript' src='/wp-admin/js/script.js' id='script-handle-js'></script>\n"; 2387 2399 2388 $this->assert SameIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );2400 $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); 2389 2401 } 2390 2402 … … 2416 2428 $expected .= "<script type='text/javascript' src='/wp-admin/js/script.js' id='test-example-js'></script>\n"; 2417 2429 2418 $this->assert SameIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );2430 $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); 2419 2431 } 2420 2432 … … 2445 2457 $expected .= "<script type='text/javascript' src='/wp-includes/js/script.js' id='test-example-js'></script>\n"; 2446 2458 2447 $this->assert SameIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );2459 $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); 2448 2460 } 2449 2461 … … 2475 2487 $expected .= "<script type='text/javascript' src='/wp-includes/js/script2.js' id='test-example-js'></script>\n"; 2476 2488 2477 $this->assert SameIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );2489 $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); 2478 2490 } 2479 2491 … … 2864 2876 $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n"; 2865 2877 2866 $this->assert Same( $expected, get_echo( 'wp_print_scripts' ) );2878 $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); 2867 2879 } 2868 2880 … … 2929 2941 $expected .= "<script type='text/javascript' src='/default/common.js' id='common-js'></script>\n"; 2930 2942 2931 $this->assert Same( $expected, $print_scripts );2943 $this->assertEqualMarkup( $expected, $print_scripts ); 2932 2944 } 2933 2945 … … 2968 2980 * 2969 2981 * @param string $markup Markup. 2970 * @return DOM Element Body element wrapping supplied markup fragment.2982 * @return DOMDocument Document containing the normalized markup fragment. 2971 2983 */ 2972 2984 protected function parse_markup_fragment( $markup ) { … … 2986 2998 } 2987 2999 2988 return $ body;2989 } 2990 2991 /** 2992 * Assert markup is equal .3000 return $dom; 3001 } 3002 3003 /** 3004 * Assert markup is equal after normalizing script tags. 2993 3005 * 2994 3006 * @param string $expected Expected markup. … … 2997 3009 */ 2998 3010 protected function assertEqualMarkup( $expected, $actual, $message = '' ) { 3011 $expected_dom = $this->parse_markup_fragment( $expected ); 3012 $actual_dom = $this->parse_markup_fragment( $actual ); 3013 foreach ( array( $expected_dom, $actual_dom ) as $dom ) { 3014 $xpath = new DOMXPath( $dom ); 3015 /** @var DOMElement $script */ 3016 3017 // Normalize type attribute. When missing, it defaults to text/javascript. 3018 foreach ( $xpath->query( '//script[ not( @type ) ]' ) as $script ) { 3019 $script->setAttribute( 'type', 'text/javascript' ); 3020 } 3021 3022 // Normalize script contents to remove CDATA wrapper. 3023 foreach ( $xpath->query( '//script[ contains( text(), "<![CDATA[" ) ]' ) as $script ) { 3024 $script->textContent = str_replace( 3025 array( 3026 "/* <![CDATA[ */\n", 3027 "\n/* ]]> */", 3028 ), 3029 '', 3030 $script->textContent 3031 ); 3032 } 3033 3034 // Normalize XHTML-compatible boolean attributes to HTML5 ones. 3035 foreach ( array( 'async', 'defer' ) as $attribute ) { 3036 foreach ( iterator_to_array( $xpath->query( "//script[ @{$attribute} = '{$attribute}' ]" ) ) as $script ) { 3037 $script->removeAttribute( $attribute ); 3038 $script->setAttributeNode( $dom->createAttribute( $attribute ) ); 3039 } 3040 } 3041 } 3042 2999 3043 $this->assertEquals( 3000 $ this->parse_markup_fragment( $expected),3001 $ this->parse_markup_fragment( $actual),3044 $expected_dom->getElementsByTagName( 'body' )->item( 0 ), 3045 $actual_dom->getElementsByTagName( 'body' )->item( 0 ), 3002 3046 $message 3003 3047 ); 3004 3048 } 3049 3050 /** 3051 * Adds html5 script theme support. 3052 */ 3053 protected function add_html5_script_theme_support() { 3054 add_theme_support( 'html5', array( 'script' ) ); 3055 } 3005 3056 }
Note: See TracChangeset
for help on using the changeset viewer.