| 202 | |
| 203 | /** |
| 204 | * Test mismatch of groups in dependencies outputs all scripts in right order. |
| 205 | * |
| 206 | * @ticket 35873 |
| 207 | */ |
| 208 | public function test_group_mismatch_in_deps() { |
| 209 | $scripts = new WP_Scripts; |
| 210 | $scripts->add( 'one', 'one', array(), 'v1', 1 ); |
| 211 | $scripts->add( 'two', 'two', array( 'one' ) ); |
| 212 | $scripts->add( 'three', 'three', array( 'two' ), 'v1', 1 ); |
| 213 | |
| 214 | $scripts->enqueue( array( 'three' ) ); |
| 215 | |
| 216 | $this->expectOutputRegex( '/^(?:<script[^>]+><\/script>\\n){7}$/' ); |
| 217 | |
| 218 | $scripts->do_items( false, 0 ); |
| 219 | $this->assertContains( 'one', $scripts->done ); |
| 220 | $this->assertContains( 'two', $scripts->done ); |
| 221 | $this->assertNotContains( 'three', $scripts->done ); |
| 222 | |
| 223 | $scripts->do_items( false, 1 ); |
| 224 | $this->assertContains( 'one', $scripts->done ); |
| 225 | $this->assertContains( 'two', $scripts->done ); |
| 226 | $this->assertContains( 'three', $scripts->done ); |
| 227 | |
| 228 | $scripts = new WP_Scripts; |
| 229 | $scripts->add( 'one', 'one', array(), 'v1', 1 ); |
| 230 | $scripts->add( 'two', 'two', array( 'one' ), 'v1', 1 ); |
| 231 | $scripts->add( 'three', 'three', array( 'one' ) ); |
| 232 | $scripts->add( 'four', 'four', array( 'two', 'three' ), 'v1', 1 ); |
| 233 | |
| 234 | $scripts->enqueue( array( 'four' ) ); |
| 235 | |
| 236 | $scripts->do_items( false, 0 ); |
| 237 | $this->assertContains( 'one', $scripts->done ); |
| 238 | $this->assertNotContains( 'two', $scripts->done ); |
| 239 | $this->assertContains( 'three', $scripts->done ); |
| 240 | $this->assertNotContains( 'four', $scripts->done ); |
| 241 | |
| 242 | $scripts->do_items( false, 1 ); |
| 243 | $this->assertContains( 'one', $scripts->done ); |
| 244 | $this->assertContains( 'two', $scripts->done ); |
| 245 | $this->assertContains( 'three', $scripts->done ); |
| 246 | $this->assertContains( 'four', $scripts->done ); |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * @ticket 35873 |
| 251 | */ |
| 252 | function test_wp_register_script_with_dependencies_in_head_and_footer() { |
| 253 | wp_register_script( 'parent', home_url( 'parent.js' ), array( 'child' ), '1', true ); // in footer |
| 254 | wp_register_script( 'child', home_url( 'child.js' ), array( 'grandchild' ), '1', false ); // in head |
| 255 | wp_register_script( 'grandchild', home_url( 'grandchild.js' ), array(), '1', true ); // in footer |
| 256 | |
| 257 | wp_enqueue_script( 'parent' ); |
| 258 | |
| 259 | $header = get_echo( 'wp_print_head_scripts' ); |
| 260 | $footer = get_echo( 'wp_print_footer_scripts' ); |
| 261 | |
| 262 | $expected_header = "<script type='text/javascript' src='http://example.org/grandchild.js?ver=1'></script>\n"; |
| 263 | $expected_header .= "<script type='text/javascript' src='http://example.org/child.js?ver=1'></script>\n"; |
| 264 | $expected_footer = "<script type='text/javascript' src='http://example.org/parent.js?ver=1'></script>\n"; |
| 265 | |
| 266 | $this->assertEquals( $expected_header, $header ); |
| 267 | $this->assertEquals( $expected_footer, $footer ); |
| 268 | } |