WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/22/2018 06:12:55 AM (20 months ago)
Author:
pento
Message:

Script/Style Dependencies: Make sure that inline scripts for handles without a source are printed.

See [36550] for WP_Styles.

Merges [43565] to the 5.0 branch.

Props bpayton.
Fixes #44551.

Location:
branches/5.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0

  • branches/5.0/tests/phpunit/tests/dependencies/scripts.php

    r43738 r43788  
    396396        $expected  = "<script type='text/javascript'>\nconsole.log(\"before\");\n</script>\n";
    397397        $expected .= "<script type='text/javascript' src='http://example.com'></script>\n";
     398        $expected .= "<script type='text/javascript'>\nconsole.log(\"after\");\n</script>\n";
     399
     400        $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     401    }
     402
     403    /**
     404     * @ticket 44551
     405     */
     406    function test_wp_add_inline_script_before_for_handle_without_source() {
     407        wp_register_script( 'test-example', '' );
     408        wp_enqueue_script( 'test-example' );
     409        wp_add_inline_script( 'test-example', 'console.log("before");', 'before' );
     410
     411        $expected = "<script type='text/javascript'>\nconsole.log(\"before\");\n</script>\n";
     412
     413        $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     414    }
     415
     416    /**
     417     * @ticket 44551
     418     */
     419    function test_wp_add_inline_script_after_for_handle_without_source() {
     420        wp_register_script( 'test-example', '' );
     421        wp_enqueue_script( 'test-example' );
     422        wp_add_inline_script( 'test-example', 'console.log("after");' );
     423
     424        $expected = "<script type='text/javascript'>\nconsole.log(\"after\");\n</script>\n";
     425
     426        $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     427    }
     428
     429    /**
     430     * @ticket 44551
     431     */
     432    function test_wp_add_inline_script_before_and_after_for_handle_without_source() {
     433        wp_register_script( 'test-example', '' );
     434        wp_enqueue_script( 'test-example' );
     435        wp_add_inline_script( 'test-example', 'console.log("before");', 'before' );
     436        wp_add_inline_script( 'test-example', 'console.log("after");' );
     437
     438        $expected  = "<script type='text/javascript'>\nconsole.log(\"before\");\n</script>\n";
    398439        $expected .= "<script type='text/javascript'>\nconsole.log(\"after\");\n</script>\n";
    399440
Note: See TracChangeset for help on using the changeset viewer.