Make WordPress Core


Ignore:
Timestamp:
01/17/2015 01:36:55 AM (12 years ago)
Author:
azaozz
Message:

Add support for IE conditional comments for WP_Scripts to match the functionality of WP_Styles, including unit tests. Props filosofo, aaroncampbell, ethitter, georgestephanis, valendesigns. Fixes #16024.

File:
1 edited

Legend:

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

    r30517 r31223  
    8585                $wp_scripts->base_url = $base_url_backup;
    8686        }
     87
     88        /**
     89         * Testing add data & conditional
     90         * @ticket 16024
     91         */
     92        function test_wp_script_add_data() {
     93                // Enqueue & add data
     94                wp_enqueue_script( 'test-only-data', 'example.com', array(), null );
     95                wp_script_add_data( 'test-only-data', 'data', 'testing' );
     96                $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' );
     114                $expected.= "<script type='text/javascript' src='http://example.com'></script>\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        }
    87122}
Note: See TracChangeset for help on using the changeset viewer.