Make WordPress Core

Ticket #45066: 45066.8.diff

File 45066.8.diff, 6.4 KB (added by sstoqnov, 5 years ago)

Replace wp-a11y.js with @wordpress/a11y & fix failing tests

  • src/wp-admin/includes/update-core.php

     
    785785        // 5.1
    786786        'wp-includes/random_compat/random_bytes_openssl.php',
    787787        'wp-includes/js/tinymce/wp-tinymce.js.gz',
     788        // 5.3
     789        'wp-includes/js/wp-a11y.js', // Moved to: wp-includes/js/dist/a11y.js
     790        'wp-includes/js/wp-a11y.min.js', // Moved to: wp-includes/js/dist/a11y.min.js
    788791);
    789792
    790793/**
  • src/wp-includes/script-loader.php

     
    879879                )
    880880        );
    881881
    882         $scripts->add( 'wp-a11y', "/wp-includes/js/wp-a11y$suffix.js", array( 'jquery' ), false, 1 );
    883 
    884882        $scripts->add( 'sack', "/wp-includes/js/tw-sack$suffix.js", array(), '1.6.1', 1 );
    885883
    886884        $scripts->add( 'quicktags', "/wp-includes/js/quicktags$suffix.js", array(), false, 1 );
  • tests/phpunit/tests/dependencies/scripts.php

     
    687687                global $wp_scripts;
    688688
    689689                wp_default_scripts( $wp_scripts );
     690                wp_default_packages( $wp_scripts );
    690691
    691692                $wp_scripts->base_url  = '';
    692693                $wp_scripts->do_concat = true;
    693694
    694695                $ver       = get_bloginfo( 'version' );
    695                 $expected  = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&amp;load%5B%5D=jquery-core,jquery-migrate,wp-a11y&amp;ver={$ver}'></script>\n";
     696
     697                $expected = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&amp;load%5B%5D=jquery-core,jquery-migrate&amp;ver={$ver}'></script>\n";
    696698                $expected .= "<script type='text/javascript'>\nconsole.log(\"before\");\n</script>\n";
    697                 $expected .= "<script type='text/javascript' src='http://example.com'></script>\n";
    698                 $expected .= "<script type='text/javascript' src='http://example2.com'></script>\n";
     699                $expected .= "<script type='text/javascript' src='http://example.org'></script>\n";
     700                $expected .= "<script type='text/javascript' src='/wp-includes/js/dist/vendor/wp-polyfill.min.js'></script>\n";
     701                $expected .= "<script type='text/javascript'>\n";
     702                $expected .= "( 'fetch' in window ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-fetch.min.js\"></scr' + 'ipt>' );( document.contains ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-node-contains.min.js\"></scr' + 'ipt>' );( window.FormData && window.FormData.prototype.keys ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-formdata.min.js\"></scr' + 'ipt>' );( Element.prototype.matches && Element.prototype.closest ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-element-closest.min.js\"></scr' + 'ipt>' );\n";
     703                $expected .= "</script>\n";
     704                $expected .= "<script type='text/javascript' src='/wp-includes/js/dist/dom-ready.min.js'></script>\n";
     705                $expected .= "<script type='text/javascript' src='/wp-includes/js/dist/a11y.min.js'></script>\n";
     706                $expected .= "<script type='text/javascript' src='http://example2.org'></script>\n";
    699707                $expected .= "<script type='text/javascript'>\nconsole.log(\"after\");\n</script>\n";
    700708
    701                 wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null );
     709                wp_enqueue_script( 'test-example', 'http://example.org', array( 'jquery' ), null );
    702710                wp_add_inline_script( 'test-example', 'console.log("before");', 'before' );
    703                 wp_enqueue_script( 'test-example2', 'http://example2.com', array( 'wp-a11y' ), null );
     711                wp_enqueue_script( 'test-example2', 'http://example2.org', array( 'wp-a11y' ), null );
    704712                wp_add_inline_script( 'test-example2', 'console.log("after");', 'after' );
    705713
     714                // Open a buffer to get the output of `wp_print_scripts`.
     715                ob_start();
    706716                wp_print_scripts();
    707                 $print_scripts = get_echo( '_print_scripts' );
     717                $print_scripts = ob_get_clean();
    708718
     719                // We've replaced wp-a11y.js with @wordpress/a11y package (see 45066)
     720                // and `wp-polyfill` is now a dependency of the packaged wp-a11y.
     721                // The packaged scipts contain various version numbers, which are
     722                // not exposed, so we will remove all version args from the output.
     723                $print_scripts = preg_replace(
     724                        '~js\?ver=([^"\']*)~', // Matches `js?ver=X.X.X` and everything to single or double quote.
     725                        'js', // The replacement, `js` without the version arg.
     726                        $print_scripts // Printed scripts.
     727                );
     728
     729                // Check if expected and printed scripts are equal.
    709730                $this->assertEquals( $expected, $print_scripts );
    710731        }
    711732
     
    716737                global $wp_scripts;
    717738
    718739                wp_default_scripts( $wp_scripts );
     740                wp_default_packages( $wp_scripts );
    719741
    720742                $wp_scripts->base_url  = '';
    721743                $wp_scripts->do_concat = true;
    722744
    723                 $expected_tail  = "<![endif]-->\n";
    724                 $expected_tail .= "<script type='text/javascript' src='/customize-dependency.js'></script>\n";
     745                $expected_tail = "<script type='text/javascript' src='/customize-dependency.js'></script>\n";
    725746                $expected_tail .= "<script type='text/javascript'>\n";
    726747                $expected_tail .= "tryCustomizeDependency()\n";
    727748                $expected_tail .= "</script>\n";
     
    730751                wp_enqueue_script( $handle, '/customize-dependency.js', array( 'customize-controls' ), null );
    731752                wp_add_inline_script( $handle, 'tryCustomizeDependency()' );
    732753
     754                // Open a buffer to get the output of `wp_print_scripts`.
     755                ob_start();
    733756                wp_print_scripts();
    734                 $print_scripts = get_echo( '_print_scripts' );
     757                $print_scripts = ob_get_clean();
    735758
    736                 $tail = substr( $print_scripts, strrpos( $print_scripts, '<![endif]-->' ) );
     759                $tail = substr( $print_scripts, strrpos( $print_scripts, "<script type='text/javascript' src='/customize-dependency.js'>" ) );
    737760                $this->assertEquals( $expected_tail, $tail );
    738761        }
    739762
  • tests/qunit/index.html

     
    2424                        };
    2525                </script>
    2626                <script src="../../build/wp-includes/js/wp-util.js"></script>
    27                 <script src="../../build/wp-includes/js/wp-a11y.js"></script>
     27                <script src="../../build/wp-includes/js/dist/a11y.js"></script>
    2828                <script>
    2929                        window._wpMediaModelsL10n = {"settings":{"ajaxurl":"\/wp-admin\/admin-ajax.php","post":{"id":0}}};
    3030                </script>