Changeset 31317
- Timestamp:
- 01/31/2015 08:40:49 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/dependencies/scripts.php
r31223 r31317 87 87 88 88 /** 89 * Testing add data & conditional89 * Testing `wp_script_add_data` with the data key. 90 90 * @ticket 16024 91 91 */ 92 function test_wp_script_add_data () {92 function test_wp_script_add_data_with_data_key() { 93 93 // Enqueue & add data 94 94 wp_enqueue_script( 'test-only-data', 'example.com', array(), null ); 95 95 wp_script_add_data( 'test-only-data', 'data', 'testing' ); 96 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 comments100 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 both105 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 brevity112 wp_enqueue_script( 'test-invalid', 'example.com', array(), null );113 wp_script_add_data( 'test-invalid', 'invalid', 'testing' );114 97 $expected.= "<script type='text/javascript' src='http://example.com'></script>\n"; 115 98 … … 120 103 $this->assertEquals( '', get_echo( 'wp_print_scripts' ) ); 121 104 } 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 } 122 158 }
Note: See TracChangeset
for help on using the changeset viewer.