Legoktm has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/154715

Change subject: Add ResourceLoader::getAPIScript() to accompany getLoadScript()
......................................................................

Add ResourceLoader::getAPIScript() to accompany getLoadScript()

Change-Id: Iad7dda40e890530cca8e2b60db8d56b8e16d06cf
---
M includes/resourceloader/ResourceLoader.php
M tests/phpunit/includes/resourceloader/ResourceLoaderTest.php
2 files changed, 26 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/15/154715/1

diff --git a/includes/resourceloader/ResourceLoader.php 
b/includes/resourceloader/ResourceLoader.php
index 198420c..0d1bf47 100644
--- a/includes/resourceloader/ResourceLoader.php
+++ b/includes/resourceloader/ResourceLoader.php
@@ -550,6 +550,22 @@
        }
 
        /**
+        * Get the URL to the api.php endpoint for the given
+        * ResourceLoader source
+        *
+        * @since 1.24
+        * @param string $source
+        * @throws MWException On an invalid $source name
+        * @return string
+        */
+       public function getAPIScript( $source ) {
+               if ( !isset( $this->sources[$source] ) ) {
+                       throw new MWException( "The $source source was never 
registered in ResourceLoader." );
+               }
+               return $this->sources[$source]['apiScript'];
+       }
+
+       /**
         * Output a response to a load request, including the content-type 
header.
         *
         * @param ResourceLoaderContext $context Context in which a response 
should be formed
diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php 
b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php
index bd6b3f2..92d174f 100644
--- a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php
+++ b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php
@@ -146,14 +146,16 @@
 
        /**
         * @covers ResourceLoader::getLoadScript
+        * @covers ResourceLoader::getAPIScript
         */
-       public function testGetLoadScript() {
+       public function testGetLoadAndAPIScript() {
                $this->setMwGlobals( 'wgResourceLoaderSources', array() );
                $rl = new ResourceLoader();
                $sources = self::fakeSources();
                $rl->addSource( $sources );
                foreach ( array( 'examplewiki', 'example2wiki' ) as $name ) {
                        $this->assertEquals( $rl->getLoadScript( $name ), 
$sources[$name]['loadScript'] );
+                       $this->assertEquals( $rl->getAPIScript( $name ), 
$sources[$name]['apiScript'] );
                }
 
                try {
@@ -162,6 +164,13 @@
                } catch ( MWException $e ) {
                        $this->assertTrue( true );
                }
+
+               try {
+                       $rl->getAPIScript( 'thiswasneverreigstered' );
+                       $this->assertTrue( false, 'ResourceLoader::getAPIScript 
should have thrown an exception' );
+               } catch ( MWException $e ) {
+                       $this->assertTrue( true );
+               }
        }
 }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iad7dda40e890530cca8e2b60db8d56b8e16d06cf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to