From dbd718dc55b7e6bfa2ca6e49b03b71f107507540 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Mon, 23 Mar 2015 03:57:45 +0000 Subject: [PATCH] resourceloader: Add @covers and minor clean up of test suites * Move testMixedCssAnnotations to ResourceLoaderFileModuleTest. * Re-order data providers before test methods. * Add relevant @covers annotations in resourceloader/ tests. * Make test helper function private. * Add a few @covers for methods called from OutputPage::makeResourceLoaderLink (only one level deep, we should have separate unit tests for the more internal helpers). Change-Id: I2cc1757126214ed28059d4566ca813a86bcd95a7 --- tests/phpunit/includes/OutputPageTest.php | 5 + .../ResourceLoaderFileModuleTest.php | 128 ++++++++++++------ .../resourceloader/ResourceLoaderTest.php | 40 +----- 3 files changed, 94 insertions(+), 79 deletions(-) diff --git a/tests/phpunit/includes/OutputPageTest.php b/tests/phpunit/includes/OutputPageTest.php index 1f35ead3d1..9a3bf17366 100644 --- a/tests/phpunit/includes/OutputPageTest.php +++ b/tests/phpunit/includes/OutputPageTest.php @@ -225,6 +225,11 @@ class OutputPageTest extends MediaWikiTestCase { /** * @dataProvider provideMakeResourceLoaderLink * @covers OutputPage::makeResourceLoaderLink + * @covers ResourceLoader::makeLoaderImplementScript + * @covers ResourceLoader::makeModuleResponse + * @covers ResourceLoader::makeInlineScript + * @covers ResourceLoader::makeLoaderStateScript + * @covers ResourceLoader::createLoaderURL */ public function testMakeResourceLoaderLink( $args, $expectedHtml ) { $this->setMwGlobals( array( diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php index 9afc54d6cb..f3dff1701e 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php @@ -18,7 +18,7 @@ class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase { ); } - public static function getModules() { + private static function getModules() { $base = array( 'localBasePath' => realpath( dirname( __FILE__ ) ), ); @@ -48,48 +48,10 @@ class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase { ); } - public static function providerGetTemplates() { - $modules = self::getModules(); - - return array( - array( - $modules['noTemplateModule'], - array(), - ), - array( - $modules['templateModuleHandlebars'], - array( - 'templates/template_awesome.handlebars' => "wow\n", - ), - ), - array( - $modules['htmlTemplateModule'], - array( - 'templates/template.html' => "hello\n", - 'templates/template2.html' => "
goodbye
\n", - ), - ), - array( - $modules['aliasedHtmlTemplateModule'], - array( - 'foo.html' => "hello\n", - 'bar.html' => "
goodbye
\n", - ), - ), - ); - } - - public static function providerGetModifiedTime() { - $modules = self::getModules(); - - return array( - // Check the default value when no templates present in module is 1 - array( $modules['noTemplateModule'], 1 ), - ); - } - /** + * @covers ResourceLoaderFileModule::getAllStyleFiles * @covers ResourceLoaderFileModule::getAllSkinStyleFiles + * @covers ResourceLoaderFileModule::getSkinStyleFiles */ public function testGetAllSkinStyleFiles() { $baseParams = array( @@ -132,6 +94,81 @@ class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase { ); } + /** + * Strip @noflip annotations from CSS code. + * @param string $css + * @return string + */ + private static function stripNoflip( $css ) { + return str_replace( '/*@noflip*/ ', '', $css ); + } + + /** + * What happens when you mix @embed and @noflip? + * This really is an integration test, but oh well. + * + * @covers ResourceLoaderFileModule::getStyles + * @covers ResourceLoaderFileModule::getStyleFiles + */ + public function testMixedCssAnnotations( ) { + $basePath = __DIR__ . '/../../data/css'; + $testModule = new ResourceLoaderFileModule( array( + 'localBasePath' => $basePath, + 'styles' => array( 'test.css' ), + ) ); + $expectedModule = new ResourceLoaderFileModule( array( + 'localBasePath' => $basePath, + 'styles' => array( 'expected.css' ), + ) ); + + $contextLtr = $this->getResourceLoaderContext( 'en', 'ltr' ); + $contextRtl = $this->getResourceLoaderContext( 'he', 'rtl' ); + + // Since we want to compare the effect of @noflip+@embed against the effect of just @embed, and + // the @noflip annotations are always preserved, we need to strip them first. + $this->assertEquals( + $expectedModule->getStyles( $contextLtr ), + self::stripNoflip( $testModule->getStyles( $contextLtr ) ), + "/*@noflip*/ with /*@embed*/ gives correct results in LTR mode" + ); + $this->assertEquals( + $expectedModule->getStyles( $contextLtr ), + self::stripNoflip( $testModule->getStyles( $contextRtl ) ), + "/*@noflip*/ with /*@embed*/ gives correct results in RTL mode" + ); + } + + public static function providerGetTemplates() { + $modules = self::getModules(); + + return array( + array( + $modules['noTemplateModule'], + array(), + ), + array( + $modules['templateModuleHandlebars'], + array( + 'templates/template_awesome.handlebars' => "wow\n", + ), + ), + array( + $modules['htmlTemplateModule'], + array( + 'templates/template.html' => "hello\n", + 'templates/template2.html' => "
goodbye
\n", + ), + ), + array( + $modules['aliasedHtmlTemplateModule'], + array( + 'foo.html' => "hello\n", + 'bar.html' => "
goodbye
\n", + ), + ), + ); + } + /** * @dataProvider providerGetTemplates * @covers ResourceLoaderFileModule::getTemplates @@ -142,6 +179,15 @@ class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase { $this->assertEquals( $rl->getTemplates(), $expected ); } + public static function providerGetModifiedTime() { + $modules = self::getModules(); + + return array( + // Check the default value when no templates present in module is 1 + array( $modules['noTemplateModule'], 1 ), + ); + } + /** * @dataProvider providerGetModifiedTime * @covers ResourceLoaderFileModule::getModifiedTime diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php index d756ce3061..e43db78c80 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php @@ -5,8 +5,6 @@ class ResourceLoaderTest extends ResourceLoaderTestCase { protected function setUp() { parent::setUp(); - // $wgResourceLoaderLESSFunctions, $wgResourceLoaderLESSImportPaths; $wgResourceLoaderLESSVars; - $this->setMwGlobals( array( 'wgResourceLoaderLESSFunctions' => array( 'test-sum' => function ( $frame, $less ) { @@ -28,15 +26,12 @@ class ResourceLoaderTest extends ResourceLoaderTestCase { ) ); } - /* Provider Methods */ public static function provideValidModules() { return array( array( 'TEST.validModule1', new ResourceLoaderTestModule() ), ); } - /* Test Methods */ - /** * Ensures that the ResourceLoaderRegisterModules hook is called when a new * ResourceLoader object is constructed. @@ -95,42 +90,10 @@ class ResourceLoaderTest extends ResourceLoaderTestCase { * @param string $css * @return string */ - private function stripNoflip( $css ) { + private static function stripNoflip( $css ) { return str_replace( '/*@noflip*/ ', '', $css ); } - /** - * What happens when you mix @embed and @noflip? - * This really is an integration test, but oh well. - */ - public function testMixedCssAnnotations( ) { - $basePath = __DIR__ . '/../../data/css'; - $testModule = new ResourceLoaderFileModule( array( - 'localBasePath' => $basePath, - 'styles' => array( 'test.css' ), - ) ); - $expectedModule = new ResourceLoaderFileModule( array( - 'localBasePath' => $basePath, - 'styles' => array( 'expected.css' ), - ) ); - - $contextLtr = $this->getResourceLoaderContext( 'en', 'ltr' ); - $contextRtl = $this->getResourceLoaderContext( 'he', 'rtl' ); - - // Since we want to compare the effect of @noflip+@embed against the effect of just @embed, and - // the @noflip annotations are always preserved, we need to strip them first. - $this->assertEquals( - $expectedModule->getStyles( $contextLtr ), - $this->stripNoflip( $testModule->getStyles( $contextLtr ) ), - "/*@noflip*/ with /*@embed*/ gives correct results in LTR mode" - ); - $this->assertEquals( - $expectedModule->getStyles( $contextLtr ), - $this->stripNoflip( $testModule->getStyles( $contextRtl ) ), - "/*@noflip*/ with /*@embed*/ gives correct results in RTL mode" - ); - } - /** * @dataProvider providePackedModules * @covers ResourceLoader::makePackedModulesString @@ -192,6 +155,7 @@ class ResourceLoaderTest extends ResourceLoaderTestCase { /** * @dataProvider provideAddSource * @covers ResourceLoader::addSource + * @covers ResourceLoader::getSources */ public function testAddSource( $name, $info, $expected ) { $rl = new ResourceLoader; -- 2.20.1