Merge "resourceloader: Move style deprecation warnings to <body>"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 24 May 2018 13:03:21 +0000 (13:03 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 24 May 2018 13:03:21 +0000 (13:03 +0000)
includes/resourceloader/ResourceLoaderClientHtml.php
tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php

index 3ba63cf..b49a2da 100644 (file)
@@ -146,7 +146,7 @@ class ResourceLoaderClientHtml {
                                'general' => [],
                        ],
                        // Deprecations for style-only modules
-                       'styledeprecations' => [],
+                       'styleDeprecations' => [],
                ];
 
                foreach ( $this->modules as $name ) {
@@ -213,7 +213,7 @@ class ResourceLoaderClientHtml {
                        }
                        $deprecation = $module->getDeprecationInformation();
                        if ( $deprecation ) {
-                               $data['styledeprecations'][] = $deprecation;
+                               $data['styleDeprecations'][] = $deprecation;
                        }
                }
 
@@ -318,14 +318,6 @@ class ResourceLoaderClientHtml {
                        );
                }
 
-               // Deprecations for only=styles modules
-               if ( $data['styledeprecations'] ) {
-                       $chunks[] = ResourceLoader::makeInlineScript(
-                               implode( '', $data['styledeprecations'] ),
-                               $nonce
-                       );
-               }
-
                // External stylesheets (only=styles)
                if ( $data['styles'] ) {
                        $chunks[] = $this->getLoad(
@@ -366,7 +358,18 @@ class ResourceLoaderClientHtml {
         * @return string|WrappedStringList HTML
         */
        public function getBodyHtml() {
-               return '';
+               $data = $this->getData();
+               $chunks = [];
+
+               // Deprecations for only=styles modules
+               if ( $data['styleDeprecations'] ) {
+                       $chunks[] = ResourceLoader::makeInlineScript(
+                               implode( '', $data['styleDeprecations'] ),
+                               $this->options['nonce']
+                       );
+               }
+
+               return WrappedStringList::join( "\n", $chunks );
        }
 
        private function getContext( $group, $type ) {
index 9b03c5c..7cd6983 100644 (file)
@@ -176,7 +176,7 @@ class ResourceLoaderClientHtmlTest extends PHPUnit\Framework\TestCase {
                                        'test.user',
                                ],
                        ],
-                       'styledeprecations' => [
+                       'styleDeprecations' => [
                                Xml::encodeJsCall(
                                        'mw.log.warn',
                                        [ 'This page is using the deprecated ResourceLoader module "test.styles.deprecated".
@@ -228,7 +228,6 @@ Deprecation message.' ]
                        . 'mw.loader.implement("test.private@{blankVer}",function($,jQuery,require,module){},{"css":[]});'
                        . 'mw.loader.load(["test"]);'
                        . 'mw.loader.load("/w/load.php?debug=false\u0026lang=nl\u0026modules=test.scripts\u0026only=scripts\u0026skin=fallback");'
-                       . 'mw.log.warn("This page is using the deprecated ResourceLoader module \"test.styles.deprecated\".\nDeprecation message.");'
                        . '});</script>' . "\n"
                        . '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=nl&amp;modules=test.styles.deprecated%2Cpure&amp;only=styles&amp;skin=fallback"/>' . "\n"
                        . '<style>.private{}</style>' . "\n"
@@ -304,18 +303,23 @@ Deprecation message.' ]
                $context = self::makeContext();
                $context->getResourceLoader()->register( self::makeSampleModules() );
 
-               $client = new ResourceLoaderClientHtml( $context );
+               $client = new ResourceLoaderClientHtml( $context, [ 'nonce' => false ] );
                $client->setConfig( [ 'key' => 'value' ] );
                $client->setModules( [
                        'test',
                        'test.private.bottom',
                ] );
+               $client->setModuleStyles( [
+                       'test.styles.deprecated',
+               ] );
                $client->setModuleScripts( [
                        'test.scripts',
                ] );
-
-               $expected = '';
-               $expected = self::expandVariables( $expected );
+               // phpcs:disable Generic.Files.LineLength
+               $expected = '<script>(window.RLQ=window.RLQ||[]).push(function(){'
+                       . 'mw.log.warn("This page is using the deprecated ResourceLoader module \"test.styles.deprecated\".\nDeprecation message.");'
+                       . '});</script>';
+               // phpcs:enable
 
                $this->assertEquals( $expected, $client->getBodyHtml() );
        }