jenkins-bot has submitted this change and it was merged.

Change subject: phpunit: Make getResourceLoaderContext() more extendable
......................................................................


phpunit: Make getResourceLoaderContext() more extendable

This makes it easier to add other options in the future,
such as setting 'modules' in the context to something else.

Change-Id: I53c25fa7ad705cc34e44f95e4f87eb53612d800e
---
M tests/phpunit/ResourceLoaderTestCase.php
M tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php
M tests/phpunit/includes/resourceloader/ResourceLoaderImageTest.php
3 files changed, 30 insertions(+), 12 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/tests/phpunit/ResourceLoaderTestCase.php 
b/tests/phpunit/ResourceLoaderTestCase.php
index baa481e..45cfdbf 100644
--- a/tests/phpunit/ResourceLoaderTestCase.php
+++ b/tests/phpunit/ResourceLoaderTestCase.php
@@ -11,14 +11,23 @@
        const BLANK_VERSION = '09p30q0';
 
        /**
-        * @param string $lang
-        * @param string $dir
+        * @param array|string $options Language code or options array
+        * - string 'lang' Language code
+        * - string 'dir' Language direction (ltr or rtl)
         * @return ResourceLoaderContext
         */
-       protected function getResourceLoaderContext( $lang = 'en', $dir = 'ltr' 
) {
+       protected function getResourceLoaderContext( $options = [] ) {
+               if ( is_string( $options ) ) {
+                       // Back-compat for extension tests
+                       $options = [ 'lang' => $options ];
+               }
+               $options += [
+                       'lang' => 'en',
+                       'dir' => 'ltr',
+               ];
                $resourceLoader = new ResourceLoader();
                $request = new FauxRequest( [
-                               'lang' => $lang,
+                               'lang' => $options['lang'],
                                'modules' => 'startup',
                                'only' => 'scripts',
                                'skin' => 'vector',
@@ -28,7 +37,7 @@
                        ->setConstructorArgs( [ $resourceLoader, $request ] )
                        ->setMethods( [ 'getDirection' ] )
                        ->getMock();
-               $ctx->method( 'getDirection' )->willReturn( $dir );
+               $ctx->method( 'getDirection' )->willReturn( $options['dir'] );
                return $ctx;
        }
 
diff --git 
a/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php 
b/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php
index 8b29983..4a3b90a 100644
--- a/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php
+++ b/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php
@@ -130,7 +130,7 @@
                $modules = self::getModules();
                $rl = new ResourceLoaderFileModule( $modules[$name] );
                $rl->setName( $name );
-               $ctx = $this->getResourceLoaderContext( 'en', 'ltr' );
+               $ctx = $this->getResourceLoaderContext();
                $this->assertEquals( $rl->getScript( $ctx ), $expected );
        }
 
@@ -210,8 +210,14 @@
                ] );
                $expectedModule->setName( 'testing' );
 
-               $contextLtr = $this->getResourceLoaderContext( 'en', 'ltr' );
-               $contextRtl = $this->getResourceLoaderContext( 'he', 'rtl' );
+               $contextLtr = $this->getResourceLoaderContext( [
+                       'lang' => 'en',
+                       'dir' => 'ltr',
+               ] );
+               $contextRtl = $this->getResourceLoaderContext( [
+                       'lang' => 'he',
+                       'dir' => '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.
@@ -282,9 +288,9 @@
                        'File has leading BOM'
                );
 
-               $contextLtr = $this->getResourceLoaderContext( 'en', 'ltr' );
+               $context = $this->getResourceLoaderContext();
                $this->assertEquals(
-                       $testModule->getStyles( $contextLtr ),
+                       $testModule->getStyles( $context ),
                        [ 'all' => ".efbbbf_bom_char_at_start_of_file {}\n" ],
                        'Leading BOM removed when concatenating files'
                );
diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderImageTest.php 
b/tests/phpunit/includes/resourceloader/ResourceLoaderImageTest.php
index 179a8ed..84b56d4 100644
--- a/tests/phpunit/includes/resourceloader/ResourceLoaderImageTest.php
+++ b/tests/phpunit/includes/resourceloader/ResourceLoaderImageTest.php
@@ -61,7 +61,10 @@
                static $contexts = [];
 
                $image = $this->getTestImage( $imageName );
-               $context = $this->getResourceLoaderContext( $languageCode, 
$dirMap[$languageCode] );
+               $context = $this->getResourceLoaderContext( [
+                       'lang' => $languageCode,
+                       'dir' => $dirMap[$languageCode],
+               ] );
 
                $this->assertEquals( $image->getPath( $context ), 
$this->imagesPath . '/' . $path );
        }
@@ -87,7 +90,7 @@
         * @covers ResourceLoaderImage::massageSvgPathdata
         */
        public function testGetImageData() {
-               $context = $this->getResourceLoaderContext( 'en', 'ltr' );
+               $context = $this->getResourceLoaderContext();
 
                $image = $this->getTestImage( 'remove' );
                $data = file_get_contents( $this->imagesPath . '/remove.svg' );

-- 
To view, visit https://gerrit.wikimedia.org/r/325070
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I53c25fa7ad705cc34e44f95e4f87eb53612d800e
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Catrope <r...@wikimedia.org>
Gerrit-Reviewer: Legoktm <lego...@member.fsf.org>
Gerrit-Reviewer: Reedy <re...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to