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

git-svn-id: https://develop.svn.wordpress.org/trunk@31317 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2015-01-31 20:40:49 +00:00
parent cec05576e4
commit 9391d4f572
1 changed files with 55 additions and 19 deletions

View File

@ -86,33 +86,69 @@ class Tests_Dependencies_Scripts extends WP_UnitTestCase {
}
/**
* Testing add data & conditional
* Testing `wp_script_add_data` with the data key.
* @ticket 16024
*/
function test_wp_script_add_data() {
function test_wp_script_add_data_with_data_key() {
// Enqueue & add data
wp_enqueue_script( 'test-only-data', 'example.com', array(), null );
wp_script_add_data( 'test-only-data', 'data', 'testing' );
$expected = "<script type='text/javascript'>\n/* <![CDATA[ */\ntesting\n/* ]]> */\n</script>\n";
$expected.= "<script type='text/javascript' src='http://example.com'></script>\n";
// Enqueue & add conditional comments
wp_enqueue_script( 'test-only-conditional', 'example.com', array(), null );
wp_script_add_data( 'test-only-conditional', 'conditional', 'gt IE 7' );
$expected.= "<!--[if gt IE 7]>\n<script type='text/javascript' src='http://example.com'></script>\n<![endif]-->\n";
// Enqueue & add data plus conditional comments for both
wp_enqueue_script( 'test-conditional-with-data', 'example.com', array(), null );
wp_script_add_data( 'test-conditional-with-data', 'data', 'testing' );
wp_script_add_data( 'test-conditional-with-data', 'conditional', 'lt IE 9' );
$expected.= "<!--[if lt IE 9]>\n<script type='text/javascript'>\n/* <![CDATA[ */\ntesting\n/* ]]> */\n</script>\n<![endif]-->\n";
$expected.= "<!--[if lt IE 9]>\n<script type='text/javascript' src='http://example.com'></script>\n<![endif]-->\n";
// Enqueue & add an invalid key for brevity
wp_enqueue_script( 'test-invalid', 'example.com', array(), null );
wp_script_add_data( 'test-invalid', 'invalid', 'testing' );
$expected.= "<script type='text/javascript' src='http://example.com'></script>\n";
// Go!
$this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
// No scripts left to print
$this->assertEquals( '', get_echo( 'wp_print_scripts' ) );
}
/**
* Testing `wp_script_add_data` with the conditional key.
* @ticket 16024
*/
function test_wp_script_add_data_with_conditional_key() {
// Enqueue & add conditional comments
wp_enqueue_script( 'test-only-conditional', 'example.com', array(), null );
wp_script_add_data( 'test-only-conditional', 'conditional', 'gt IE 7' );
$expected = "<!--[if gt IE 7]>\n<script type='text/javascript' src='http://example.com'></script>\n<![endif]-->\n";
// Go!
$this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
// No scripts left to print
$this->assertEquals( '', get_echo( 'wp_print_scripts' ) );
}
/**
* Testing `wp_script_add_data` with both the data & conditional keys.
* @ticket 16024
*/
function test_wp_script_add_data_with_data_and_conditional_keys() {
// Enqueue & add data plus conditional comments for both
wp_enqueue_script( 'test-conditional-with-data', 'example.com', array(), null );
wp_script_add_data( 'test-conditional-with-data', 'data', 'testing' );
wp_script_add_data( 'test-conditional-with-data', 'conditional', 'lt IE 9' );
$expected = "<!--[if lt IE 9]>\n<script type='text/javascript'>\n/* <![CDATA[ */\ntesting\n/* ]]> */\n</script>\n<![endif]-->\n";
$expected.= "<!--[if lt IE 9]>\n<script type='text/javascript' src='http://example.com'></script>\n<![endif]-->\n";
// Go!
$this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
// No scripts left to print
$this->assertEquals( '', get_echo( 'wp_print_scripts' ) );
}
/**
* Testing `wp_script_add_data` with an anvalid key.
* @ticket 16024
*/
function test_wp_script_add_data_with_invalid_key() {
// Enqueue & add an invalid key
wp_enqueue_script( 'test-invalid', 'example.com', array(), null );
wp_script_add_data( 'test-invalid', 'invalid', 'testing' );
$expected = "<script type='text/javascript' src='http://example.com'></script>\n";
// Go!
$this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );