WordPress.org

Make WordPress Core

Changeset 36604


Ignore:
Timestamp:
02/20/16 22:10:01 (21 months ago)
Author:
ocean90
Message:

Script Loader: Fix missing script output when the groups of dependencies are different.

Aka: Don't lose the grandchild.

Props gitlost, ocean90.
Fixes #35873.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class.wp-dependencies.php

    r36550 r36604  
    385385        $group = (int) $group; 
    386386 
    387         if ( $recursion ) 
    388             $group = min($this->group, $group); 
    389         else 
    390             $this->group = $group; 
     387        if ( $recursion ) { 
     388            $group = min( $this->group, $group ); 
     389        } 
     390 
     391        $this->group = $group; 
    391392 
    392393        if ( isset($this->groups[$handle]) && $this->groups[$handle] <= $group ) 
  • trunk/tests/phpunit/tests/dependencies/scripts.php

    r36559 r36604  
    200200        $this->assertContains( home_url( 'baz.js' ), $footer ); 
    201201    } 
     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', '/parent.js', array( 'child' ), '1', true ); // in footer 
     254        wp_register_script( 'child', '/child.js', array( 'grandchild' ), '1', false ); // in head 
     255        wp_register_script( 'grandchild', '/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='/grandchild.js?ver=1'></script>\n"; 
     263        $expected_header .= "<script type='text/javascript' src='/child.js?ver=1'></script>\n"; 
     264        $expected_footer  = "<script type='text/javascript' src='/parent.js?ver=1'></script>\n"; 
     265 
     266        $this->assertEquals( $expected_header, $header ); 
     267        $this->assertEquals( $expected_footer, $footer ); 
     268    } 
    202269} 
Note: See TracChangeset for help on using the changeset viewer.