X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=tests%2Fphpunit%2FResourceLoaderTestCase.php;h=68b91bf3a419e14afc3fe080acc232a3027d4fc1;hb=434ff86050115d4e1e3d61a23754815ebd7aeac6;hp=baa481e51c61becffd636db0c3d82d0ba8bcdce1;hpb=82dff2f46c95d527de8a1fd32961c22832eb5444;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/ResourceLoaderTestCase.php b/tests/phpunit/ResourceLoaderTestCase.php index baa481e51c..68b91bf3a4 100644 --- a/tests/phpunit/ResourceLoaderTestCase.php +++ b/tests/phpunit/ResourceLoaderTestCase.php @@ -11,16 +11,30 @@ 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', + 'modules' => 'startup', + 'only' => 'scripts', + ]; + $resourceLoader = $rl ?: new ResourceLoader(); $request = new FauxRequest( [ - 'lang' => $lang, - 'modules' => 'startup', - 'only' => 'scripts', + 'lang' => $options['lang'], + 'modules' => $options['modules'], + 'only' => $options['only'], 'skin' => 'vector', 'target' => 'phpunit', ] ); @@ -28,7 +42,7 @@ abstract class ResourceLoaderTestCase extends MediaWikiTestCase { ->setConstructorArgs( [ $resourceLoader, $request ] ) ->setMethods( [ 'getDirection' ] ) ->getMock(); - $ctx->method( 'getDirection' )->willReturn( $dir ); + $ctx->method( 'getDirection' )->willReturn( $options['dir'] ); return $ctx; } @@ -142,6 +156,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; + } }