From 9391d4f57259c6ed00b32af5488ab8795317ebd1 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Sat, 31 Jan 2015 20:40:49 +0000 Subject: [PATCH] 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 --- tests/phpunit/tests/dependencies/scripts.php | 74 +++++++++++++++----- 1 file changed, 55 insertions(+), 19 deletions(-) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 445d9dc72d..da46fc441b 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -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 = "\n"; $expected.= "\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.= "\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.= "\n"; - $expected.= "\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.= "\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 = "\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 = "\n"; + $expected.= "\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 = "\n"; + // Go! $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );