3 use Psr\Log\LoggerInterface
;
4 use Psr\Log\NullLogger
;
6 abstract class ResourceLoaderTestCase
extends MediaWikiTestCase
{
10 * @return ResourceLoaderContext
12 protected function getResourceLoaderContext( $lang = 'en', $dir = 'ltr' ) {
13 $resourceLoader = new ResourceLoader();
14 $request = new FauxRequest( [
16 'modules' => 'startup',
19 'target' => 'phpunit',
21 $ctx = $this->getMockBuilder( 'ResourceLoaderContext' )
22 ->setConstructorArgs( [ $resourceLoader, $request ] )
23 ->setMethods( [ 'getDirection' ] )
25 $ctx->method( 'getDirection' )->willReturn( $dir );
29 public static function getSettings() {
31 // For ResourceLoader::inDebugMode since it doesn't have context
32 'ResourceLoaderDebug' => true,
34 // Avoid influence from wgInvalidateCacheOnLocalSettingsChange
35 'CacheEpoch' => '20140101000000',
37 // For ResourceLoader::__construct()
38 'ResourceLoaderSources' => [],
42 'ScriptExtension' => '.php',
43 'Script' => '/w/index.php',
44 'LoadScript' => '/w/load.php',
48 protected function setUp() {
51 ResourceLoader
::clearCache();
54 foreach ( self
::getSettings() as $key => $value ) {
55 $globals['wg' . $key] = $value;
57 $this->setMwGlobals( $globals );
63 class ResourceLoaderTestModule
extends ResourceLoaderModule
{
64 protected $messages = [];
65 protected $dependencies = [];
66 protected $group = null;
67 protected $source = 'local';
68 protected $position = 'bottom';
69 protected $script = '';
70 protected $styles = '';
71 protected $skipFunction = null;
72 protected $isRaw = false;
73 protected $isKnownEmpty = false;
74 protected $type = ResourceLoaderModule
::LOAD_GENERAL
;
75 protected $targets = [ 'phpunit' ];
77 public function __construct( $options = [] ) {
78 foreach ( $options as $key => $value ) {
83 public function getScript( ResourceLoaderContext
$context ) {
84 return $this->validateScriptFile( 'input', $this->script
);
87 public function getStyles( ResourceLoaderContext
$context ) {
88 return [ '' => $this->styles
];
91 public function getMessages() {
92 return $this->messages
;
95 public function getDependencies( ResourceLoaderContext
$context = null ) {
96 return $this->dependencies
;
99 public function getGroup() {
103 public function getSource() {
104 return $this->source
;
106 public function getPosition() {
107 return $this->position
;
110 public function getType() {
114 public function getSkipFunction() {
115 return $this->skipFunction
;
118 public function isRaw() {
121 public function isKnownEmpty( ResourceLoaderContext
$context ) {
122 return $this->isKnownEmpty
;
125 public function enableModuleContentVersion() {
130 class ResourceLoaderFileModuleTestModule
extends ResourceLoaderFileModule
{
133 class EmptyResourceLoader
extends ResourceLoader
{
134 // TODO: This won't be needed once ResourceLoader is empty by default
135 // and default registrations are done from ServiceWiring instead.
136 public function __construct( Config
$config = null, LoggerInterface
$logger = null ) {
137 $this->setLogger( $logger ?
: new NullLogger() );
138 $this->config
= $config ?
: ConfigFactory
::getDefaultInstance()->makeConfig( 'main' );
139 $this->setMessageBlobStore( new MessageBlobStore( $this, $this->getLogger() ) );