summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/ResourceLoaderTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/includes/ResourceLoaderTest.php')
-rw-r--r--tests/phpunit/includes/ResourceLoaderTest.php62
1 files changed, 60 insertions, 2 deletions
diff --git a/tests/phpunit/includes/ResourceLoaderTest.php b/tests/phpunit/includes/ResourceLoaderTest.php
index 60618b10..ca8b2b6e 100644
--- a/tests/phpunit/includes/ResourceLoaderTest.php
+++ b/tests/phpunit/includes/ResourceLoaderTest.php
@@ -4,6 +4,32 @@ class ResourceLoaderTest extends MediaWikiTestCase {
protected static $resourceLoaderRegisterModulesHook;
+ protected function setUp() {
+ parent::setUp();
+
+ // $wgResourceLoaderLESSFunctions, $wgResourceLoaderLESSImportPaths; $wgResourceLoaderLESSVars;
+
+ $this->setMwGlobals( array(
+ 'wgResourceLoaderLESSFunctions' => array(
+ 'test-sum' => function ( $frame, $less ) {
+ $sum = 0;
+ foreach ( $frame[2] as $arg ) {
+ $sum += (int)$arg[1];
+ }
+ return $sum;
+ },
+ ),
+ 'wgResourceLoaderLESSImportPaths' => array(
+ dirname( __DIR__ ) . '/data/less/common',
+ ),
+ 'wgResourceLoaderLESSVars' => array(
+ 'foo' => '2px',
+ 'Foo' => '#eeeeee',
+ 'bar' => 5,
+ ),
+ ) );
+ }
+
/* Hook Methods */
/**
@@ -11,6 +37,7 @@ class ResourceLoaderTest extends MediaWikiTestCase {
*/
public static function resourceLoaderRegisterModules( &$resourceLoader ) {
self::$resourceLoaderRegisterModulesHook = true;
+
return true;
}
@@ -21,6 +48,14 @@ class ResourceLoaderTest extends MediaWikiTestCase {
);
}
+ public static function provideResourceLoaderContext() {
+ $resourceLoader = new ResourceLoader();
+ $request = new FauxRequest();
+ return array(
+ array( new ResourceLoaderContext( $resourceLoader, $request ) ),
+ );
+ }
+
/* Test Methods */
/**
@@ -31,6 +66,7 @@ class ResourceLoaderTest extends MediaWikiTestCase {
self::$resourceLoaderRegisterModulesHook = false;
$resourceLoader = new ResourceLoader();
$this->assertTrue( self::$resourceLoaderRegisterModulesHook );
+
return $resourceLoader;
}
@@ -48,7 +84,22 @@ class ResourceLoaderTest extends MediaWikiTestCase {
}
/**
+ * @dataProvider provideResourceLoaderContext
+ * @covers ResourceLoaderFileModule::compileLessFile
+ */
+ public function testLessFileCompilation( $context ) {
+ $basePath = __DIR__ . '/../data/less/module';
+ $module = new ResourceLoaderFileModule( array(
+ 'localBasePath' => $basePath,
+ 'styles' => array( 'styles.less' ),
+ ) );
+ $styles = $module->getStyles( $context );
+ $this->assertStringEqualsFile( $basePath . '/styles.css', $styles['all'] );
+ }
+
+ /**
* @dataProvider providePackedModules
+ * @covers ResourceLoader::makePackedModulesString
*/
public function testMakePackedModulesString( $desc, $modules, $packed ) {
$this->assertEquals( $packed, ResourceLoader::makePackedModulesString( $modules ), $desc );
@@ -56,6 +107,7 @@ class ResourceLoaderTest extends MediaWikiTestCase {
/**
* @dataProvider providePackedModules
+ * @covers ResourceLoaderContext::expandModuleNames
*/
public function testexpandModuleNames( $desc, $modules, $packed ) {
$this->assertEquals( $modules, ResourceLoaderContext::expandModuleNames( $packed ), $desc );
@@ -77,14 +129,20 @@ class ResourceLoaderTest extends MediaWikiTestCase {
'Regression fixed in r88706 with dotless names',
array( 'foo', 'bar', 'baz' ),
'foo,bar,baz',
- )
+ ),
+ array(
+ 'Prefixless modules after a prefixed module',
+ array( 'single.module', 'foobar', 'foobaz' ),
+ 'single.module|foobar,foobaz',
+ ),
);
}
}
/* Stubs */
-class ResourceLoaderTestModule extends ResourceLoaderModule {}
+class ResourceLoaderTestModule extends ResourceLoaderModule {
+}
/* Hooks */
global $wgHooks;