| | 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->setOutputCallback( '__return_empty_string' ); |
| | 172 | $this->expectOutputRegex( '/^(?:<script[^>]+><\/script>\\n){2}/' ); |
| | 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 | $this->expectOutputRegex( '/^(?:<script[^>]+><\/script>\\n){1}/' ); |
| | 179 | $scripts->do_items( false, 1 ); |
| | 180 | $this->assertContains( 'one', $scripts->done ); |
| | 181 | $this->assertContains( 'two', $scripts->done ); |
| | 182 | $this->assertContains( 'three', $scripts->done ); |
| | 183 | |
| | 184 | $scripts = new WP_Scripts; |
| | 185 | $scripts->add( 'one', 'one', array(), 'v1', 1 ); |
| | 186 | $scripts->add( 'two', 'two', array( 'one' ), 'v1', 1 ); |
| | 187 | $scripts->add( 'three', 'three', array( 'one' ) ); |
| | 188 | $scripts->add( 'four', 'four', array( 'two', 'three' ), 'v1', 1 ); |
| | 189 | |
| | 190 | $scripts->enqueue( array( 'four' ) ); |
| | 191 | |
| | 192 | $this->expectOutputRegex( '/^(?:<script[^>]+><\/script>\\n){2}/' ); |
| | 193 | $scripts->do_items( false, 0 ); |
| | 194 | $this->assertContains( 'one', $scripts->done ); |
| | 195 | $this->assertNotContains( 'two', $scripts->done ); |
| | 196 | $this->assertContains( 'three', $scripts->done ); |
| | 197 | $this->assertNotContains( 'four', $scripts->done ); |
| | 198 | |
| | 199 | $this->expectOutputRegex( '/^(?:<script[^>]+><\/script>\\n){2}/' ); |
| | 200 | $scripts->do_items( false, 1 ); |
| | 201 | $this->assertContains( 'one', $scripts->done ); |
| | 202 | $this->assertContains( 'two', $scripts->done ); |
| | 203 | $this->assertContains( 'three', $scripts->done ); |
| | 204 | $this->assertContains( 'four', $scripts->done ); |
| | 205 | } |
| | 206 | |
| | 207 | /** |
| | 250 | |
| | 251 | /** |
| | 252 | * @ticket 35873 |
| | 253 | */ |
| | 254 | function test_wp_register_script_with_dependencies_in_head_and_footer() { |
| | 255 | wp_register_script( 'parent', home_url( 'parent.js' ), array( 'child' ), '1', true ); // in footer |
| | 256 | wp_register_script( 'child', home_url( 'child.js' ), array( 'grandchild' ), '1', false ); // in head |
| | 257 | wp_register_script( 'grandchild', home_url( 'grandchild.js' ), array(), '1', true ); // in footer |
| | 258 | |
| | 259 | wp_enqueue_script( 'parent' ); |
| | 260 | |
| | 261 | $header = get_echo( 'wp_print_head_scripts' ); |
| | 262 | $footer = get_echo( 'wp_print_footer_scripts' ); |
| | 263 | |
| | 264 | $expected_header = "<script type='text/javascript' src='http://example.org/grandchild.js?ver=1'></script>\n"; |
| | 265 | $expected_header .= "<script type='text/javascript' src='http://example.org/child.js?ver=1'></script>\n"; |
| | 266 | $expected_footer = "<script type='text/javascript' src='http://example.org/parent.js?ver=1'></script>\n"; |
| | 267 | |
| | 268 | $this->assertEquals( $expected_header, $header ); |
| | 269 | $this->assertEquals( $expected_footer, $footer ); |
| | 270 | } |