Make WordPress Core

Ticket #25247: 25247_tests6.diff

File 25247_tests6.diff, 4.6 KB (added by gitlost, 9 years ago)

Fixed outputExpectedRegex stuff.

  • tests/phpunit/tests/dependencies/jquery.php

     
    8181
    8282                unset( $GLOBALS['wp_scripts'] );
    8383        }
     84
     85        /**
     86         * Test placing of jquery in footer.
     87         * @ticket 25247
     88         */
     89        function test_jquery_in_footer() {
     90                $scripts = new WP_Scripts;
     91                $scripts->add( 'jquery', false, array( 'jquery-core', 'jquery-migrate' ) );
     92                $scripts->add( 'jquery-core', '/jquery.js', array() );
     93                $scripts->add( 'jquery-migrate', "/jquery-migrate.js", array() );
     94
     95                $scripts->enqueue( 'jquery' );
     96
     97                $object = $scripts->query( 'jquery' );
     98                $object->add_data( 'group', 1 );
     99                foreach( $object->deps as $dep ) {
     100                        $scripts->add_data( $dep, 'group', 1 );
     101                }
     102
     103                $this->expectOutputRegex( '/^(?:<script[^>]+><\/script>\\n){2}$/' );
     104
     105                $scripts->do_items( false, 0 );
     106                // Could do $this->assertContains( 'jquery', $scripts->done );
     107                $this->assertNotContains( 'jquery-core', $scripts->done, 'jquery-core should be in footer but is in head' );
     108                $this->assertNotContains( 'jquery-migrate', $scripts->done, 'jquery-migrate should be in footer but is in head' );
     109
     110                $scripts->do_items( false, 1 );
     111                $this->assertContains( 'jquery', $scripts->done );
     112                $this->assertContains( 'jquery-core', $scripts->done, 'jquery-core in footer' );
     113                $this->assertContains( 'jquery-migrate', $scripts->done, 'jquery-migrate in footer' );
     114        }
    84115}
  • tests/phpunit/tests/dependencies/scripts.php

     
    157157        }
    158158
    159159        /**
     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        /**
    160205         * Testing 'wp_register_script' return boolean success/failure value.
    161206         *
    162207         * @ticket 31126
     
    199244                $this->assertContains( home_url( 'bar.js' ), $footer );
    200245                $this->assertContains( home_url( 'baz.js' ), $footer );
    201246        }
     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        }
    202268}