/**
* ResourceLoader module based on local JavaScript/CSS files.
+ *
+ * The following public methods can query the database:
+ *
+ * - getDefinitionSummary / … / ResourceLoaderModule::getFileDependencies.
+ * - getVersionHash / getDefinitionSummary / … / ResourceLoaderModule::getFileDependencies.
+ * - getStyles / ResourceLoaderModule::saveFileDependencies.
*/
class ResourceLoaderFileModule extends ResourceLoaderModule {
}
}
+/**
+ * A more constrained and testable variant of ResourceLoaderFileModule.
+ *
+ * - Implements getLessVars() support.
+ * - Disables database persistance of discovered file dependencies.
+ */
class ResourceLoaderFileTestModule extends ResourceLoaderFileModule {
protected $lessVars = [];
public function getLessVars( ResourceLoaderContext $context ) {
return $this->lessVars;
}
+
+ /** @return array */
+ protected function getFileDependencies( ResourceLoaderContext $context ) {
+ // No-op
+ return [];
+ }
+
+ protected function saveFileDependencies( ResourceLoaderContext $context, $refs ) {
+ // No-op
+ }
}
class ResourceLoaderFileModuleTestingSubclass extends ResourceLoaderFileModule {
<?php
/**
- * @group Database
* @group ResourceLoader
*/
class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase {
}
);
$this->setService( 'SkinFactory', $skinFactory );
+
+ // This test is not expected to query any database
+ MediaWiki\MediaWikiServices::disableStorageBackend();
}
private static function getModules() {
$base = [
- 'localBasePath' => realpath( __DIR__ ),
+ 'localBasePath' => __DIR__,
];
return [
*/
public function testMixedCssAnnotations() {
$basePath = __DIR__ . '/../../data/css';
- $testModule = new ResourceLoaderFileModule( [
+ $testModule = new ResourceLoaderFileTestModule( [
'localBasePath' => $basePath,
'styles' => [ 'test.css' ],
] );
$testModule->setName( 'testing' );
- $expectedModule = new ResourceLoaderFileModule( [
+ $expectedModule = new ResourceLoaderFileTestModule( [
'localBasePath' => $basePath,
'styles' => [ 'expected.css' ],
] );
*/
public function testBomConcatenation() {
$basePath = __DIR__ . '/../../data/css';
- $testModule = new ResourceLoaderFileModule( [
+ $testModule = new ResourceLoaderFileTestModule( [
'localBasePath' => $basePath,
'styles' => [ 'bom.css' ],
] );