WordPress.org

Make WordPress Core


Ignore:
Timestamp:
08/11/2018 05:41:29 PM (19 months ago)
Author:
SergeyBiryukov
Message:

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

See [36550] for WP_Styles.

Props bpayton.
Fixes #44551.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/dependencies/scripts.php

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