Merge "content: Use "::class" when overriding TextContent::getContentClass()"
[lhc/web/wiklou.git] / tests / phpunit / ResourceLoaderTestCase.php
1 <?php
2
3 abstract class ResourceLoaderTestCase extends MediaWikiTestCase {
4 /**
5 * @param string $lang
6 * @param string $dir
7 * @return ResourceLoaderContext
8 */
9 protected function getResourceLoaderContext( $lang = 'en', $dir = 'ltr' ) {
10 $resourceLoader = new ResourceLoader();
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
50 ResourceLoader::clearCache();
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
62 class ResourceLoaderTestModule extends ResourceLoaderModule {
63 protected $messages = [];
64 protected $dependencies = [];
65 protected $group = null;
66 protected $source = 'local';
67 protected $position = 'bottom';
68 protected $script = '';
69 protected $styles = '';
70 protected $skipFunction = null;
71 protected $isRaw = false;
72 protected $isKnownEmpty = false;
73 protected $type = ResourceLoaderModule::LOAD_GENERAL;
74 protected $targets = [ 'phpunit' ];
75
76 public function __construct( $options = [] ) {
77 foreach ( $options as $key => $value ) {
78 $this->$key = $value;
79 }
80 }
81
82 public function getScript( ResourceLoaderContext $context ) {
83 return $this->validateScriptFile( 'input', $this->script );
84 }
85
86 public function getStyles( ResourceLoaderContext $context ) {
87 return [ '' => $this->styles ];
88 }
89
90 public function getMessages() {
91 return $this->messages;
92 }
93
94 public function getDependencies( ResourceLoaderContext $context = null ) {
95 return $this->dependencies;
96 }
97
98 public function getGroup() {
99 return $this->group;
100 }
101
102 public function getSource() {
103 return $this->source;
104 }
105 public function getPosition() {
106 return $this->position;
107 }
108
109 public function getType() {
110 return $this->type;
111 }
112
113 public function getSkipFunction() {
114 return $this->skipFunction;
115 }
116
117 public function isRaw() {
118 return $this->isRaw;
119 }
120 public function isKnownEmpty( ResourceLoaderContext $context ) {
121 return $this->isKnownEmpty;
122 }
123
124 public function enableModuleContentVersion() {
125 return true;
126 }
127 }
128
129 class ResourceLoaderFileModuleTestModule extends ResourceLoaderFileModule {
130 }