From 9976cef4edfd1b24014f8bece428d43b5163beb0 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Fri, 7 Mar 2014 18:18:31 +0100 Subject: [PATCH] tests: Add ResourceLoaderTestCase and abstract context creation Change-Id: Ib4b265256e60a2f2109da73dc7edba6a75587ce2 --- tests/TestsAutoLoader.php | 3 ++ tests/phpunit/ResourceLoaderTestCase.php | 38 +++++++++++++++++++ .../ResourceLoaderModuleTest.php | 16 +------- .../ResourceLoaderTest.php | 23 +++-------- tests/phpunit/structure/StructureTest.php | 1 + 5 files changed, 48 insertions(+), 33 deletions(-) create mode 100644 tests/phpunit/ResourceLoaderTestCase.php rename tests/phpunit/includes/{ => resourceloader}/ResourceLoaderModuleTest.php (79%) rename tests/phpunit/includes/{ => resourceloader}/ResourceLoaderTest.php (86%) diff --git a/tests/TestsAutoLoader.php b/tests/TestsAutoLoader.php index ea4b0f6827..7a048bf17a 100644 --- a/tests/TestsAutoLoader.php +++ b/tests/TestsAutoLoader.php @@ -40,6 +40,9 @@ $wgAutoloadClasses += array( 'MediaWikiPHPUnitCommand' => "$testDir/phpunit/MediaWikiPHPUnitCommand.php", 'MediaWikiPHPUnitTestListener' => "$testDir/phpunit/MediaWikiPHPUnitTestListener.php", 'MediaWikiLangTestCase' => "$testDir/phpunit/MediaWikiLangTestCase.php", + 'ResourceLoaderTestCase' => "$testDir/phpunit/ResourceLoaderTestCase.php", + 'ResourceLoaderTestModule' => "$testDir/phpunit/ResourceLoaderTestCase.php", + 'ResourceLoaderFileModuleTestModule' => "$testDir/phpunit/ResourceLoaderTestCase.php", 'TestUser' => "$testDir/phpunit/includes/TestUser.php", # tests/phpunit/includes diff --git a/tests/phpunit/ResourceLoaderTestCase.php b/tests/phpunit/ResourceLoaderTestCase.php new file mode 100644 index 0000000000..d43247192b --- /dev/null +++ b/tests/phpunit/ResourceLoaderTestCase.php @@ -0,0 +1,38 @@ + 'true', + 'lang' => 'en', + 'modules' => 'startup', + 'only' => 'scripts', + 'skin' => 'vector', + 'target' => 'test', + ) ); + return new ResourceLoaderContext( $resourceLoader, $request ); + } + + protected function setUp() { + parent::setUp(); + + $this->setMwGlobals( array( + // For ResourceLoader::__construct() + 'wgResourceLoaderSources' => array(), + + // For wfScript() + 'wgScriptPath' => '/w', + 'wgScriptExtension' => '.php', + 'wgScript' => '/w/index.php', + 'wgLoadScript' => '/w/load.php', + ) ); + } +} + +/* Stubs */ + +class ResourceLoaderTestModule extends ResourceLoaderModule {} + +class ResourceLoaderFileModuleTestModule extends ResourceLoaderFileModule {} diff --git a/tests/phpunit/includes/ResourceLoaderModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php similarity index 79% rename from tests/phpunit/includes/ResourceLoaderModuleTest.php rename to tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php index 46433191fb..b25e9b061a 100644 --- a/tests/phpunit/includes/ResourceLoaderModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php @@ -1,18 +1,6 @@ 'false', - 'lang' => 'en', - 'modules' => 'startup', - 'only' => 'scripts', - 'skin' => 'vector', - ) ); - return new ResourceLoaderContext( $resourceLoader, $request ); - } +class ResourceLoaderModuleTest extends ResourceLoaderTestCase { /** * @covers ResourceLoaderModule::getDefinitionSummary @@ -83,5 +71,3 @@ class ResourceLoaderModuleTest extends MediaWikiTestCase { ); } } - -class ResourceLoaderFileModuleTestModule extends ResourceLoaderFileModule {} diff --git a/tests/phpunit/includes/ResourceLoaderTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php similarity index 86% rename from tests/phpunit/includes/ResourceLoaderTest.php rename to tests/phpunit/includes/resourceloader/ResourceLoaderTest.php index ca8b2b6efe..ab0c8d9b14 100644 --- a/tests/phpunit/includes/ResourceLoaderTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php @@ -1,6 +1,6 @@ array( - dirname( __DIR__ ) . '/data/less/common', + dirname( dirname( __DIR__ ) ) . '/data/less/common', ), 'wgResourceLoaderLESSVars' => array( 'foo' => '2px', @@ -48,14 +48,6 @@ class ResourceLoaderTest extends MediaWikiTestCase { ); } - public static function provideResourceLoaderContext() { - $resourceLoader = new ResourceLoader(); - $request = new FauxRequest(); - return array( - array( new ResourceLoaderContext( $resourceLoader, $request ) ), - ); - } - /* Test Methods */ /** @@ -84,11 +76,11 @@ class ResourceLoaderTest extends MediaWikiTestCase { } /** - * @dataProvider provideResourceLoaderContext * @covers ResourceLoaderFileModule::compileLessFile */ - public function testLessFileCompilation( $context ) { - $basePath = __DIR__ . '/../data/less/module'; + public function testLessFileCompilation() { + $context = self::getResourceLoaderContext(); + $basePath = __DIR__ . '/../../data/less/module'; $module = new ResourceLoaderFileModule( array( 'localBasePath' => $basePath, 'styles' => array( 'styles.less' ), @@ -139,11 +131,6 @@ class ResourceLoaderTest extends MediaWikiTestCase { } } -/* Stubs */ - -class ResourceLoaderTestModule extends ResourceLoaderModule { -} - /* Hooks */ global $wgHooks; $wgHooks['ResourceLoaderRegisterModules'][] = 'ResourceLoaderTest::resourceLoaderRegisterModules'; diff --git a/tests/phpunit/structure/StructureTest.php b/tests/phpunit/structure/StructureTest.php index df00d4df22..23932997cc 100644 --- a/tests/phpunit/structure/StructureTest.php +++ b/tests/phpunit/structure/StructureTest.php @@ -22,6 +22,7 @@ class StructureTest extends MediaWikiTestCase { 'ApiQueryContinueTestBase', 'MediaWikiLangTestCase', 'MediaWikiTestCase', + 'ResourceLoaderTestCase', 'PHPUnit_Framework_TestCase', 'DumpTestCase', ) ); -- 2.20.1