resourceloader: Simplify load.mock.php by removing includes dependency
authorTimo Tijhof <krinklemail@gmail.com>
Thu, 1 Mar 2018 01:45:45 +0000 (17:45 -0800)
committerTimo Tijhof <krinklemail@gmail.com>
Tue, 6 Mar 2018 23:59:13 +0000 (15:59 -0800)
It previously depended on Xml.php for Xml::encodeJsCall, which
in turn depends on FormatJson. Other Xml.php methods also depend
on Sanitizer, but that was carefully not triggered.

Avoid both of these by simply constructing the string inline,
and using json_encode() directly for the one variable parameter.

Also, fix the names of one of the ResourceLoaderTest cases for
dotless module names. It claims to have been added to cover a
regression fixed in r88706, but that commit seems rather unrelated.
A bit of searching revealed as the relevant commit instead.

Bug: T188076
Change-Id: I04851d0355227f3a6b79b8d41a51d4beadce0e80

tests/phpunit/includes/resourceloader/ResourceLoaderTest.php
tests/qunit/data/load.mock.php

index 0bc558a..4e9f539 100644 (file)
@@ -261,7 +261,7 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
                                'jquery.foo,bar|jquery.ui.baz,quux',
                        ],
                        [
-                               'Regression fixed in r88706 with dotless names',
+                               'Regression fixed in r87497 (7fee86c38e) with dotless names',
                                [ 'foo', 'bar', 'baz' ],
                                'foo,bar,baz',
                        ],
index 671bdf1..23fb4c9 100644 (file)
@@ -24,9 +24,6 @@
  */
 header( 'Content-Type: text/javascript; charset=utf-8' );
 
-require_once __DIR__ . '/../../../includes/json/FormatJson.php';
-require_once __DIR__ . '/../../../includes/Xml.php';
-
 $moduleImplementations = [
        'testUsesMissing' => "
 mw.loader.implement( 'testUsesMissing', function () {
@@ -66,7 +63,7 @@ if ( isset( $_GET['modules'] ) ) {
                if ( isset( $moduleImplementations[$module] ) ) {
                        $response .= $moduleImplementations[$module];
                } else {
-                       $response .= Xml::encodeJsCall( 'mw.loader.state', [ $module, 'missing' ], true );
+                       $response .= 'mw.loader.state(' . json_encode( $module ) . ', "missing" );' . "\n";
                }
        }
 }