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->expects( $this->any() )->method( 'getDirection' )->will(
26 $this->returnValue( $dir )
31 public static function getSettings() {
33 // For ResourceLoader::inDebugMode since it doesn't have context
34 'ResourceLoaderDebug' => true,
36 // Avoid influence from wgInvalidateCacheOnLocalSettingsChange
37 'CacheEpoch' => '20140101000000',
39 // For ResourceLoader::__construct()
40 'ResourceLoaderSources' => [],
44 'ScriptExtension' => '.php',
45 'Script' => '/w/index.php',
46 'LoadScript' => '/w/load.php',
50 protected function setUp() {
53 ResourceLoader
::clearCache();
56 foreach ( self
::getSettings() as $key => $value ) {
57 $globals['wg' . $key] = $value;
59 $this->setMwGlobals( $globals );
65 class ResourceLoaderTestModule
extends ResourceLoaderModule
{
66 protected $messages = [];
67 protected $dependencies = [];
68 protected $group = null;
69 protected $source = 'local';
70 protected $position = 'bottom';
71 protected $script = '';
72 protected $styles = '';
73 protected $skipFunction = null;
74 protected $isRaw = false;
75 protected $isKnownEmpty = false;
76 protected $type = ResourceLoaderModule
::LOAD_GENERAL
;
77 protected $targets = [ 'phpunit' ];
79 public function __construct( $options = [] ) {
80 foreach ( $options as $key => $value ) {
85 public function getScript( ResourceLoaderContext
$context ) {
86 return $this->validateScriptFile( 'input', $this->script
);
89 public function getStyles( ResourceLoaderContext
$context ) {
90 return [ '' => $this->styles
];
93 public function getMessages() {
94 return $this->messages
;
97 public function getDependencies( ResourceLoaderContext
$context = null ) {
98 return $this->dependencies
;
101 public function getGroup() {
105 public function getSource() {
106 return $this->source
;
108 public function getPosition() {
109 return $this->position
;
112 public function getType() {
116 public function getSkipFunction() {
117 return $this->skipFunction
;
120 public function isRaw() {
123 public function isKnownEmpty( ResourceLoaderContext
$context ) {
124 return $this->isKnownEmpty
;
127 public function enableModuleContentVersion() {
132 class ResourceLoaderFileModuleTestModule
extends ResourceLoaderFileModule
{
135 class EmptyResourceLoader
extends ResourceLoader
{
136 // TODO: This won't be needed once ResourceLoader is empty by default
137 // and default registrations are done from ServiceWiring instead.
138 public function __construct( Config
$config = null, LoggerInterface
$logger = null ) {
139 $this->setLogger( $logger ?
: new NullLogger() );
140 $this->config
= $config ?
: ConfigFactory
::getDefaultInstance()->makeConfig( 'main' );
141 $this->setMessageBlobStore( new MessageBlobStore( $this, $this->getLogger() ) );