Changeset 60719 for trunk/tests/phpunit/tests/dependencies/scripts.php
- Timestamp:
- 09/08/2025 11:25:40 AM (2 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/dependencies/scripts.php
r60704 r60719 18 18 19 19 /** 20 * @var bool 21 */ 22 protected $old_concatenate_scripts; 23 24 /** 20 25 * @var WP_Styles 21 26 */ … … 33 38 public function set_up() { 34 39 parent::set_up(); 35 $this->old_wp_scripts = isset( $GLOBALS['wp_scripts'] ) ? $GLOBALS['wp_scripts'] : null; 36 $this->old_wp_styles = isset( $GLOBALS['wp_styles'] ) ? $GLOBALS['wp_styles'] : null; 40 $this->old_wp_scripts = isset( $GLOBALS['wp_scripts'] ) ? $GLOBALS['wp_scripts'] : null; 41 $this->old_wp_styles = isset( $GLOBALS['wp_styles'] ) ? $GLOBALS['wp_styles'] : null; 42 $this->old_concatenate_scripts = isset( $GLOBALS['concatenate_scripts'] ) ? $GLOBALS['concatenate_scripts'] : null; 37 43 remove_action( 'wp_default_scripts', 'wp_default_scripts' ); 38 44 remove_action( 'wp_default_scripts', 'wp_default_packages' ); … … 49 55 wp.i18n.setLocaleData( localeData, domain ); 50 56 } )( "__DOMAIN__", __JSON_TRANSLATIONS__ ); 57 //# sourceURL=__HANDLE__-js-translations 51 58 /* ]]> */ 52 59 </script> … … 56 63 57 64 public function tear_down() { 58 $GLOBALS['wp_scripts'] = $this->old_wp_scripts; 59 $GLOBALS['wp_styles'] = $this->old_wp_styles; 65 $GLOBALS['wp_scripts'] = $this->old_wp_scripts; 66 $GLOBALS['wp_styles'] = $this->old_wp_styles; 67 $GLOBALS['concatenate_scripts'] = $this->old_concatenate_scripts; 60 68 add_action( 'wp_default_scripts', 'wp_default_scripts' ); 61 69 parent::tear_down(); … … 117 125 public function test_after_inline_script_with_delayed_main_script( $strategy ) { 118 126 wp_enqueue_script( 'ms-isa-1', 'http://example.org/ms-isa-1.js', array(), null, compact( 'strategy' ) ); 119 wp_add_inline_script( 'ms-isa-1', 'console.log( "after one");', 'after' );127 wp_add_inline_script( 'ms-isa-1', 'console.log(\'after one\');', 'after' ); 120 128 $output = get_echo( 'wp_print_scripts' ); 121 129 $expected = "<script type='text/javascript' src='http://example.org/ms-isa-1.js' id='ms-isa-1-js' data-wp-strategy='{$strategy}'></script>\n"; 122 130 $expected .= wp_get_inline_script_tag( 123 'console.log("after one");',131 "console.log('after one');\n//# sourceURL=ms-isa-1-js-after", 124 132 array( 125 133 'id' => 'ms-isa-1-js-after', … … 144 152 public function test_after_inline_script_with_blocking_main_script() { 145 153 wp_enqueue_script( 'ms-insa-3', 'http://example.org/ms-insa-3.js', array(), null ); 146 wp_add_inline_script( 'ms-insa-3', 'console.log( "after one");', 'after' );154 wp_add_inline_script( 'ms-insa-3', 'console.log(\'after one\');', 'after' ); 147 155 $output = get_echo( 'wp_print_scripts' ); 148 156 149 157 $expected = "<script type='text/javascript' src='http://example.org/ms-insa-3.js' id='ms-insa-3-js'></script>\n"; 150 158 $expected .= wp_get_inline_script_tag( 151 'console.log("after one");',159 "console.log('after one');\n//# sourceURL=ms-insa-3-js-after", 152 160 array( 153 161 'id' => 'ms-insa-3-js-after', … … 175 183 public function test_before_inline_scripts_with_delayed_main_script( $strategy ) { 176 184 wp_enqueue_script( 'ds-i1-1', 'http://example.org/ds-i1-1.js', array(), null, compact( 'strategy' ) ); 177 wp_add_inline_script( 'ds-i1-1', 'console.log( "before first");', 'before' );185 wp_add_inline_script( 'ds-i1-1', 'console.log(\'before first\');', 'before' ); 178 186 wp_enqueue_script( 'ds-i1-2', 'http://example.org/ds-i1-2.js', array(), null, compact( 'strategy' ) ); 179 187 wp_enqueue_script( 'ds-i1-3', 'http://example.org/ds-i1-3.js', array(), null, compact( 'strategy' ) ); 180 188 wp_enqueue_script( 'ms-i1-1', 'http://example.org/ms-i1-1.js', array( 'ds-i1-1', 'ds-i1-2', 'ds-i1-3' ), null, compact( 'strategy' ) ); 181 wp_add_inline_script( 'ms-i1-1', 'console.log( "before last");', 'before' );189 wp_add_inline_script( 'ms-i1-1', 'console.log(\'before last\');', 'before' ); 182 190 $output = get_echo( 'wp_print_scripts' ); 183 191 184 192 $expected = wp_get_inline_script_tag( 185 'console.log("before first");',193 "console.log('before first');\n//# sourceURL=ds-i1-1-js-before", 186 194 array( 187 195 'id' => 'ds-i1-1-js-before', … … 192 200 $expected .= "<script type='text/javascript' src='http://example.org/ds-i1-3.js' id='ds-i1-3-js' {$strategy}='{$strategy}' data-wp-strategy='{$strategy}'></script>\n"; 193 201 $expected .= wp_get_inline_script_tag( 194 'console.log("before last");',202 "console.log('before last');\n//# sourceURL=ms-i1-1-js-before", 195 203 array( 196 204 'id' => 'ms-i1-1-js-before', … … 514 522 /* <![CDATA[ */ 515 523 scriptEventLog.push( "blocking-not-async-without-dependency: before inline" ) 524 //# sourceURL=blocking-not-async-without-dependency-js-before 516 525 /* ]]> */ 517 526 </script> … … 520 529 /* <![CDATA[ */ 521 530 scriptEventLog.push( "blocking-not-async-without-dependency: after inline" ) 531 //# sourceURL=blocking-not-async-without-dependency-js-after 522 532 /* ]]> */ 523 533 </script> … … 525 535 /* <![CDATA[ */ 526 536 scriptEventLog.push( "async-with-blocking-dependency: before inline" ) 537 //# sourceURL=async-with-blocking-dependency-js-before 527 538 /* ]]> */ 528 539 </script> … … 531 542 /* <![CDATA[ */ 532 543 scriptEventLog.push( "async-with-blocking-dependency: after inline" ) 544 //# sourceURL=async-with-blocking-dependency-js-after 533 545 /* ]]> */ 534 546 </script> … … 559 571 /* <![CDATA[ */ 560 572 scriptEventLog.push( "async-no-dependency: before inline" ) 573 //# sourceURL=async-no-dependency-js-before 561 574 /* ]]> */ 562 575 </script> … … 565 578 /* <![CDATA[ */ 566 579 scriptEventLog.push( "async-no-dependency: after inline" ) 580 //# sourceURL=async-no-dependency-js-after 567 581 /* ]]> */ 568 582 </script> … … 570 584 /* <![CDATA[ */ 571 585 scriptEventLog.push( "async-one-async-dependency: before inline" ) 586 //# sourceURL=async-one-async-dependency-js-before 572 587 /* ]]> */ 573 588 </script> … … 576 591 /* <![CDATA[ */ 577 592 scriptEventLog.push( "async-one-async-dependency: after inline" ) 593 //# sourceURL=async-one-async-dependency-js-after 578 594 /* ]]> */ 579 595 </script> … … 581 597 /* <![CDATA[ */ 582 598 scriptEventLog.push( "async-two-async-dependencies: before inline" ) 599 //# sourceURL=async-two-async-dependencies-js-before 583 600 /* ]]> */ 584 601 </script> … … 587 604 /* <![CDATA[ */ 588 605 scriptEventLog.push( "async-two-async-dependencies: after inline" ) 606 //# sourceURL=async-two-async-dependencies-js-after 589 607 /* ]]> */ 590 608 </script> … … 607 625 /* <![CDATA[ */ 608 626 scriptEventLog.push( "async-with-blocking-dependent: before inline" ) 627 //# sourceURL=async-with-blocking-dependent-js-before 609 628 /* ]]> */ 610 629 </script> … … 613 632 /* <![CDATA[ */ 614 633 scriptEventLog.push( "async-with-blocking-dependent: after inline" ) 634 //# sourceURL=async-with-blocking-dependent-js-after 615 635 /* ]]> */ 616 636 </script> … … 618 638 /* <![CDATA[ */ 619 639 scriptEventLog.push( "blocking-dependent-of-async: before inline" ) 640 //# sourceURL=blocking-dependent-of-async-js-before 620 641 /* ]]> */ 621 642 </script> … … 624 645 /* <![CDATA[ */ 625 646 scriptEventLog.push( "blocking-dependent-of-async: after inline" ) 647 //# sourceURL=blocking-dependent-of-async-js-after 626 648 /* ]]> */ 627 649 </script> … … 644 666 /* <![CDATA[ */ 645 667 scriptEventLog.push( "async-with-defer-dependent: before inline" ) 668 //# sourceURL=async-with-defer-dependent-js-before 646 669 /* ]]> */ 647 670 </script> … … 650 673 /* <![CDATA[ */ 651 674 scriptEventLog.push( "async-with-defer-dependent: after inline" ) 675 //# sourceURL=async-with-defer-dependent-js-after 652 676 /* ]]> */ 653 677 </script> … … 655 679 /* <![CDATA[ */ 656 680 scriptEventLog.push( "defer-dependent-of-async: before inline" ) 681 //# sourceURL=defer-dependent-of-async-js-before 657 682 /* ]]> */ 658 683 </script> … … 661 686 /* <![CDATA[ */ 662 687 scriptEventLog.push( "defer-dependent-of-async: after inline" ) 688 //# sourceURL=defer-dependent-of-async-js-after 663 689 /* ]]> */ 664 690 </script> … … 684 710 /* <![CDATA[ */ 685 711 scriptEventLog.push( "blocking-bundle-of-none: before inline" ) 712 //# sourceURL=blocking-bundle-of-none-js-before 686 713 /* ]]> */ 687 714 </script> … … 689 716 /* <![CDATA[ */ 690 717 scriptEventLog.push( "blocking-bundle-of-none: after inline" ) 718 //# sourceURL=blocking-bundle-of-none-js-after 691 719 /* ]]> */ 692 720 </script> … … 694 722 /* <![CDATA[ */ 695 723 scriptEventLog.push( "defer-dependent-of-blocking-bundle-of-none: before inline" ) 724 //# sourceURL=defer-dependent-of-blocking-bundle-of-none-js-before 696 725 /* ]]> */ 697 726 </script> … … 700 729 /* <![CDATA[ */ 701 730 scriptEventLog.push( "defer-dependent-of-blocking-bundle-of-none: after inline" ) 731 //# sourceURL=defer-dependent-of-blocking-bundle-of-none-js-after 702 732 /* ]]> */ 703 733 </script> … … 726 756 /* <![CDATA[ */ 727 757 scriptEventLog.push( "blocking-bundle-member-one: before inline" ) 758 //# sourceURL=blocking-bundle-member-one-js-before 728 759 /* ]]> */ 729 760 </script> … … 732 763 /* <![CDATA[ */ 733 764 scriptEventLog.push( "blocking-bundle-member-one: after inline" ) 765 //# sourceURL=blocking-bundle-member-one-js-after 734 766 /* ]]> */ 735 767 </script> … … 737 769 /* <![CDATA[ */ 738 770 scriptEventLog.push( "blocking-bundle-member-two: before inline" ) 771 //# sourceURL=blocking-bundle-member-two-js-before 739 772 /* ]]> */ 740 773 </script> … … 743 776 /* <![CDATA[ */ 744 777 scriptEventLog.push( "blocking-bundle-member-two: after inline" ) 778 //# sourceURL=blocking-bundle-member-two-js-after 745 779 /* ]]> */ 746 780 </script> … … 748 782 /* <![CDATA[ */ 749 783 scriptEventLog.push( "defer-dependent-of-blocking-bundle-of-two: before inline" ) 784 //# sourceURL=defer-dependent-of-blocking-bundle-of-two-js-before 750 785 /* ]]> */ 751 786 </script> … … 754 789 /* <![CDATA[ */ 755 790 scriptEventLog.push( "defer-dependent-of-blocking-bundle-of-two: after inline" ) 791 //# sourceURL=defer-dependent-of-blocking-bundle-of-two-js-after 756 792 /* ]]> */ 757 793 </script> … … 779 815 /* <![CDATA[ */ 780 816 scriptEventLog.push( "defer-bundle-of-none: before inline" ) 817 //# sourceURL=defer-bundle-of-none-js-before 781 818 /* ]]> */ 782 819 </script> … … 784 821 /* <![CDATA[ */ 785 822 scriptEventLog.push( "defer-bundle-of-none: after inline" ) 823 //# sourceURL=defer-bundle-of-none-js-after 786 824 /* ]]> */ 787 825 </script> … … 789 827 /* <![CDATA[ */ 790 828 scriptEventLog.push( "defer-dependent-of-defer-bundle-of-none: before inline" ) 829 //# sourceURL=defer-dependent-of-defer-bundle-of-none-js-before 791 830 /* ]]> */ 792 831 </script> … … 795 834 /* <![CDATA[ */ 796 835 scriptEventLog.push( "defer-dependent-of-defer-bundle-of-none: after inline" ) 836 //# sourceURL=defer-dependent-of-defer-bundle-of-none-js-after 797 837 /* ]]> */ 798 838 </script> … … 818 858 /* <![CDATA[ */ 819 859 scriptEventLog.push( "blocking-dependency-with-defer-following-dependency: before inline" ) 860 //# sourceURL=blocking-dependency-with-defer-following-dependency-js-before 820 861 /* ]]> */ 821 862 </script> … … 824 865 /* <![CDATA[ */ 825 866 scriptEventLog.push( "blocking-dependency-with-defer-following-dependency: after inline" ) 867 //# sourceURL=blocking-dependency-with-defer-following-dependency-js-after 826 868 /* ]]> */ 827 869 </script> … … 829 871 /* <![CDATA[ */ 830 872 scriptEventLog.push( "defer-dependency-with-blocking-preceding-dependency: before inline" ) 873 //# sourceURL=defer-dependency-with-blocking-preceding-dependency-js-before 831 874 /* ]]> */ 832 875 </script> … … 835 878 /* <![CDATA[ */ 836 879 scriptEventLog.push( "defer-dependency-with-blocking-preceding-dependency: after inline" ) 880 //# sourceURL=defer-dependency-with-blocking-preceding-dependency-js-after 837 881 /* ]]> */ 838 882 </script> … … 840 884 /* <![CDATA[ */ 841 885 scriptEventLog.push( "defer-dependent-of-blocking-and-defer-dependencies: before inline" ) 886 //# sourceURL=defer-dependent-of-blocking-and-defer-dependencies-js-before 842 887 /* ]]> */ 843 888 </script> … … 846 891 /* <![CDATA[ */ 847 892 scriptEventLog.push( "defer-dependent-of-blocking-and-defer-dependencies: after inline" ) 893 //# sourceURL=defer-dependent-of-blocking-and-defer-dependencies-js-after 848 894 /* ]]> */ 849 895 </script> … … 869 915 /* <![CDATA[ */ 870 916 scriptEventLog.push( "defer-dependency-with-blocking-following-dependency: before inline" ) 917 //# sourceURL=defer-dependency-with-blocking-following-dependency-js-before 871 918 /* ]]> */ 872 919 </script> … … 875 922 /* <![CDATA[ */ 876 923 scriptEventLog.push( "defer-dependency-with-blocking-following-dependency: after inline" ) 924 //# sourceURL=defer-dependency-with-blocking-following-dependency-js-after 877 925 /* ]]> */ 878 926 </script> … … 880 928 /* <![CDATA[ */ 881 929 scriptEventLog.push( "blocking-dependency-with-defer-preceding-dependency: before inline" ) 930 //# sourceURL=blocking-dependency-with-defer-preceding-dependency-js-before 882 931 /* ]]> */ 883 932 </script> … … 886 935 /* <![CDATA[ */ 887 936 scriptEventLog.push( "blocking-dependency-with-defer-preceding-dependency: after inline" ) 937 //# sourceURL=blocking-dependency-with-defer-preceding-dependency-js-after 888 938 /* ]]> */ 889 939 </script> … … 891 941 /* <![CDATA[ */ 892 942 scriptEventLog.push( "defer-dependent-of-defer-and-blocking-dependencies: before inline" ) 943 //# sourceURL=defer-dependent-of-defer-and-blocking-dependencies-js-before 893 944 /* ]]> */ 894 945 </script> … … 897 948 /* <![CDATA[ */ 898 949 scriptEventLog.push( "defer-dependent-of-defer-and-blocking-dependencies: after inline" ) 950 //# sourceURL=defer-dependent-of-defer-and-blocking-dependencies-js-after 899 951 /* ]]> */ 900 952 </script> … … 917 969 /* <![CDATA[ */ 918 970 scriptEventLog.push( "defer-with-async-dependent: before inline" ) 971 //# sourceURL=defer-with-async-dependent-js-before 919 972 /* ]]> */ 920 973 </script> … … 923 976 /* <![CDATA[ */ 924 977 scriptEventLog.push( "defer-with-async-dependent: after inline" ) 978 //# sourceURL=defer-with-async-dependent-js-after 925 979 /* ]]> */ 926 980 </script> … … 928 982 /* <![CDATA[ */ 929 983 scriptEventLog.push( "async-dependent-of-defer: before inline" ) 984 //# sourceURL=async-dependent-of-defer-js-before 930 985 /* ]]> */ 931 986 </script> … … 934 989 /* <![CDATA[ */ 935 990 scriptEventLog.push( "async-dependent-of-defer: after inline" ) 991 //# sourceURL=async-dependent-of-defer-js-after 936 992 /* ]]> */ 937 993 </script> … … 950 1006 /* <![CDATA[ */ 951 1007 scriptEventLog.push( "defer-with-before-inline: before inline" ) 1008 //# sourceURL=defer-with-before-inline-js-before 952 1009 /* ]]> */ 953 1010 </script> … … 968 1025 /* <![CDATA[ */ 969 1026 scriptEventLog.push( "defer-with-after-inline: after inline" ) 1027 //# sourceURL=defer-with-after-inline-js-after 970 1028 /* ]]> */ 971 1029 </script> … … 1015 1073 /* <![CDATA[ */ 1016 1074 scriptEventLog.push( "defer-dependent-of-nested-aliases: before inline" ) 1075 //# sourceURL=defer-dependent-of-nested-aliases-js-before 1017 1076 /* ]]> */ 1018 1077 </script> … … 1021 1080 /* <![CDATA[ */ 1022 1081 scriptEventLog.push( "defer-dependent-of-nested-aliases: after inline" ) 1082 //# sourceURL=defer-dependent-of-nested-aliases-js-after 1023 1083 /* ]]> */ 1024 1084 </script> … … 1562 1622 global $wp_scripts, $concatenate_scripts, $wp_version; 1563 1623 1564 $old_value = $concatenate_scripts;1565 1624 $concatenate_scripts = true; 1566 1625 … … 1576 1635 $print_scripts = get_echo( '_print_scripts' ); 1577 1636 1578 // Reset global before asserting.1579 $concatenate_scripts = $old_value;1580 1581 1637 $expected = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5Bchunk_0%5D=one-concat-dep,two-concat-dep,three-concat-dep&ver={$wp_version}'></script>\n"; 1582 1638 $expected .= "<script type='text/javascript' src='/main-script.js' id='main-defer-script-js' defer='defer' data-wp-strategy='defer'></script>\n"; … … 1597 1653 global $wp_scripts, $concatenate_scripts, $wp_version; 1598 1654 1599 $old_value = $concatenate_scripts;1600 1655 $concatenate_scripts = true; 1601 1656 … … 1611 1666 $print_scripts = get_echo( '_print_scripts' ); 1612 1667 1613 // Reset global before asserting.1614 $concatenate_scripts = $old_value;1615 1616 1668 $expected = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5Bchunk_0%5D=one-concat-dep-1,two-concat-dep-1,three-concat-dep-1&ver={$wp_version}'></script>\n"; 1617 1669 $expected .= "<script type='text/javascript' src='/main-script.js' id='main-async-script-1-js' async='async' data-wp-strategy='async'></script>\n"; … … 1633 1685 global $wp_scripts, $concatenate_scripts, $wp_version; 1634 1686 1635 $old_value = $concatenate_scripts;1636 1687 $concatenate_scripts = true; 1637 1688 … … 1650 1701 $print_scripts = get_echo( '_print_scripts' ); 1651 1702 1652 // Reset global before asserting.1653 $concatenate_scripts = $old_value;1654 1655 1703 $expected = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5Bchunk_0%5D=one-concat-dep-2,two-concat-dep-2,three-concat-dep-2,four-concat-dep-2,five-concat-dep-2,six-concat-dep-2&ver={$wp_version}'></script>\n"; 1656 1704 $expected .= "<script type='text/javascript' src='/main-script.js' id='deferred-script-2-js' defer='defer' data-wp-strategy='defer'></script>\n"; … … 1752 1800 wp_enqueue_script( 'test-only-data', 'example.com', array(), null ); 1753 1801 wp_script_add_data( 'test-only-data', 'data', 'testing' ); 1754 $expected = "<script type='text/javascript' id='test-only-data-js-extra'>\n/* <![CDATA[ */\ntesting\n/ * ]]> */\n</script>\n";1802 $expected = "<script type='text/javascript' id='test-only-data-js-extra'>\n/* <![CDATA[ */\ntesting\n//# sourceURL=test-only-data-js-extra\n/* ]]> */\n</script>\n"; 1755 1803 $expected .= "<script type='text/javascript' src='http://example.com' id='test-only-data-js'></script>\n"; 1756 1804 … … 1790 1838 wp_script_add_data( 'test-conditional-with-data', 'data', 'testing' ); 1791 1839 wp_script_add_data( 'test-conditional-with-data', 'conditional', 'lt IE 9' ); 1792 $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";1840 $expected = "<!--[if lt IE 9]>\n<script type='text/javascript' id='test-conditional-with-data-js-extra'>\n/* <![CDATA[ */\ntesting\n//# sourceURL=test-conditional-with-data-js-extra\n/* ]]> */\n</script>\n<![endif]-->\n"; 1793 1841 $expected .= "<!--[if lt IE 9]>\n<script type='text/javascript' src='http://example.com' id='test-conditional-with-data-js'></script>\n<![endif]-->\n"; 1794 1842 $expected = str_replace( "'", '"', $expected ); … … 2014 2062 /* <![CDATA[ */ 2015 2063 console.log("before"); 2064 //# sourceURL=test-example-js-before 2016 2065 /* ]]> */ 2017 2066 </script> … … 2034 2083 /* <![CDATA[ */ 2035 2084 console.log("after"); 2085 //# sourceURL=test-example-js-after 2036 2086 /* ]]> */ 2037 2087 </script> … … 2049 2099 wp_add_inline_script( 'test-example', 'console.log("after");' ); 2050 2100 2051 $expected = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n/ * ]]> */\n</script>\n";2101 $expected = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n//# sourceURL=test-example-js-before\n/* ]]> */\n</script>\n"; 2052 2102 $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n"; 2053 $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n/ * ]]> */\n</script>\n";2103 $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=test-example-js-after\n/* ]]> */\n</script>\n"; 2054 2104 2055 2105 $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) ); … … 2064 2114 wp_add_inline_script( 'test-example', 'console.log("before");', 'before' ); 2065 2115 2066 $expected = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n/ * ]]> */\n</script>\n";2116 $expected = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n//# sourceURL=test-example-js-before\n/* ]]> */\n</script>\n"; 2067 2117 2068 2118 $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) ); … … 2077 2127 wp_add_inline_script( 'test-example', 'console.log("after");' ); 2078 2128 2079 $expected = "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n/ * ]]> */\n</script>\n";2129 $expected = "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=test-example-js-after\n/* ]]> */\n</script>\n"; 2080 2130 2081 2131 $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) ); … … 2091 2141 wp_add_inline_script( 'test-example', 'console.log("after");' ); 2092 2142 2093 $expected = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n/ * ]]> */\n</script>\n";2094 $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n/ * ]]> */\n</script>\n";2143 $expected = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n//# sourceURL=test-example-js-before\n/* ]]> */\n</script>\n"; 2144 $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=test-example-js-after\n/* ]]> */\n</script>\n"; 2095 2145 2096 2146 $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) ); … … 2107 2157 wp_add_inline_script( 'test-example', 'console.log("after");' ); 2108 2158 2109 $expected = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\nconsole.log(\"before\");\n/ * ]]> */\n</script>\n";2159 $expected = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\nconsole.log(\"before\");\n//# sourceURL=test-example-js-before\n/* ]]> */\n</script>\n"; 2110 2160 $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n"; 2111 $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\nconsole.log(\"after\");\n/ * ]]> */\n</script>\n";2161 $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\nconsole.log(\"after\");\n//# sourceURL=test-example-js-after\n/* ]]> */\n</script>\n"; 2112 2162 2113 2163 $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) ); … … 2123 2173 wp_add_inline_script( 'test-example', 'console.log("after");' ); 2124 2174 2125 $expected = "<script type='text/javascript' id='test-example-js-extra'>\n/* <![CDATA[ */\nvar testExample = {\"foo\":\"bar\"};\n/ * ]]> */\n</script>\n";2126 $expected .= "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n/ * ]]> */\n</script>\n";2175 $expected = "<script type='text/javascript' id='test-example-js-extra'>\n/* <![CDATA[ */\nvar testExample = {\"foo\":\"bar\"};\n//# sourceURL=test-example-js-extra\n/* ]]> */\n</script>\n"; 2176 $expected .= "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n//# sourceURL=test-example-js-before\n/* ]]> */\n</script>\n"; 2127 2177 $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n"; 2128 $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n/ * ]]> */\n</script>\n";2178 $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=test-example-js-after\n/* ]]> */\n</script>\n"; 2129 2179 2130 2180 $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) ); … … 2147 2197 wp_add_inline_script( 'two', 'console.log("before two");', 'before' ); 2148 2198 2149 $expected = "<script type='text/javascript' id='one-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before one\");\n/ * ]]> */\n</script>\n";2199 $expected = "<script type='text/javascript' id='one-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before one\");\n//# sourceURL=one-js-before\n/* ]]> */\n</script>\n"; 2150 2200 $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}one.js?ver={$wp_version}' id='one-js'></script>\n"; 2151 $expected .= "<script type='text/javascript' id='two-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before two\");\n/ * ]]> */\n</script>\n";2201 $expected .= "<script type='text/javascript' id='two-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before two\");\n//# sourceURL=two-js-before\n/* ]]> */\n</script>\n"; 2152 2202 $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}two.js?ver={$wp_version}' id='two-js'></script>\n"; 2153 2203 $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}three.js?ver={$wp_version}' id='three-js'></script>\n"; … … 2171 2221 wp_add_inline_script( 'one', 'console.log("before one");', 'before' ); 2172 2222 2173 $expected = "<script type='text/javascript' id='one-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before one\");\n/ * ]]> */\n</script>\n";2223 $expected = "<script type='text/javascript' id='one-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before one\");\n//# sourceURL=one-js-before\n/* ]]> */\n</script>\n"; 2174 2224 $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}one.js?ver={$wp_version}' id='one-js'></script>\n"; 2175 2225 $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}two.js?ver={$wp_version}' id='two-js'></script>\n"; … … 2198 2248 $expected = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5Bchunk_0%5D=one&ver={$wp_version}'></script>\n"; 2199 2249 $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}two.js?ver={$wp_version}' id='two-js'></script>\n"; 2200 $expected .= "<script type='text/javascript' id='two-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after two\");\n/ * ]]> */\n</script>\n";2250 $expected .= "<script type='text/javascript' id='two-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after two\");\n//# sourceURL=two-js-after\n/* ]]> */\n</script>\n"; 2201 2251 $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}three.js?ver={$wp_version}' id='three-js'></script>\n"; 2202 $expected .= "<script type='text/javascript' id='three-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after three\");\n/ * ]]> */\n</script>\n";2252 $expected .= "<script type='text/javascript' id='three-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after three\");\n//# sourceURL=three-js-after\n/* ]]> */\n</script>\n"; 2203 2253 $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}four.js?ver={$wp_version}' id='four-js'></script>\n"; 2204 2254 … … 2221 2271 2222 2272 $expected = "<!--[if gte IE 9]>\n"; 2223 $expected .= "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n/ * ]]> */\n</script>\n";2273 $expected .= "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n//# sourceURL=test-example-js-before\n/* ]]> */\n</script>\n"; 2224 2274 $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n"; 2225 $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n/ * ]]> */\n</script>\n";2275 $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=test-example-js-after\n/* ]]> */\n</script>\n"; 2226 2276 $expected .= "<![endif]-->\n"; 2227 2277 $expected = str_replace( "'", '"', $expected ); … … 2251 2301 $expected = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5Bchunk_0%5D=jquery-core,jquery-migrate&ver={$wp_version}'></script>\n"; 2252 2302 $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n"; 2253 $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n/ * ]]> */\n</script>\n";2303 $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=test-example-js-after\n/* ]]> */\n</script>\n"; 2254 2304 2255 2305 wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null ); … … 2276 2326 $expected .= "<!--[if gte IE 9]>\n"; 2277 2327 $expected .= "<script type=\"text/javascript\" src=\"http://example.com\" id=\"test-example-js\"></script>\n"; 2278 $expected .= "<script type=\"text/javascript\" id=\"test-example-js-after\">\n/* <![CDATA[ */\nconsole.log(\"after\");\n/ * ]]> */\n</script>\n";2328 $expected .= "<script type=\"text/javascript\" id=\"test-example-js-after\">\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=test-example-js-after\n/* ]]> */\n</script>\n"; 2279 2329 $expected .= "<![endif]-->\n"; 2280 2330 … … 2302 2352 2303 2353 $expected = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5Bchunk_0%5D=jquery-core,jquery-migrate&ver={$wp_version}'></script>\n"; 2304 $expected .= "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n/ * ]]> */\n</script>\n";2354 $expected .= "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n//# sourceURL=test-example-js-before\n/* ]]> */\n</script>\n"; 2305 2355 $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n"; 2306 2356 … … 2327 2377 2328 2378 $expected = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5Bchunk_0%5D=jquery-core,jquery-migrate,wp-dom-ready,wp-hooks&ver={$wp_version}'></script>\n"; 2329 $expected .= "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n/* ]]> */\n</script>\n"; 2379 $expected .= "<script type='text/javascript' id='test-example-js-before'>\n"; 2380 $expected .= "/* <![CDATA[ */\nconsole.log(\"before\");\n//# sourceURL=test-example-js-before\n/* ]]> */\n"; 2381 $expected .= "</script>\n"; 2330 2382 $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n"; 2331 2383 $expected .= "<script type='text/javascript' src='/wp-includes/js/dist/i18n.min.js' id='wp-i18n-js'></script>\n"; … … 2333 2385 $expected .= "/* <![CDATA[ */\n"; 2334 2386 $expected .= "wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ 'ltr' ] } );\n"; 2387 $expected .= "//# sourceURL=wp-i18n-js-after\n"; 2335 2388 $expected .= "/* ]]> */\n"; 2336 2389 $expected .= "</script>\n"; 2337 2390 $expected .= "<script type='text/javascript' src='/wp-includes/js/dist/a11y.min.js' id='wp-a11y-js'></script>\n"; 2338 2391 $expected .= "<script type='text/javascript' src='http://example2.com' id='test-example2-js'></script>\n"; 2339 $expected .= "<script type='text/javascript' id='test-example2-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n/* ]]> */\n</script>\n"; 2340 2392 $expected .= "<script type='text/javascript' id='test-example2-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=test-example2-js-after\n/* ]]> */\n</script>\n"; 2341 2393 wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null ); 2342 2394 wp_add_inline_script( 'test-example', 'console.log("before");', 'before' ); … … 2382 2434 $expected_tail .= "/* <![CDATA[ */\n"; 2383 2435 $expected_tail .= "tryCustomizeDependency()\n"; 2436 $expected_tail .= "//# sourceURL=customize-dependency-js-after\n"; 2384 2437 $expected_tail .= "/* ]]> */\n"; 2385 2438 $expected_tail .= "</script>\n"; … … 2417 2470 2418 2471 $expected = "<script type='text/javascript' src='/wp-includes/js/script.js?ver={$wp_version}' id='one-js'></script>\n"; 2419 $expected .= "<script type='text/javascript' id='one-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after one\");\n/ * ]]> */\n</script>\n";2472 $expected .= "<script type='text/javascript' id='one-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after one\");\n//# sourceURL=one-js-after\n/* ]]> */\n</script>\n"; 2420 2473 $expected .= "<script type='text/javascript' src='/wp-includes/js/script2.js?ver={$wp_version}' id='two-js'></script>\n"; 2421 2474 $expected .= "<script type='text/javascript' src='/wp-includes/js/script3.js?ver={$wp_version}' id='three-js'></script>\n"; … … 2441 2494 2442 2495 $expected = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5Bchunk_0%5D=one,two&ver={$wp_version}'></script>\n"; 2443 $expected .= "<script type='text/javascript' id='three-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before three\");\n/ * ]]> */\n</script>\n";2496 $expected .= "<script type='text/javascript' id='three-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before three\");\n//# sourceURL=three-js-before\n/* ]]> */\n</script>\n"; 2444 2497 $expected .= "<script type='text/javascript' src='/wp-includes/js/script3.js?ver={$wp_version}' id='three-js'></script>\n"; 2445 2498 $expected .= "<script type='text/javascript' src='/wp-includes/js/script4.js?ver={$wp_version}' id='four-js'></script>\n"; … … 2461 2514 ), 2462 2515 'delayed' => false, 2463 'expected_data' => '/*before foo 1*/',2464 'expected_tag' => "<script id='foo-js-before' type='text/javascript'>\n/* <![CDATA[ */\n/*before foo 1*/\n/ * ]]> */\n</script>\n",2516 'expected_data' => "/*before foo 1*/\n//# sourceURL=foo-js-before", 2517 'expected_tag' => "<script id='foo-js-before' type='text/javascript'>\n/* <![CDATA[ */\n/*before foo 1*/\n//# sourceURL=foo-js-before\n/* ]]> */\n</script>\n", 2465 2518 ), 2466 2519 'after-blocking' => array( … … 2471 2524 ), 2472 2525 'delayed' => false, 2473 'expected_data' => "/*after foo 1*/\n/*after foo 2*/ ",2474 'expected_tag' => "<script id='foo-js-after' type='text/javascript'>\n/* <![CDATA[ */\n/*after foo 1*/\n/*after foo 2*/\n/ * ]]> */\n</script>\n",2526 'expected_data' => "/*after foo 1*/\n/*after foo 2*/\n//# sourceURL=foo-js-after", 2527 'expected_tag' => "<script id='foo-js-after' type='text/javascript'>\n/* <![CDATA[ */\n/*after foo 1*/\n/*after foo 2*/\n//# sourceURL=foo-js-after\n/* ]]> */\n</script>\n", 2475 2528 ), 2476 2529 'before-delayed' => array( … … 2480 2533 ), 2481 2534 'delayed' => true, 2482 'expected_data' => '/*before foo 1*/',2483 'expected_tag' => "<script id='foo-js-before' type='text/javascript'>\n/* <![CDATA[ */\n/*before foo 1*/\n/ * ]]> */\n</script>\n",2535 'expected_data' => "/*before foo 1*/\n//# sourceURL=foo-js-before", 2536 'expected_tag' => "<script id='foo-js-before' type='text/javascript'>\n/* <![CDATA[ */\n/*before foo 1*/\n//# sourceURL=foo-js-before\n/* ]]> */\n</script>\n", 2484 2537 ), 2485 2538 'after-delayed' => array( … … 2490 2543 ), 2491 2544 'delayed' => true, 2492 'expected_data' => "/*after foo 1*/\n/*after foo 2*/ ",2493 'expected_tag' => "<script id='foo-js-after' type='text/javascript'>\n/* <![CDATA[ */\n/*after foo 1*/\n/*after foo 2*/\n/ * ]]> */\n</script>\n",2545 'expected_data' => "/*after foo 1*/\n/*after foo 2*/\n//# sourceURL=foo-js-after", 2546 'expected_tag' => "<script id='foo-js-after' type='text/javascript'>\n/* <![CDATA[ */\n/*after foo 1*/\n/*after foo 2*/\n//# sourceURL=foo-js-after\n/* ]]> */\n</script>\n", 2494 2547 ), 2495 2548 ); … … 3133 3186 wp_localize_script( 'test-example', 'testExample', $l10n_data ); 3134 3187 3135 $expected = "<script type='text/javascript' id='test-example-js-extra'>\n/* <![CDATA[ */\nvar testExample = {$expected};\n/ * ]]> */\n</script>\n";3188 $expected = "<script type='text/javascript' id='test-example-js-extra'>\n/* <![CDATA[ */\nvar testExample = {$expected};\n//# sourceURL=test-example-js-extra\n/* ]]> */\n</script>\n"; 3136 3189 $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n"; 3137 3190 … … 3702 3755 return $data['dependencies']; 3703 3756 } 3757 3758 /** 3759 * @ticket 63887 3760 */ 3761 public function test_source_url_encoding() { 3762 $this->add_html5_script_theme_support(); 3763 3764 $handle = '# test/</script> #'; 3765 3766 wp_enqueue_script( $handle, '/example.js', array(), '0.0' ); 3767 wp_add_inline_script( $handle, '"before";', 'before' ); 3768 wp_add_inline_script( $handle, '"after";' ); 3769 wp_localize_script( $handle, 'test', array() ); 3770 3771 $expected = <<<HTML 3772 <script id="# test/</script> #-js-extra"> 3773 var test = []; 3774 //# sourceURL=%23%20test%2F%3C%2Fscript%3E%20%23-js-extra 3775 </script> 3776 <script id="# test/</script> #-js-before"> 3777 "before"; 3778 //# sourceURL=%23%20test%2F%3C%2Fscript%3E%20%23-js-before 3779 </script> 3780 <script src="/example.js?ver=0.0" id="# test/</script> #-js"></script> 3781 <script id="# test/</script> #-js-after"> 3782 "after"; 3783 //# sourceURL=%23%20test%2F%3C%2Fscript%3E%20%23-js-after 3784 </script> 3785 3786 HTML; 3787 3788 $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) ); 3789 } 3790 3791 /** 3792 * @ticket 63887 3793 */ 3794 public function test_source_url_with_concat() { 3795 global $wp_scripts, $concatenate_scripts, $wp_version; 3796 $this->add_html5_script_theme_support(); 3797 3798 $concatenate_scripts = true; 3799 3800 $wp_scripts->do_concat = true; 3801 $wp_scripts->default_dirs = array( $this->default_scripts_dir ); 3802 3803 wp_enqueue_script( 'one', $this->default_scripts_dir . '1.js' ); 3804 wp_enqueue_script( 'two', $this->default_scripts_dir . '2.js' ); 3805 wp_localize_script( 'one', 'one', array( 'key' => 'val' ) ); 3806 wp_localize_script( 'two', 'two', array( 'key' => 'val' ) ); 3807 3808 wp_print_scripts(); 3809 $print_scripts = get_echo( '_print_scripts' ); 3810 3811 $expected = <<<HTML 3812 <script> 3813 /* <![CDATA[ */ 3814 var one = {"key":"val"};var two = {"key":"val"}; 3815 //# sourceURL=js-inline-concat-one%2Ctwo 3816 /* ]]> */ 3817 </script> 3818 <script src="/wp-admin/load-scripts.php?c=0&load%5Bchunk_0%5D=one,two&ver={$wp_version}"></script> 3819 3820 HTML; 3821 3822 $this->assertEqualHTML( $expected, $print_scripts ); 3823 } 3704 3824 }
Note: See TracChangeset
for help on using the changeset viewer.