MediaWiki  1.28.0
ResourceLoaderTestCase.php
Go to the documentation of this file.
1 <?php
2 
5 
6 abstract class ResourceLoaderTestCase extends MediaWikiTestCase {
7  // Version hash for a blank file module.
8  // Result of ResourceLoader::makeHash(), ResourceLoaderTestModule
9  // and ResourceLoaderFileModule::getDefinitionSummary().
10  const BLANK_VERSION = '09p30q0';
11 
17  protected function getResourceLoaderContext( $lang = 'en', $dir = 'ltr' ) {
19  $request = new FauxRequest( [
20  'lang' => $lang,
21  'modules' => 'startup',
22  'only' => 'scripts',
23  'skin' => 'vector',
24  'target' => 'phpunit',
25  ] );
26  $ctx = $this->getMockBuilder( 'ResourceLoaderContext' )
27  ->setConstructorArgs( [ $resourceLoader, $request ] )
28  ->setMethods( [ 'getDirection' ] )
29  ->getMock();
30  $ctx->method( 'getDirection' )->willReturn( $dir );
31  return $ctx;
32  }
33 
34  public static function getSettings() {
35  return [
36  // For ResourceLoader::inDebugMode since it doesn't have context
37  'ResourceLoaderDebug' => true,
38 
39  // Avoid influence from wgInvalidateCacheOnLocalSettingsChange
40  'CacheEpoch' => '20140101000000',
41 
42  // For ResourceLoader::__construct()
43  'ResourceLoaderSources' => [],
44 
45  // For wfScript()
46  'ScriptPath' => '/w',
47  'ScriptExtension' => '.php',
48  'Script' => '/w/index.php',
49  'LoadScript' => '/w/load.php',
50  ];
51  }
52 
53  protected function setUp() {
54  parent::setUp();
55 
57 
58  $globals = [];
59  foreach ( self::getSettings() as $key => $value ) {
60  $globals['wg' . $key] = $value;
61  }
62  $this->setMwGlobals( $globals );
63  }
64 }
65 
66 /* Stubs */
67 
69  protected $messages = [];
70  protected $dependencies = [];
71  protected $group = null;
72  protected $source = 'local';
73  protected $position = 'bottom';
74  protected $script = '';
75  protected $styles = '';
76  protected $skipFunction = null;
77  protected $isRaw = false;
78  protected $isKnownEmpty = false;
80  protected $targets = [ 'phpunit' ];
81 
82  public function __construct( $options = [] ) {
83  foreach ( $options as $key => $value ) {
84  $this->$key = $value;
85  }
86  }
87 
89  return $this->validateScriptFile( 'input', $this->script );
90  }
91 
93  return [ '' => $this->styles ];
94  }
95 
96  public function getMessages() {
97  return $this->messages;
98  }
99 
100  public function getDependencies( ResourceLoaderContext $context = null ) {
101  return $this->dependencies;
102  }
103 
104  public function getGroup() {
105  return $this->group;
106  }
107 
108  public function getSource() {
109  return $this->source;
110  }
111  public function getPosition() {
112  return $this->position;
113  }
114 
115  public function getType() {
116  return $this->type;
117  }
118 
119  public function getSkipFunction() {
120  return $this->skipFunction;
121  }
122 
123  public function isRaw() {
124  return $this->isRaw;
125  }
127  return $this->isKnownEmpty;
128  }
129 
130  public function enableModuleContentVersion() {
131  return true;
132  }
133 }
134 
136 }
137 
139  // TODO: This won't be needed once ResourceLoader is empty by default
140  // and default registrations are done from ServiceWiring instead.
141  public function __construct( Config $config = null, LoggerInterface $logger = null ) {
142  $this->setLogger( $logger ?: new NullLogger() );
143  $this->config = $config ?: ConfigFactory::getDefaultInstance()->makeConfig( 'main' );
144  $this->setMessageBlobStore( new MessageBlobStore( $this, $this->getLogger() ) );
145  }
146 }
__construct(Config $config=null, LoggerInterface $logger=null)
This class generates message blobs for use by ResourceLoader modules.
getDependencies(ResourceLoaderContext $context=null)
$context
Definition: load.php:50
if(count($args)==0) $dir
Abstraction for ResourceLoader modules, with name registration and maxage functionality.
error also a ContextSource you ll probably need to make sure the header is varied on such as when responding to a resource loader request or generating HTML output & $resourceLoader
Definition: hooks.txt:2573
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
if(!isset($args[0])) $lang
$value
isKnownEmpty(ResourceLoaderContext $context)
getResourceLoaderContext($lang= 'en', $dir= 'ltr')
validateScriptFile($fileName, $contents)
Validate a given script file; if valid returns the original source.
ResourceLoader module based on local JavaScript/CSS files.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition: hooks.txt:1046
setMessageBlobStore(MessageBlobStore $blobStore)
getScript(ResourceLoaderContext $context)
getStyles(ResourceLoaderContext $context)
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
static getDefaultInstance()
static clearCache()
Reset static members used for caching.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2573
setLogger(LoggerInterface $logger)
LoggerInterface $logger
setMwGlobals($pairs, $value=null)
Dynamic JavaScript and CSS resource loading system.
Object passed around to modules which contains information about the state of a specific loader reque...