Merge "Show protection log on creation-protected pages"
[lhc/web/wiklou.git] / tests / phpunit / ResourceLoaderTestCase.php
index 45cfdbf..f75cc22 100644 (file)
@@ -14,9 +14,12 @@ abstract class ResourceLoaderTestCase extends MediaWikiTestCase {
         * @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( $options = [] ) {
+       protected function getResourceLoaderContext( $options = [], ResourceLoader $rl = null ) {
                if ( is_string( $options ) ) {
                        // Back-compat for extension tests
                        $options = [ 'lang' => $options ];
@@ -24,13 +27,16 @@ abstract class ResourceLoaderTestCase extends MediaWikiTestCase {
                $options += [
                        'lang' => 'en',
                        'dir' => 'ltr',
+                       'skin' => 'vector',
+                       'modules' => 'startup',
+                       'only' => 'scripts',
                ];
-               $resourceLoader = new ResourceLoader();
+               $resourceLoader = $rl ?: new ResourceLoader();
                $request = new FauxRequest( [
                                'lang' => $options['lang'],
-                               'modules' => 'startup',
-                               'only' => 'scripts',
-                               'skin' => 'vector',
+                               'modules' => $options['modules'],
+                               'only' => $options['only'],
+                               'skin' => $options['skin'],
                                'target' => 'phpunit',
                ] );
                $ctx = $this->getMockBuilder( 'ResourceLoaderContext' )
@@ -88,6 +94,7 @@ class ResourceLoaderTestModule extends ResourceLoaderModule {
        protected $isKnownEmpty = false;
        protected $type = ResourceLoaderModule::LOAD_GENERAL;
        protected $targets = [ 'phpunit' ];
+       protected $shouldEmbed = null;
 
        public function __construct( $options = [] ) {
                foreach ( $options as $key => $value ) {
@@ -137,11 +144,31 @@ class ResourceLoaderTestModule extends ResourceLoaderModule {
                return $this->isKnownEmpty;
        }
 
+       public function shouldEmbedModule( ResourceLoaderContext $context ) {
+               return $this->shouldEmbed !== null ? $this->shouldEmbed : parent::shouldEmbedModule( $context );
+       }
+
        public function enableModuleContentVersion() {
                return true;
        }
 }
 
+class ResourceLoaderFileTestModule extends ResourceLoaderFileModule {
+       protected $lessVars = [];
+
+       public function __construct( $options = [], $test = [] ) {
+               parent::__construct( $options );
+
+               foreach ( $test as $key => $value ) {
+                       $this->$key = $value;
+               }
+       }
+
+       public function getLessVars( ResourceLoaderContext $context ) {
+               return $this->lessVars;
+       }
+}
+
 class ResourceLoaderFileModuleTestModule extends ResourceLoaderFileModule {
 }
 
@@ -151,6 +178,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;
+       }
 }