Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / ResourceLoaderTestCase.php
blob055beb018c35c66cff716355453602d8bea83cf0
1 <?php
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 )
25 return $ctx;
28 protected function setUp() {
29 parent::setUp();
31 ResourceLoader::clearCache();
33 $this->setMwGlobals( array(
34 // For ResourceLoader::inDebugMode since it doesn't have context
35 'wgResourceLoaderDebug' => true,
37 // Avoid influence from wgInvalidateCacheOnLocalSettingsChange
38 'wgCacheEpoch' => '20140101000000',
40 // For ResourceLoader::__construct()
41 'wgResourceLoaderSources' => array(),
43 // For wfScript()
44 'wgScriptPath' => '/w',
45 'wgScriptExtension' => '.php',
46 'wgScript' => '/w/index.php',
47 'wgLoadScript' => '/w/load.php',
48 ) );
52 /* Stubs */
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' );
64 public function __construct( $options = array() ) {
65 foreach ( $options as $key => $value ) {
66 $this->$key = $value;
70 public function getScript( ResourceLoaderContext $context ) {
71 return $this->script;
74 public function getStyles( ResourceLoaderContext $context ) {
75 return array( '' => $this->styles );
78 public function getDependencies() {
79 return $this->dependencies;
82 public function getGroup() {
83 return $this->group;
86 public function getSource() {
87 return $this->source;
90 public function getSkipFunction() {
91 return $this->skipFunction;
94 public function isRaw() {
95 return $this->isRaw;
99 class ResourceLoaderFileModuleTestModule extends ResourceLoaderFileModule {
102 class ResourceLoaderWikiModuleTestModule extends ResourceLoaderWikiModule {
103 // Override expected via PHPUnit mocks and stubs
104 protected function getPages( ResourceLoaderContext $context ) {
105 return array();