resourceloader: Implement '$pages' parameter to ResourceLoaderWikiModule constructor
[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( array(
12 'lang' => $lang,
13 'modules' => 'startup',
14 'only' => 'scripts',
15 'skin' => 'vector',
16 'target' => 'test',
17 ) );
18 $ctx = $this->getMockBuilder( 'ResourceLoaderContext' )
19 ->setConstructorArgs( array( $resourceLoader, $request ) )
20 ->setMethods( array( 'getDirection' ) )
21 ->getMock();
22 $ctx->expects( $this->any() )->method( 'getDirection' )->will(
23 $this->returnValue( $dir )
24 );
25 return $ctx;
26 }
27
28 protected function setUp() {
29 parent::setUp();
30
31 ResourceLoader::clearCache();
32
33 $this->setMwGlobals( array(
34 // For ResourceLoader::inDebugMode since it doesn't have context
35 'wgResourceLoaderDebug' => true,
36
37 // Avoid influence from wgInvalidateCacheOnLocalSettingsChange
38 'wgCacheEpoch' => '20140101000000',
39
40 // For ResourceLoader::__construct()
41 'wgResourceLoaderSources' => array(),
42
43 // For wfScript()
44 'wgScriptPath' => '/w',
45 'wgScriptExtension' => '.php',
46 'wgScript' => '/w/index.php',
47 'wgLoadScript' => '/w/load.php',
48 ) );
49 }
50 }
51
52 /* Stubs */
53
54 class ResourceLoaderTestModule extends ResourceLoaderModule {
55 protected $dependencies = array();
56 protected $group = null;
57 protected $source = 'local';
58 protected $script = '';
59 protected $styles = '';
60 protected $skipFunction = null;
61 protected $isRaw = false;
62 protected $targets = array( 'test' );
63
64 public function __construct( $options = array() ) {
65 foreach ( $options as $key => $value ) {
66 $this->$key = $value;
67 }
68 }
69
70 public function getScript( ResourceLoaderContext $context ) {
71 return $this->script;
72 }
73
74 public function getStyles( ResourceLoaderContext $context ) {
75 return array( '' => $this->styles );
76 }
77
78 public function getDependencies() {
79 return $this->dependencies;
80 }
81
82 public function getGroup() {
83 return $this->group;
84 }
85
86 public function getSource() {
87 return $this->source;
88 }
89
90 public function getSkipFunction() {
91 return $this->skipFunction;
92 }
93
94 public function isRaw() {
95 return $this->isRaw;
96 }
97 }
98
99 class ResourceLoaderFileModuleTestModule extends ResourceLoaderFileModule {
100 }