| 574 | /** |
| 575 | * Original issue with concat. |
| 576 | * |
| 577 | * @ticket 36392 |
| 578 | */ |
| 579 | public function test_wp_add_inline_script_customize_dependency_concat() { |
| 580 | global $wp_scripts; |
| 581 | |
| 582 | wp_default_scripts( $wp_scripts ); |
| 583 | |
| 584 | $wp_scripts->base_url = ''; |
| 585 | $wp_scripts->do_concat = true; |
| 586 | |
| 587 | $ver = get_bloginfo( 'version' ); |
| 588 | |
| 589 | $look_for = "/* ]]> */\n</script>\n"; |
| 590 | |
| 591 | $expected_tail = $look_for; |
| 592 | $expected_tail .= "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5B%5D=underscore,customize-base,wp-a11y,customize-controls&ver={$ver}'></script>\n"; |
| 593 | $expected_tail .= "<script type='text/javascript' src='/customize-dependency.js'></script>\n"; |
| 594 | $expected_tail .= "<script type='text/javascript'>\n"; |
| 595 | $expected_tail .= "tryCustomizeDependency()\n"; |
| 596 | $expected_tail .= "</script>\n"; |
| 597 | |
| 598 | $handle = 'customize-dependency'; |
| 599 | wp_enqueue_script( $handle, '/customize-dependency.js', array( 'customize-controls' ), null ); |
| 600 | wp_add_inline_script( $handle, 'tryCustomizeDependency()' ); |
| 601 | |
| 602 | $wp_print_scripts = get_echo( 'wp_print_scripts' ); |
| 603 | $print_scripts = get_echo( '_print_scripts' ); |
| 604 | |
| 605 | $tail = substr( $print_scripts, strrpos( $print_scripts, $look_for ) ); |
| 606 | $this->assertEquals( $expected_tail, $tail ); |
| 607 | $this->assertEquals( '', $wp_print_scripts ); |
| 608 | } |
| 609 | |
| 610 | /** |
| 611 | * Original issue without concat. |
| 612 | * |
| 613 | * @ticket 36392 |
| 614 | */ |
| 615 | public function test_wp_add_inline_script_customize_dependency_noconcat() { |
| 616 | global $wp_scripts; |
| 617 | |
| 618 | wp_default_scripts( $wp_scripts ); |
| 619 | |
| 620 | $wp_scripts->base_url = ''; |
| 621 | $wp_scripts->do_concat = false; |
| 622 | |
| 623 | $ver = get_bloginfo( 'version' ); |
| 624 | |
| 625 | $look_for = "/* ]]> */\n</script>\n"; |
| 626 | |
| 627 | $expected_tail = $look_for; |
| 628 | $expected_tail .= "<script type='text/javascript' src='/wp-admin/js/customize-controls.js?ver={$ver}'></script>\n"; |
| 629 | $expected_tail .= "<script type='text/javascript' src='/customize-dependency.js'></script>\n"; |
| 630 | $expected_tail .= "<script type='text/javascript'>\n"; |
| 631 | $expected_tail .= "tryCustomizeDependency()\n"; |
| 632 | $expected_tail .= "</script>\n"; |
| 633 | |
| 634 | $handle = 'customize-dependency'; |
| 635 | wp_enqueue_script( $handle, '/customize-dependency.js', array( 'customize-controls' ), null ); |
| 636 | wp_add_inline_script( $handle, 'tryCustomizeDependency()' ); |
| 637 | |
| 638 | $print_scripts = get_echo( 'wp_print_scripts' ); |
| 639 | |
| 640 | $tail = substr( $print_scripts, strrpos( $print_scripts, $look_for ) ); |
| 641 | $this->assertEquals( $expected_tail, $tail ); |
| 642 | } |
| 643 | |
| 644 | /** |
| 645 | * @ticket 36392 |
| 646 | */ |
| 647 | public function test_wp_add_inline_script_concat_with_core_dependency() { |
| 648 | global $wp_scripts; |
| 649 | |
| 650 | wp_default_scripts( $wp_scripts ); |
| 651 | |
| 652 | $wp_scripts->base_url = ''; |
| 653 | $wp_scripts->do_concat = true; |
| 654 | |
| 655 | $ver = get_bloginfo( 'version' ); |
| 656 | $expected = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5B%5D=jquery-core,jquery-migrate&ver={$ver}'></script>\n"; |
| 657 | $expected .= "<script type='text/javascript' src='http://example.com'></script>\n"; |
| 658 | $expected .= "<script type='text/javascript'>\nconsole.log(\"after\");\n</script>\n"; |
| 659 | |
| 660 | wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null ); |
| 661 | wp_add_inline_script( 'test-example', 'console.log("after");' ); |
| 662 | |
| 663 | wp_print_scripts(); |
| 664 | $print_scripts = get_echo( '_print_scripts' ); |
| 665 | |
| 666 | $this->assertEquals( $expected, $print_scripts ); |
| 667 | } |
| 668 | |
| 669 | /** |
| 670 | * @ticket 36392 |
| 671 | */ |
| 672 | public function test_wp_add_inline_script_noconcat_with_core_dependency() { |
| 673 | global $wp_scripts; |
| 674 | |
| 675 | wp_default_scripts( $wp_scripts ); |
| 676 | |
| 677 | $wp_scripts->base_url = ''; |
| 678 | $wp_scripts->do_concat = false; |
| 679 | |
| 680 | $js_ver = $wp_scripts->registered['jquery']->ver; |
| 681 | $js_migrate_ver = $wp_scripts->registered['jquery-migrate']->ver; |
| 682 | |
| 683 | $expected = "<script type='text/javascript' src='/wp-includes/js/jquery/jquery.js?ver={$js_ver}'></script>\n"; |
| 684 | $expected .= "<script type='text/javascript' src='/wp-includes/js/jquery/jquery-migrate.js?ver={$js_migrate_ver}'></script>\n"; |
| 685 | $expected .= "<script type='text/javascript' src='http://example.com'></script>\n"; |
| 686 | $expected .= "<script type='text/javascript'>\nconsole.log(\"after\");\n</script>\n"; |
| 687 | |
| 688 | wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null ); |
| 689 | wp_add_inline_script( 'test-example', 'console.log("after");' ); |
| 690 | |
| 691 | $print_scripts = get_echo( 'wp_print_scripts' ); |
| 692 | |
| 693 | $this->assertEquals( $expected, $print_scripts ); |
| 694 | } |
| 695 | |
| 696 | /** |
| 697 | * @ticket 36392 |
| 698 | */ |
| 699 | public function test_wp_add_inline_script_concat_with_conditional_and_core_dependency() { |
| 700 | global $wp_scripts; |
| 701 | |
| 702 | wp_default_scripts( $wp_scripts ); |
| 703 | |
| 704 | $wp_scripts->base_url = ''; |
| 705 | $wp_scripts->do_concat = true; |
| 706 | |
| 707 | $ver = get_bloginfo( 'version' ); |
| 708 | $expected = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5B%5D=jquery-core,jquery-migrate&ver={$ver}'></script>\n"; |
| 709 | $expected .= "<!--[if gte IE 9]>\n"; |
| 710 | $expected .= "<script type='text/javascript' src='http://example.com'></script>\n"; |
| 711 | $expected .= "<script type='text/javascript'>\nconsole.log(\"after\");\n</script>\n"; |
| 712 | $expected .= "<![endif]-->\n"; |
| 713 | |
| 714 | wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null ); |
| 715 | wp_add_inline_script( 'test-example', 'console.log("after");' ); |
| 716 | wp_script_add_data( 'test-example', 'conditional', 'gte IE 9' ); |
| 717 | |
| 718 | wp_print_scripts(); |
| 719 | $print_scripts = get_echo( '_print_scripts' ); |
| 720 | |
| 721 | $this->assertEquals( $expected, $print_scripts ); |
| 722 | } |
| 723 | |
| 724 | /** |
| 725 | * @ticket 36392 |
| 726 | */ |
| 727 | public function test_wp_add_inline_script_before_concat_with_core_dependency() { |
| 728 | global $wp_scripts; |
| 729 | |
| 730 | wp_default_scripts( $wp_scripts ); |
| 731 | |
| 732 | $wp_scripts->base_url = ''; |
| 733 | $wp_scripts->do_concat = true; |
| 734 | |
| 735 | $ver = get_bloginfo( 'version' ); |
| 736 | $expected = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5B%5D=jquery-core,jquery-migrate&ver={$ver}'></script>\n"; |
| 737 | $expected .= "<script type='text/javascript'>\nconsole.log(\"before\");\n</script>\n"; |
| 738 | $expected .= "<script type='text/javascript' src='http://example.com'></script>\n"; |
| 739 | |
| 740 | wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null ); |
| 741 | wp_add_inline_script( 'test-example', 'console.log("before");', 'before' ); |
| 742 | |
| 743 | wp_print_scripts(); |
| 744 | $print_scripts = get_echo( '_print_scripts' ); |
| 745 | |
| 746 | $this->assertEquals( $expected, $print_scripts ); |
| 747 | } |
| 748 | |
| 749 | /** |
| 750 | * @ticket 36392 |
| 751 | */ |
| 752 | public function test_wp_add_inline_script_before_after_concat_with_core_dependency() { |
| 753 | global $wp_scripts; |
| 754 | |
| 755 | wp_default_scripts( $wp_scripts ); |
| 756 | |
| 757 | $wp_scripts->base_url = ''; |
| 758 | $wp_scripts->do_concat = true; |
| 759 | |
| 760 | $ver = get_bloginfo( 'version' ); |
| 761 | $expected = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5B%5D=jquery-core,jquery-migrate&ver={$ver}'></script>\n"; |
| 762 | $expected .= "<script type='text/javascript'>\nconsole.log(\"before\");\n</script>\n"; |
| 763 | $expected .= "<script type='text/javascript' src='http://example.com'></script>\n"; |
| 764 | $expected .= "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5B%5D=wp-a11y&ver={$ver}'></script>\n"; |
| 765 | $expected .= "<script type='text/javascript' src='http://example2.com'></script>\n"; |
| 766 | $expected .= "<script type='text/javascript'>\nconsole.log(\"after\");\n</script>\n"; |
| 767 | |
| 768 | wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null ); |
| 769 | wp_add_inline_script( 'test-example', 'console.log("before");', 'before' ); |
| 770 | wp_enqueue_script( 'test-example2', 'http://example2.com', array( 'wp-a11y' ), null ); |
| 771 | wp_add_inline_script( 'test-example2', 'console.log("after");', 'after' ); |
| 772 | |
| 773 | wp_print_scripts(); |
| 774 | $print_scripts = get_echo( '_print_scripts' ); |
| 775 | |
| 776 | $this->assertEquals( $expected, $print_scripts ); |
| 777 | } |
| 778 | |
| 779 | /** |
| 780 | * @ticket 36392 |
| 781 | */ |
| 782 | public function test_wp_add_inline_script_before_after_concat_with_core_dependency_default_dirs() { |
| 783 | global $wp_scripts; |
| 784 | |
| 785 | wp_default_scripts( $wp_scripts ); |
| 786 | |
| 787 | $wp_scripts->base_url = ''; |
| 788 | $wp_scripts->do_concat = true; |
| 789 | $wp_scripts->default_dirs = array('/wp-admin/js/', '/wp-includes/js/'); // Default dirs as in wp-includes/script-loader.php |
| 790 | |
| 791 | $ver = get_bloginfo( 'version' ); |
| 792 | $expected = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5B%5D=jquery-core,jquery-migrate&ver={$ver}'></script>\n"; |
| 793 | $expected .= "<script type='text/javascript'>\nconsole.log(\"before\");\n</script>\n"; |
| 794 | $expected .= "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5B%5D=test-example,wp-a11y,test-example2&ver={$ver}'></script>\n"; |
| 795 | $expected .= "<script type='text/javascript'>\nconsole.log(\"after\");\n</script>\n"; |
| 796 | |
| 797 | wp_enqueue_script( 'test-example', '/wp-admin/js/example.js', array( 'jquery' ), null ); |
| 798 | wp_add_inline_script( 'test-example', 'console.log("before");', 'before' ); |
| 799 | wp_enqueue_script( 'test-example2', '/wp-includes/js/example2.js', array( 'wp-a11y' ), null ); |
| 800 | wp_add_inline_script( 'test-example2', 'console.log("after");', 'after' ); |
| 801 | |
| 802 | wp_print_scripts(); |
| 803 | $print_scripts = get_echo( '_print_scripts' ); |
| 804 | |
| 805 | $this->assertEquals( $expected, $print_scripts ); |
| 806 | } |
| 807 | |
| 808 | /** |
| 809 | * @ticket 36392 |
| 810 | */ |
| 811 | public function test_wp_script_conditional_concat_dependency() { |
| 812 | global $wp_scripts; |
| 813 | |
| 814 | $wp_scripts->do_concat = true; |
| 815 | $wp_scripts->default_dirs = array( '/directory/' ); |
| 816 | |
| 817 | wp_enqueue_script( 'one', '/directory/one.js' ); |
| 818 | wp_enqueue_script( 'two', '/directory/two.js' ); |
| 819 | wp_enqueue_script( 'three', '/directory/three.js', array( 'one' ) ); |
| 820 | |
| 821 | wp_script_add_data( 'one', 'conditional', 'blah' ); |
| 822 | |
| 823 | wp_print_scripts(); |
| 824 | $print_scripts = get_echo( '_print_scripts' ); |
| 825 | |
| 826 | $ver = get_bloginfo( 'version' ); |
| 827 | |
| 828 | $expected = "<!--[if blah]>\n"; |
| 829 | $expected .= "<script type='text/javascript' src='/directory/one.js?ver={$ver}'></script>\n"; |
| 830 | $expected .= "<![endif]-->\n"; |
| 831 | $expected .= "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5B%5D=two,three&ver={$ver}'></script>\n"; |
| 832 | |
| 833 | $this->assertEquals( $expected, $print_scripts ); |
| 834 | } |
| 835 | |
| 836 | /** |
| 837 | * @ticket 36392 |
| 838 | */ |
| 839 | public function test_wp_script_conditional_noconcat_dependency() { |
| 840 | global $wp_scripts; |
| 841 | |
| 842 | $wp_scripts->do_concat = false; |
| 843 | $wp_scripts->default_dirs = array( '/directory/' ); |
| 844 | |
| 845 | wp_enqueue_script( 'one', '/directory/one.js' ); |
| 846 | wp_enqueue_script( 'two', '/directory/two.js' ); |
| 847 | wp_enqueue_script( 'three', '/directory/three.js', array( 'one' ) ); |
| 848 | |
| 849 | wp_script_add_data( 'one', 'conditional', 'blah' ); |
| 850 | |
| 851 | $print_scripts = get_echo( 'wp_print_scripts' ); |
| 852 | |
| 853 | $ver = get_bloginfo( 'version' ); |
| 854 | |
| 855 | $expected = "<!--[if blah]>\n"; |
| 856 | $expected .= "<script type='text/javascript' src='/directory/one.js?ver={$ver}'></script>\n"; |
| 857 | $expected .= "<![endif]-->\n"; |
| 858 | $expected .= "<script type='text/javascript' src='/directory/two.js?ver={$ver}'></script>\n"; |
| 859 | $expected .= "<script type='text/javascript' src='/directory/three.js?ver={$ver}'></script>\n"; |
| 860 | |
| 861 | $this->assertEquals( $expected, $print_scripts ); |
| 862 | } |
| 863 | |
| 864 | /** |
| 865 | * @ticket 36392 |
| 866 | */ |
| 867 | public function test_wp_script_diff_default_dirs_concat_dependency() { |
| 868 | global $wp_scripts; |
| 869 | |
| 870 | $wp_scripts->do_concat = true; |
| 871 | $wp_scripts->default_dirs = array( '/directory/' ); |
| 872 | |
| 873 | wp_enqueue_script( 'one', '/directory/one.js' ); |
| 874 | wp_enqueue_script( 'two', '/directory2/two.js' ); // Not in_default_dirs(). |
| 875 | wp_enqueue_script( 'three', '/directory/three.js', array( 'two' ) ); |
| 876 | |
| 877 | $wp_print_scripts = get_echo( 'wp_print_scripts' ); |
| 878 | $print_scripts = get_echo( '_print_scripts' ); |
| 879 | |
| 880 | $ver = get_bloginfo( 'version' ); |
| 881 | |
| 882 | $expected = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5B%5D=one&ver={$ver}'></script>\n"; |
| 883 | $expected .= "<script type='text/javascript' src='/directory2/two.js?ver={$ver}'></script>\n"; |
| 884 | $expected .= "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5B%5D=three&ver={$ver}'></script>\n"; |
| 885 | |
| 886 | $this->assertEquals( $expected, $print_scripts ); |
| 887 | $this->assertEquals( '', $wp_print_scripts ); |
| 888 | } |
| 889 | |
| 890 | /** |
| 891 | * @ticket 36392 |
| 892 | */ |
| 893 | public function test_wp_script_conditional_before_after_concat_dependency_diff_include_dirs() { |
| 894 | global $wp_scripts; |
| 895 | |
| 896 | $wp_scripts->do_concat = true; |
| 897 | $wp_scripts->default_dirs = array( '/directory/' ); |
| 898 | |
| 899 | wp_enqueue_script( 'one', '/directory/one.js' ); |
| 900 | wp_enqueue_script( 'two', '/directory2/two.js' ); // Not in_default_dirs(). |
| 901 | wp_enqueue_script( 'three', '/directory/three.js', array( 'one' ) ); |
| 902 | wp_enqueue_script( 'four', '/directory/four.js' ); |
| 903 | |
| 904 | wp_script_add_data( 'one', 'conditional', 'blah' ); |
| 905 | wp_add_inline_script( 'one', 'console.log("before1");', 'before' ); |
| 906 | |
| 907 | wp_add_inline_script( 'two', 'console.log("before2");', 'before' ); |
| 908 | wp_add_inline_script( 'two', 'console.log("after2");', 'after' ); |
| 909 | |
| 910 | wp_add_inline_script( 'three', 'console.log("before3");', 'before' ); |
| 911 | wp_add_inline_script( 'three', 'console.log("after3");', 'after' ); |
| 912 | |
| 913 | wp_add_inline_script( 'four', 'console.log("before4");', 'before' ); |
| 914 | wp_add_inline_script( 'four', 'console.log("after4");', 'after' ); |
| 915 | |
| 916 | wp_print_scripts(); |
| 917 | $print_scripts = get_echo( '_print_scripts' ); |
| 918 | |
| 919 | $ver = get_bloginfo( 'version' ); |
| 920 | |
| 921 | $expected = "<!--[if blah]>\n"; |
| 922 | $expected .= "<script type='text/javascript'>\nconsole.log(\"before1\");\n</script>\n"; |
| 923 | $expected .= "<script type='text/javascript' src='/directory/one.js?ver={$ver}'></script>\n"; |
| 924 | $expected .= "<![endif]-->\n"; |
| 925 | $expected .= "<script type='text/javascript'>\nconsole.log(\"before2\");\n</script>\n"; |
| 926 | $expected .= "<script type='text/javascript' src='/directory2/two.js?ver={$ver}'></script>\n"; |
| 927 | $expected .= "<script type='text/javascript'>\nconsole.log(\"after2\");\n</script>\n"; |
| 928 | $expected .= "<script type='text/javascript'>\nconsole.log(\"before3\");\n</script>\n"; |
| 929 | $expected .= "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5B%5D=three&ver={$ver}'></script>\n"; |
| 930 | $expected .= "<script type='text/javascript'>\nconsole.log(\"after3\");\n</script>\n"; |
| 931 | $expected .= "<script type='text/javascript'>\nconsole.log(\"before4\");\n</script>\n"; |
| 932 | $expected .= "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5B%5D=four&ver={$ver}'></script>\n"; |
| 933 | $expected .= "<script type='text/javascript'>\nconsole.log(\"after4\");\n</script>\n"; |
| 934 | |
| 935 | $this->assertEquals( $expected, $print_scripts ); |
| 936 | } |
| 937 | |
| 938 | /** |
| 939 | * @ticket 36392 |
| 940 | */ |
| 941 | public function test_wp_add_inline_script_concat_diff_include_dirs_localize_conditional() { |
| 942 | global $wp_scripts; |
| 943 | |
| 944 | $wp_scripts->do_concat = true; |
| 945 | $wp_scripts->default_dirs = array( '/directory/' ); |
| 946 | |
| 947 | wp_enqueue_script( 'one', '/directory/one.js' ); |
| 948 | wp_localize_script( 'one', 'oneLocalize', array( 'foo' => 'bar' ) ); |
| 949 | wp_enqueue_script( 'two', '/directory2/two.js' ); // Not in_default_dirs(). |
| 950 | wp_localize_script( 'two', 'twoLocalize', array( 'foo' => 'bar' ) ); |
| 951 | wp_script_add_data( 'two', 'conditional', 'lt IE 9' ); |
| 952 | |
| 953 | $wp_print_scripts = get_echo( 'wp_print_scripts' ); |
| 954 | $print_scripts = $wp_print_scripts . get_echo( '_print_scripts' ); |
| 955 | |
| 956 | $ver = get_bloginfo( 'version' ); |
| 957 | |
| 958 | $expected = "<!--[if lt IE 9]>\n<script type='text/javascript'>\n/* <![CDATA[ */\nvar twoLocalize = {\"foo\":\"bar\"};\n/* ]]> */\n</script>\n<![endif]-->\n"; |
| 959 | $expected .= "\n<script type='text/javascript'>\n/* <![CDATA[ */\nvar oneLocalize = {\"foo\":\"bar\"};/* ]]> */\n</script>\n"; |
| 960 | $expected .= "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5B%5D=one&ver={$ver}'></script>\n"; |
| 961 | $expected .= "<!--[if lt IE 9]>\n<script type='text/javascript' src='/directory2/two.js?ver={$ver}'></script>\n<![endif]-->\n"; |
| 962 | |
| 963 | $this->assertEquals( $expected, $print_scripts ); |
| 964 | } |
| 965 | |
| 966 | /** |
| 967 | * @ticket 36392 |
| 968 | */ |
| 969 | public function test_wp_add_line_script_before_core_registered_script() { |
| 970 | global $wp_scripts; |
| 971 | |
| 972 | wp_default_scripts( $wp_scripts ); |
| 973 | |
| 974 | $wp_scripts->base_url = ''; |
| 975 | $wp_scripts->do_concat = true; |
| 976 | |
| 977 | $ver = get_bloginfo( 'version' ); |
| 978 | $expected = "<script type='text/javascript'>\nconsole.log(\"before jquery\");\n</script>\n"; |
| 979 | $expected .= "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5B%5D=jquery-core,jquery-migrate&ver={$ver}'></script>\n"; |
| 980 | $expected .= "<script type='text/javascript' src='http://example.com'></script>\n"; |
| 981 | |
| 982 | wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null ); |
| 983 | wp_add_inline_script( 'jquery-core', 'console.log("before jquery");', 'before' ); |
| 984 | |
| 985 | wp_print_scripts(); |
| 986 | $print_scripts = get_echo( '_print_scripts' ); |
| 987 | |
| 988 | $this->assertEquals( $expected, $print_scripts ); |
| 989 | } |
| 990 | |
| 991 | /** |
| 992 | * @ticket 36392 |
| 993 | */ |
| 994 | public function test_wp_add_line_script_after_core_registered_script() { |
| 995 | global $wp_scripts; |
| 996 | |
| 997 | wp_default_scripts( $wp_scripts ); |
| 998 | |
| 999 | $wp_scripts->base_url = ''; |
| 1000 | $wp_scripts->do_concat = true; |
| 1001 | |
| 1002 | $ver = get_bloginfo( 'version' ); |
| 1003 | $expected = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5B%5D=jquery-core&ver={$ver}'></script>\n"; |
| 1004 | $expected .= "<script type='text/javascript'>\nconsole.log(\"after jquery\");\n</script>\n"; |
| 1005 | $expected .= "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5B%5D=jquery-migrate&ver={$ver}'></script>\n"; |
| 1006 | $expected .= "<script type='text/javascript' src='http://example.com'></script>\n"; |
| 1007 | |
| 1008 | wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null ); |
| 1009 | wp_add_inline_script( 'jquery-core', 'console.log("after jquery");', 'after' ); |
| 1010 | |
| 1011 | wp_print_scripts(); |
| 1012 | $print_scripts = get_echo( '_print_scripts' ); |
| 1013 | |
| 1014 | $this->assertEquals( $expected, $print_scripts ); |
| 1015 | } |