WordPress.org

Make WordPress Core

Changeset 31317


Ignore:
Timestamp:
01/31/2015 08:40:49 PM (5 years ago)
Author:
azaozz
Message:

Separate the tests for IE conditional comments support in WP_Scripts. Props valendesigns, see 16024.

File:
1 edited

Legend:

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

    r31223 r31317  
    8787
    8888    /**
    89      * Testing add data & conditional
     89     * Testing `wp_script_add_data` with the data key.
    9090     * @ticket 16024
    9191     */
    92     function test_wp_script_add_data() {
     92    function test_wp_script_add_data_with_data_key() {
    9393        // Enqueue & add data
    9494        wp_enqueue_script( 'test-only-data', 'example.com', array(), null );
    9595        wp_script_add_data( 'test-only-data', 'data', 'testing' );
    9696        $expected = "<script type='text/javascript'>\n/* <![CDATA[ */\ntesting\n/* ]]> */\n</script>\n";
    97         $expected.= "<script type='text/javascript' src='http://example.com'></script>\n";
    98 
    99         // Enqueue & add conditional comments
    100         wp_enqueue_script( 'test-only-conditional', 'example.com', array(), null );
    101         wp_script_add_data( 'test-only-conditional', 'conditional', 'gt IE 7' );
    102         $expected.= "<!--[if gt IE 7]>\n<script type='text/javascript' src='http://example.com'></script>\n<![endif]-->\n";
    103 
    104         // Enqueue & add data plus conditional comments for both
    105         wp_enqueue_script( 'test-conditional-with-data', 'example.com', array(), null );
    106         wp_script_add_data( 'test-conditional-with-data', 'data', 'testing' );
    107         wp_script_add_data( 'test-conditional-with-data', 'conditional', 'lt IE 9' );
    108         $expected.= "<!--[if lt IE 9]>\n<script type='text/javascript'>\n/* <![CDATA[ */\ntesting\n/* ]]> */\n</script>\n<![endif]-->\n";
    109         $expected.= "<!--[if lt IE 9]>\n<script type='text/javascript' src='http://example.com'></script>\n<![endif]-->\n";
    110 
    111         // Enqueue & add an invalid key for brevity
    112         wp_enqueue_script( 'test-invalid', 'example.com', array(), null );
    113         wp_script_add_data( 'test-invalid', 'invalid', 'testing' );
    11497        $expected.= "<script type='text/javascript' src='http://example.com'></script>\n";
    11598
     
    120103        $this->assertEquals( '', get_echo( 'wp_print_scripts' ) );
    121104    }
     105
     106    /**
     107     * Testing `wp_script_add_data` with the conditional key.
     108     * @ticket 16024
     109     */
     110    function test_wp_script_add_data_with_conditional_key() {
     111        // Enqueue & add conditional comments
     112        wp_enqueue_script( 'test-only-conditional', 'example.com', array(), null );
     113        wp_script_add_data( 'test-only-conditional', 'conditional', 'gt IE 7' );
     114        $expected = "<!--[if gt IE 7]>\n<script type='text/javascript' src='http://example.com'></script>\n<![endif]-->\n";
     115
     116        // Go!
     117        $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     118
     119        // No scripts left to print
     120        $this->assertEquals( '', get_echo( 'wp_print_scripts' ) );
     121    }
     122
     123    /**
     124     * Testing `wp_script_add_data` with both the data & conditional keys.
     125     * @ticket 16024
     126     */
     127    function test_wp_script_add_data_with_data_and_conditional_keys() {
     128        // Enqueue & add data plus conditional comments for both
     129        wp_enqueue_script( 'test-conditional-with-data', 'example.com', array(), null );
     130        wp_script_add_data( 'test-conditional-with-data', 'data', 'testing' );
     131        wp_script_add_data( 'test-conditional-with-data', 'conditional', 'lt IE 9' );
     132        $expected = "<!--[if lt IE 9]>\n<script type='text/javascript'>\n/* <![CDATA[ */\ntesting\n/* ]]> */\n</script>\n<![endif]-->\n";
     133        $expected.= "<!--[if lt IE 9]>\n<script type='text/javascript' src='http://example.com'></script>\n<![endif]-->\n";
     134
     135        // Go!
     136        $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     137
     138        // No scripts left to print
     139        $this->assertEquals( '', get_echo( 'wp_print_scripts' ) );
     140    }
     141
     142    /**
     143     * Testing `wp_script_add_data` with an anvalid key.
     144     * @ticket 16024
     145     */
     146    function test_wp_script_add_data_with_invalid_key() {
     147        // Enqueue & add an invalid key
     148        wp_enqueue_script( 'test-invalid', 'example.com', array(), null );
     149        wp_script_add_data( 'test-invalid', 'invalid', 'testing' );
     150        $expected = "<script type='text/javascript' src='http://example.com'></script>\n";
     151
     152        // Go!
     153        $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     154
     155        // No scripts left to print
     156        $this->assertEquals( '', get_echo( 'wp_print_scripts' ) );
     157    }
    122158}
Note: See TracChangeset for help on using the changeset viewer.