Make WordPress Core


Ignore:
Timestamp:
11/06/2012 09:35:35 PM (12 years ago)
Author:
nbachiyski
Message:

Add tests for inline scripts and literal values.

See #WP22229

File:
1 edited

Legend:

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

    r909 r1115  
    99    function setUp() {
    1010        parent::setUp();
    11         $this->old_wp_scripts = $GLOBALS['wp_scripts'];
     11        $this->old_wp_scripts = isset( $GLOBALS['wp_scripts'] ) ? $GLOBALS['wp_scripts'] : null;
    1212        remove_action( 'wp_default_scripts', 'wp_default_scripts' );
    1313        $GLOBALS['wp_scripts'] = new WP_Scripts();
     
    8585        $wp_scripts->base_url = $base_url_backup;
    8686    }
     87
     88    /**
     89     * @ticket 22229
     90     */
     91    function test_inline_should_not_output_script_tag_with_src() {
     92        wp_enqueue_script( 'baba-inline-0', 'inline' );
     93        $this->assertEquals( '', get_echo( 'wp_print_scripts' ) );
     94    }
     95
     96    /**
     97     * @ticket 22229
     98     */
     99    function test_json_encode_should_not_encode_special_literal_values() {
     100        $literal = new WP_JS_Literal( 'baba()' );
     101        $this->assertEquals( '{"x":baba()}', WP_JS_Literal::json_encode( array( 'x' => $literal ), array( $literal ) ) );
     102    }
     103
     104    /**
     105     * @ticket 22229
     106     */
     107    function test_json_encode_should_not_encode_special_literal_values_with_dependencies() {
     108        $literal = new WP_JS_Literal( 'baba()', array( 'dep0', 'dep1' ) );
     109        $this->assertEquals( '{"x":baba()}', WP_JS_Literal::json_encode( array( 'x' => $literal ), array( $literal ) ) );
     110    }
    87111}
Note: See TracChangeset for help on using the changeset viewer.