Merge "Add mediastatistics-header-3d"
[lhc/web/wiklou.git] / tests / phpunit / ResourceLoaderTestCase.php
index baa481e..a8a8f4d 100644 (file)
@@ -11,24 +11,39 @@ abstract class ResourceLoaderTestCase extends MediaWikiTestCase {
        const BLANK_VERSION = '09p30q0';
 
        /**
-        * @param string $lang
-        * @param string $dir
+        * @param array|string $options Language code or options array
+        * - string 'lang' Language code
+        * - string 'dir' Language direction (ltr or rtl)
+        * - string 'modules' Pipe-separated list of module names
+        * - string|null 'only' "scripts" (unwrapped script), "styles" (stylesheet), or null
+        *    (mw.loader.implement).
         * @return ResourceLoaderContext
         */
-       protected function getResourceLoaderContext( $lang = 'en', $dir = 'ltr' ) {
-               $resourceLoader = new ResourceLoader();
+       protected function getResourceLoaderContext( $options = [], ResourceLoader $rl = null ) {
+               if ( is_string( $options ) ) {
+                       // Back-compat for extension tests
+                       $options = [ 'lang' => $options ];
+               }
+               $options += [
+                       'lang' => 'en',
+                       'dir' => 'ltr',
+                       'skin' => 'vector',
+                       'modules' => 'startup',
+                       'only' => 'scripts',
+               ];
+               $resourceLoader = $rl ?: new ResourceLoader();
                $request = new FauxRequest( [
-                               'lang' => $lang,
-                               'modules' => 'startup',
-                               'only' => 'scripts',
-                               'skin' => 'vector',
+                               'lang' => $options['lang'],
+                               'modules' => $options['modules'],
+                               'only' => $options['only'],
+                               'skin' => $options['skin'],
                                'target' => 'phpunit',
                ] );
                $ctx = $this->getMockBuilder( 'ResourceLoaderContext' )
                        ->setConstructorArgs( [ $resourceLoader, $request ] )
                        ->setMethods( [ 'getDirection' ] )
                        ->getMock();
-               $ctx->method( 'getDirection' )->willReturn( $dir );
+               $ctx->method( 'getDirection' )->willReturn( $options['dir'] );
                return $ctx;
        }
 
@@ -142,6 +157,12 @@ class EmptyResourceLoader extends ResourceLoader {
        public function __construct( Config $config = null, LoggerInterface $logger = null ) {
                $this->setLogger( $logger ?: new NullLogger() );
                $this->config = $config ?: MediaWikiServices::getInstance()->getMainConfig();
+               // Source "local" is required by StartupModule
+               $this->addSource( 'local', $this->config->get( 'LoadScript' ) );
                $this->setMessageBlobStore( new MessageBlobStore( $this, $this->getLogger() ) );
        }
+
+       public function getErrors() {
+               return $this->errors;
+       }
 }