MediaWiki  REL1_24
ResourceLoaderTestCase.php
Go to the documentation of this file.
00001 <?php
00002 
00003 abstract class ResourceLoaderTestCase extends MediaWikiTestCase {
00004     protected static function getResourceLoaderContext( $lang = 'en' ) {
00005         $resourceLoader = new ResourceLoader();
00006         $request = new FauxRequest( array(
00007                 'lang' => $lang,
00008                 'modules' => 'startup',
00009                 'only' => 'scripts',
00010                 'skin' => 'vector',
00011                 'target' => 'test',
00012         ) );
00013         return new ResourceLoaderContext( $resourceLoader, $request );
00014     }
00015 
00016     protected function setUp() {
00017         parent::setUp();
00018 
00019         ResourceLoader::clearCache();
00020 
00021         $this->setMwGlobals( array(
00022             // For ResourceLoader::inDebugMode since it doesn't have context
00023             'wgResourceLoaderDebug' => true,
00024 
00025             // Avoid influence from wgInvalidateCacheOnLocalSettingsChange
00026             'wgCacheEpoch' => '20140101000000',
00027 
00028             // For ResourceLoader::__construct()
00029             'wgResourceLoaderSources' => array(),
00030 
00031             // For wfScript()
00032             'wgScriptPath' => '/w',
00033             'wgScriptExtension' => '.php',
00034             'wgScript' => '/w/index.php',
00035             'wgLoadScript' => '/w/load.php',
00036         ) );
00037     }
00038 }
00039 
00040 /* Stubs */
00041 
00042 class ResourceLoaderTestModule extends ResourceLoaderModule {
00043     protected $dependencies = array();
00044     protected $group = null;
00045     protected $source = 'local';
00046     protected $script = '';
00047     protected $styles = '';
00048     protected $skipFunction = null;
00049     protected $isRaw = false;
00050     protected $targets = array( 'test' );
00051 
00052     public function __construct( $options = array() ) {
00053         foreach ( $options as $key => $value ) {
00054             $this->$key = $value;
00055         }
00056     }
00057 
00058     public function getScript( ResourceLoaderContext $context ) {
00059         return $this->script;
00060     }
00061 
00062     public function getStyles( ResourceLoaderContext $context ) {
00063         return array( '' => $this->styles );
00064     }
00065 
00066     public function getDependencies() {
00067         return $this->dependencies;
00068     }
00069 
00070     public function getGroup() {
00071         return $this->group;
00072     }
00073 
00074     public function getSource() {
00075         return $this->source;
00076     }
00077 
00078     public function getSkipFunction() {
00079         return $this->skipFunction;
00080     }
00081 
00082     public function isRaw() {
00083         return $this->isRaw;
00084     }
00085 }
00086 
00087 class ResourceLoaderFileModuleTestModule extends ResourceLoaderFileModule {
00088 }
00089 
00090 class ResourceLoaderWikiModuleTestModule extends ResourceLoaderWikiModule {
00091     // Override expected via PHPUnit mocks and stubs
00092     protected function getPages( ResourceLoaderContext $context ) {
00093         return array();
00094     }
00095 }