| 160 | * Test mismatch of groups in dependencies outputs all scripts in right order. |
| 161 | * @ticket 25247 |
| 162 | */ |
| 163 | public function test_group_mismatch_in_deps() { |
| 164 | $scripts = new WP_Scripts; |
| 165 | $scripts->add( 'one', 'one', array(), 'v1', 1 ); |
| 166 | $scripts->add( 'two', 'two', array( 'one' ) ); |
| 167 | $scripts->add( 'three', 'three', array( 'two' ), 'v1', 1 ); |
| 168 | |
| 169 | $scripts->enqueue( array( 'three' ) ); |
| 170 | |
| 171 | $this->expectOutputRegex( '/^(?:<script[^>]+><\/script>\\n){7}$/' ); |
| 172 | |
| 173 | $scripts->do_items( false, 0 ); |
| 174 | $this->assertContains( 'one', $scripts->done ); |
| 175 | $this->assertContains( 'two', $scripts->done ); |
| 176 | $this->assertNotContains( 'three', $scripts->done ); |
| 177 | |
| 178 | $scripts->do_items( false, 1 ); |
| 179 | $this->assertContains( 'one', $scripts->done ); |
| 180 | $this->assertContains( 'two', $scripts->done ); |
| 181 | $this->assertContains( 'three', $scripts->done ); |
| 182 | |
| 183 | $scripts = new WP_Scripts; |
| 184 | $scripts->add( 'one', 'one', array(), 'v1', 1 ); |
| 185 | $scripts->add( 'two', 'two', array( 'one' ), 'v1', 1 ); |
| 186 | $scripts->add( 'three', 'three', array( 'one' ) ); |
| 187 | $scripts->add( 'four', 'four', array( 'two', 'three' ), 'v1', 1 ); |
| 188 | |
| 189 | $scripts->enqueue( array( 'four' ) ); |
| 190 | |
| 191 | $scripts->do_items( false, 0 ); |
| 192 | $this->assertContains( 'one', $scripts->done ); |
| 193 | $this->assertNotContains( 'two', $scripts->done ); |
| 194 | $this->assertContains( 'three', $scripts->done ); |
| 195 | $this->assertNotContains( 'four', $scripts->done ); |
| 196 | |
| 197 | $scripts->do_items( false, 1 ); |
| 198 | $this->assertContains( 'one', $scripts->done ); |
| 199 | $this->assertContains( 'two', $scripts->done ); |
| 200 | $this->assertContains( 'three', $scripts->done ); |
| 201 | $this->assertContains( 'four', $scripts->done ); |
| 202 | } |
| 203 | |
| 204 | /** |
| 247 | |
| 248 | /** |
| 249 | * @ticket 35873 |
| 250 | */ |
| 251 | function test_wp_register_script_with_dependencies_in_head_and_footer() { |
| 252 | wp_register_script( 'parent', home_url( 'parent.js' ), array( 'child' ), '1', true ); // in footer |
| 253 | wp_register_script( 'child', home_url( 'child.js' ), array( 'grandchild' ), '1', false ); // in head |
| 254 | wp_register_script( 'grandchild', home_url( 'grandchild.js' ), array(), '1', true ); // in footer |
| 255 | |
| 256 | wp_enqueue_script( 'parent' ); |
| 257 | |
| 258 | $header = get_echo( 'wp_print_head_scripts' ); |
| 259 | $footer = get_echo( 'wp_print_footer_scripts' ); |
| 260 | |
| 261 | $expected_header = "<script type='text/javascript' src='http://example.org/grandchild.js?ver=1'></script>\n"; |
| 262 | $expected_header .= "<script type='text/javascript' src='http://example.org/child.js?ver=1'></script>\n"; |
| 263 | $expected_footer = "<script type='text/javascript' src='http://example.org/parent.js?ver=1'></script>\n"; |
| 264 | |
| 265 | $this->assertEquals( $expected_header, $header ); |
| 266 | $this->assertEquals( $expected_footer, $footer ); |
| 267 | } |