resourceloader: Add @covers and minor clean up of test suites
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 23 Mar 2015 03:57:45 +0000 (03:57 +0000)
committerTimo Tijhof <krinklemail@gmail.com>
Mon, 23 Mar 2015 04:16:08 +0000 (04:16 +0000)
* 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
tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php
tests/phpunit/includes/resourceloader/ResourceLoaderTest.php

index 1f35ead..9a3bf17 100644 (file)
@@ -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(
index 9afc54d..f3dff17 100644 (file)
@@ -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' => "<strong>hello</strong>\n",
-                                       'templates/template2.html' => "<div>goodbye</div>\n",
-                               ),
-                       ),
-                       array(
-                               $modules['aliasedHtmlTemplateModule'],
-                               array(
-                                       'foo.html' => "<strong>hello</strong>\n",
-                                       'bar.html' => "<div>goodbye</div>\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' => "<strong>hello</strong>\n",
+                                       'templates/template2.html' => "<div>goodbye</div>\n",
+                               ),
+                       ),
+                       array(
+                               $modules['aliasedHtmlTemplateModule'],
+                               array(
+                                       'foo.html' => "<strong>hello</strong>\n",
+                                       'bar.html' => "<div>goodbye</div>\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
index d756ce3..e43db78 100644 (file)
@@ -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;