Merge "resourceloader: Condition-wrap the HTML tag instead of JS response"
[lhc/web/wiklou.git] / tests / phpunit / ResourceLoaderTestCase.php
1 <?php
2
3 abstract class ResourceLoaderTestCase extends MediaWikiTestCase {
4 protected static function getResourceLoaderContext( $lang = 'en' ) {
5 $resourceLoader = new ResourceLoader();
6 $request = new FauxRequest( array(
7 'lang' => $lang,
8 'modules' => 'startup',
9 'only' => 'scripts',
10 'skin' => 'vector',
11 'target' => 'test',
12 ) );
13 return new ResourceLoaderContext( $resourceLoader, $request );
14 }
15
16 protected function setUp() {
17 parent::setUp();
18
19 ResourceLoader::clearCache();
20
21 $this->setMwGlobals( array(
22 // For ResourceLoader::inDebugMode since it doesn't have context
23 'wgResourceLoaderDebug' => true,
24
25 // Avoid influence from wgInvalidateCacheOnLocalSettingsChange
26 'wgCacheEpoch' => '20140101000000',
27
28 // For ResourceLoader::__construct()
29 'wgResourceLoaderSources' => array(),
30
31 // For wfScript()
32 'wgScriptPath' => '/w',
33 'wgScriptExtension' => '.php',
34 'wgScript' => '/w/index.php',
35 'wgLoadScript' => '/w/load.php',
36 ) );
37 }
38 }
39
40 /* Stubs */
41
42 class ResourceLoaderTestModule extends ResourceLoaderModule {
43 protected $dependencies = array();
44 protected $group = null;
45 protected $source = 'local';
46 protected $script = '';
47 protected $styles = '';
48 protected $skipFunction = null;
49 protected $isRaw = false;
50 protected $targets = array( 'test' );
51
52 public function __construct( $options = array() ) {
53 foreach ( $options as $key => $value ) {
54 $this->$key = $value;
55 }
56 }
57
58 public function getScript( ResourceLoaderContext $context ) {
59 return $this->script;
60 }
61
62 public function getStyles( ResourceLoaderContext $context ) {
63 return array( '' => $this->styles );
64 }
65
66 public function getDependencies() {
67 return $this->dependencies;
68 }
69
70 public function getGroup() {
71 return $this->group;
72 }
73
74 public function getSource() {
75 return $this->source;
76 }
77
78 public function getSkipFunction() {
79 return $this->skipFunction;
80 }
81
82 public function isRaw() {
83 return $this->isRaw;
84 }
85 }
86
87 class ResourceLoaderFileModuleTestModule extends ResourceLoaderFileModule {
88 }
89
90 class ResourceLoaderWikiModuleTestModule extends ResourceLoaderWikiModule {
91 // Override expected via PHPUnit mocks and stubs
92 protected function getPages( ResourceLoaderContext $context ) {
93 return array();
94 }
95 }