MediaWiki  1.27.1
ResourceLoaderTestCase.php
Go to the documentation of this file.
1 <?php
2 
3 abstract class ResourceLoaderTestCase extends MediaWikiTestCase {
9  protected function getResourceLoaderContext( $lang = 'en', $dir = 'ltr' ) {
11  $request = new FauxRequest( [
12  'lang' => $lang,
13  'modules' => 'startup',
14  'only' => 'scripts',
15  'skin' => 'vector',
16  'target' => 'phpunit',
17  ] );
18  $ctx = $this->getMockBuilder( 'ResourceLoaderContext' )
19  ->setConstructorArgs( [ $resourceLoader, $request ] )
20  ->setMethods( [ 'getDirection' ] )
21  ->getMock();
22  $ctx->expects( $this->any() )->method( 'getDirection' )->will(
23  $this->returnValue( $dir )
24  );
25  return $ctx;
26  }
27 
28  public static function getSettings() {
29  return [
30  // For ResourceLoader::inDebugMode since it doesn't have context
31  'ResourceLoaderDebug' => true,
32 
33  // Avoid influence from wgInvalidateCacheOnLocalSettingsChange
34  'CacheEpoch' => '20140101000000',
35 
36  // For ResourceLoader::__construct()
37  'ResourceLoaderSources' => [],
38 
39  // For wfScript()
40  'ScriptPath' => '/w',
41  'ScriptExtension' => '.php',
42  'Script' => '/w/index.php',
43  'LoadScript' => '/w/load.php',
44  ];
45  }
46 
47  protected function setUp() {
48  parent::setUp();
49 
51 
52  $globals = [];
53  foreach ( self::getSettings() as $key => $value ) {
54  $globals['wg' . $key] = $value;
55  }
56  $this->setMwGlobals( $globals );
57  }
58 }
59 
60 /* Stubs */
61 
63  protected $messages = [];
64  protected $dependencies = [];
65  protected $group = null;
66  protected $source = 'local';
67  protected $script = '';
68  protected $styles = '';
69  protected $skipFunction = null;
70  protected $isRaw = false;
71  protected $targets = [ 'phpunit' ];
72 
73  public function __construct( $options = [] ) {
74  foreach ( $options as $key => $value ) {
75  $this->$key = $value;
76  }
77  }
78 
80  return $this->validateScriptFile( 'input', $this->script );
81  }
82 
84  return [ '' => $this->styles ];
85  }
86 
87  public function getMessages() {
88  return $this->messages;
89  }
90 
91  public function getDependencies( ResourceLoaderContext $context = null ) {
92  return $this->dependencies;
93  }
94 
95  public function getGroup() {
96  return $this->group;
97  }
98 
99  public function getSource() {
100  return $this->source;
101  }
102 
103  public function getSkipFunction() {
104  return $this->skipFunction;
105  }
106 
107  public function isRaw() {
108  return $this->isRaw;
109  }
110 
111  public function enableModuleContentVersion() {
112  return true;
113  }
114 }
115 
117 }
getDependencies(ResourceLoaderContext $context=null)
magic word the default is to use $key to get the and $key value or $key value text $key value html to format the value $key
Definition: hooks.txt:2321
$context
Definition: load.php:44
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:2418
if(!isset($args[0])) $lang
$value
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:1004
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 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:2418
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...