wiki.techinc.nl/tests/phpunit/ResourceLoaderTestCase.php
Kunal Mehta 8968d8787f Check page_len in ResourceLoaderWikiModule::isKnownEmpty() for 'user' modules
In most cases, we just check whether the pages exist before saying
the module is not empty to avoid generating cached HTML without
the appropriate <script> or <link> tags.

However, for modules in the 'user' group, normal users cannot
delete their personal JavaScript/CSS pages, causing needless
extra requests, even though we know the pages are empty.

ResourceLoader::isKnownEmpty() now checks the page_len field
for modules in the 'user' group to check that there is
some actual content.

Bug: 68488
Change-Id: I0570f62887fd4642fd60367ae0b51d7dc19488ca
2014-08-30 00:24:37 +00:00

90 lines
2.1 KiB
PHP

<?php
abstract class ResourceLoaderTestCase extends MediaWikiTestCase {
protected static function getResourceLoaderContext( $lang = 'en' ) {
$resourceLoader = new ResourceLoader();
$request = new FauxRequest( array(
'lang' => $lang,
'modules' => 'startup',
'only' => 'scripts',
'skin' => 'vector',
'target' => 'test',
) );
return new ResourceLoaderContext( $resourceLoader, $request );
}
protected function setUp() {
parent::setUp();
ResourceLoader::clearCache();
$this->setMwGlobals( array(
// For ResourceLoader::inDebugMode since it doesn't have context
'wgResourceLoaderDebug' => true,
// Avoid influence from wgInvalidateCacheOnLocalSettingsChange
'wgCacheEpoch' => '20140101000000',
// For ResourceLoader::__construct()
'wgResourceLoaderSources' => array(),
// For wfScript()
'wgScriptPath' => '/w',
'wgScriptExtension' => '.php',
'wgScript' => '/w/index.php',
'wgLoadScript' => '/w/load.php',
) );
}
}
/* Stubs */
class ResourceLoaderTestModule extends ResourceLoaderModule {
protected $dependencies = array();
protected $group = null;
protected $source = 'local';
protected $script = '';
protected $styles = '';
protected $skipFunction = null;
protected $targets = array( 'test' );
public function __construct( $options = array() ) {
foreach ( $options as $key => $value ) {
$this->$key = $value;
}
}
public function getScript( ResourceLoaderContext $context ) {
return $this->script;
}
public function getStyles( ResourceLoaderContext $context ) {
return array( '' => $this->styles );
}
public function getDependencies() {
return $this->dependencies;
}
public function getGroup() {
return $this->group;
}
public function getSource() {
return $this->source;
}
public function getSkipFunction() {
return $this->skipFunction;
}
}
class ResourceLoaderFileModuleTestModule extends ResourceLoaderFileModule {
}
class ResourceLoaderWikiModuleTestModule extends ResourceLoaderWikiModule {
// Override expected via PHPUnit mocks and stubs
protected function getPages( ResourceLoaderContext $context ) {
return array();
}
}