diff --git tests/phpunit/tests/dependencies/scripts.php tests/phpunit/tests/dependencies/scripts.php
index 445d9dc..da46fc4 100644
|
|
|
class Tests_Dependencies_Scripts extends WP_UnitTestCase {
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | | * Testing add data & conditional |
| | 89 | * 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 | 97 | $expected.= "<script type='text/javascript' src='http://example.com'></script>\n"; |
| 98 | 98 | |
| | 99 | // Go! |
| | 100 | $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) ); |
| | 101 | |
| | 102 | // No scripts left to print |
| | 103 | $this->assertEquals( '', get_echo( 'wp_print_scripts' ) ); |
| | 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() { |
| 99 | 111 | // Enqueue & add conditional comments |
| 100 | 112 | wp_enqueue_script( 'test-only-conditional', 'example.com', array(), null ); |
| 101 | 113 | 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"; |
| | 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' ) ); |
| 103 | 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() { |
| 104 | 128 | // Enqueue & add data plus conditional comments for both |
| 105 | 129 | wp_enqueue_script( 'test-conditional-with-data', 'example.com', array(), null ); |
| 106 | 130 | wp_script_add_data( 'test-conditional-with-data', 'data', 'testing' ); |
| 107 | 131 | 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"; |
| | 132 | $expected = "<!--[if lt IE 9]>\n<script type='text/javascript'>\n/* <![CDATA[ */\ntesting\n/* ]]> */\n</script>\n<![endif]-->\n"; |
| 109 | 133 | $expected.= "<!--[if lt IE 9]>\n<script type='text/javascript' src='http://example.com'></script>\n<![endif]-->\n"; |
| 110 | 134 | |
| 111 | | // Enqueue & add an invalid key for brevity |
| | 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 |
| 112 | 148 | wp_enqueue_script( 'test-invalid', 'example.com', array(), null ); |
| 113 | 149 | wp_script_add_data( 'test-invalid', 'invalid', 'testing' ); |
| 114 | | $expected.= "<script type='text/javascript' src='http://example.com'></script>\n"; |
| | 150 | $expected = "<script type='text/javascript' src='http://example.com'></script>\n"; |
| 115 | 151 | |
| 116 | 152 | // Go! |
| 117 | 153 | $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) ); |