jenkins-bot has submitted this change and it was merged.
Change subject: Inject settings into api client info module
......................................................................
Inject settings into api client info module
Change-Id: Iba2a88813d177504fb71e47df2f8defc12d0abc8
---
M client/includes/api/ApiClientInfo.php
M client/tests/phpunit/includes/api/ApiClientInfoTest.php
2 files changed, 138 insertions(+), 37 deletions(-)
Approvals:
Daniel Kinzler: Looks good to me, approved
jenkins-bot: Verified
diff --git a/client/includes/api/ApiClientInfo.php
b/client/includes/api/ApiClientInfo.php
index 9e201e1..563e241 100644
--- a/client/includes/api/ApiClientInfo.php
+++ b/client/includes/api/ApiClientInfo.php
@@ -33,14 +33,19 @@
*/
class ApiClientInfo extends \ApiQueryBase {
+ protected $settings;
+
/**
* @since 0.4
*
- * @param $api ApiBase
- * @param $moduleName string
+ * @param ApiBase $api
+ * @param string $moduleName
*/
public function __construct( $api, $moduleName ) {
parent::__construct( $api, $moduleName, 'wb' );
+
+ // @todo inject this instead of using singleton here
+ $this->settings = Settings::singleton();
}
/**
@@ -51,34 +56,51 @@
public function execute() {
$params = $this->extractRequestParams();
+ $apiData = $this->getRepoInfo( $params );
+
+ $this->getResult()->addValue( 'query', 'wikibase', $apiData );
+ }
+
+ /**
+ * Set settings for api module
+ *
+ * @since 0.4
+ *
+ * @param SettingsArray $settings
+ */
+ public function setSettings( SettingsArray $settings ) {
+ $this->settings = $settings;
+ }
+
+ /**
+ * Gets repo url info to inject into the api module
+ *
+ * @since 0.4
+ *
+ * @param array $params[]
+ *
+ * @return array
+ */
+ public function getRepoInfo( array $params ) {
$data = array( 'repo' => array() );
+
+ $repoUrlArray = array(
+ 'base' => $this->settings->getSetting( 'repoUrl' ),
+ 'scriptpath' => $this->settings->getSetting(
'repoScriptPath' ),
+ 'articlepath' => $this->settings->getSetting(
'repoArticlePath' ),
+ );
foreach ( $params['prop'] as $p ) {
switch ( $p ) {
case 'url':
- $data['repo']['url'] = $this->urlInfo();
+ $data['repo']['url'] = $repoUrlArray;
break;
default;
break;
}
}
- $this->getResult()->addValue( 'query', 'wikibase', $data );
- }
-
- /**
- * Provides url settings for the associated Wikibase repo
- *
- * @since 0.4
- *
- * @return array
- */
- public function urlInfo() {
- return array(
- 'base' => Settings::get( 'repoUrl' ),
- 'scriptpath' => Settings::get( 'repoScriptPath' ),
- 'articlepath' => Settings::get( 'repoArticlePath' ),
- );
+ return $data;
}
/**
diff --git a/client/tests/phpunit/includes/api/ApiClientInfoTest.php
b/client/tests/phpunit/includes/api/ApiClientInfoTest.php
index 3294e26..808aa2a 100644
--- a/client/tests/phpunit/includes/api/ApiClientInfoTest.php
+++ b/client/tests/phpunit/includes/api/ApiClientInfoTest.php
@@ -1,6 +1,8 @@
<?php
-
namespace Wikibase\Test;
+
+use Wikibase\SettingsArray;
+use Wikibase\ApiClientInfo;
/**
* Tests for ApiClientInfo module.
@@ -37,23 +39,57 @@
* @licence GNU GPL v2+
* @author Katie Filbert < [email protected] >
*/
-class ApiClientInfoTest extends \ApiTestCase {
+class ApiClientInfoTest extends \MediaWikiTestCase {
- public function testGetUrlInfo() {
- $data = $this->doApiRequest(
- array(
- 'action' => 'query',
- 'meta' => 'wikibase',
- 'wbprop' => 'url',
- )
- );
+ protected $apiContext;
- $this->assertArrayHasKey( 'query', $data[0] );
- $this->assertArrayHasKey( 'wikibase', $data[0]['query'] );
- $this->assertArrayHasKey( 'repo', $data[0]['query']['wikibase']
);
- $this->assertArrayHasKey( 'url',
$data[0]['query']['wikibase']['repo'] );
+ public function setUp() {
+ parent::setUp();
- $urlInfo = $data[0]['query']['wikibase']['repo']['url'];
+ $this->apiContext = new \ApiTestContext();
+ }
+
+ public function getApiModule( array $params, SettingsArray $settings ) {
+ $request = new \FauxRequest( $params, true );
+
+ $user = \User::newFromName( 'zombie' );
+
+ $context = $this->apiContext->newTestContext( $request, $user );
+ $apiMain = new \ApiMain( $context, true );
+
+ $apiModule = new ApiClientInfo( $apiMain, 'query' );
+ $apiModule->setSettings( $settings );
+
+ return $apiModule;
+ }
+
+ /**
+ * @dataProvider executeProvider
+ */
+ public function testExecute( $params ) {
+ $settings = $this->getSettings();
+
+ $module = $this->getApiModule( $params, $settings );
+ $module->execute();
+
+ $result = $module->getResult()->getData();
+
+ $this->assertInternalType( 'array', $result, 'top level element
is an array' );
+
+ $this->assertArrayHasKey( 'query', $result, 'top level element
has a query key' );
+ $this->assertArrayHasKey( 'wikibase', $result['query'], 'second
level element has a wikibase key' );
+ }
+
+ /**
+ * @dataProvider getRepoInfoProvider
+ */
+ public function testGetRepoInfo( array $params, SettingsArray $settings
) {
+ $module = $this->getApiModule( $params, $settings );
+ $reqParams = $module->extractRequestParams();
+ $repoInfo = $module->getRepoInfo( $reqParams );
+
+ $this->assertArrayHasKey( 'repo', $repoInfo, 'top level element
has repo key' );
+ $urlInfo = $repoInfo['repo']['url'];
$this->assertArrayHasKey( 'base', $urlInfo );
$this->assertArrayHasKey( 'scriptpath', $urlInfo );
@@ -66,8 +102,51 @@
$this->assertInternalType( 'string', $urlInfo['articlepath'],
"The repo URL information for 'articlepath' should be a
string" );
- $this->assertEquals( \Wikibase\Settings::get( 'repoUrl' ),
$urlInfo['base'] );
- $this->assertEquals( \Wikibase\Settings::get( 'repoScriptPath'
), $urlInfo['scriptpath'] );
- $this->assertEquals( \Wikibase\Settings::get( 'repoArticlePath'
), $urlInfo['articlepath'] );
+ $this->assertEquals( $settings->getSetting( 'repoUrl' ),
$urlInfo['base'] );
+ $this->assertEquals( $settings->getSetting( 'repoScriptPath' ),
$urlInfo['scriptpath'] );
+ $this->assertEquals( $settings->getSetting( 'repoArticlePath'
), $urlInfo['articlepath'] );
+
}
+
+ public function executeProvider() {
+ $params = $this->getApiRequestParams();
+
+ return array(
+ array( $params )
+ );
+ }
+
+ public function getRepoInfoProvider() {
+ $params = $this->getApiRequestParams();
+ $settings = $this->getSettings();
+
+ return array(
+ array( $params, $settings )
+ );
+ }
+
+ /**
+ * @return array
+ */
+ protected function getApiRequestParams() {
+ $params = array(
+ 'action' => 'query',
+ 'meta' => 'wikibase',
+ 'wbprop' => 'url'
+ );
+
+ return $params;
+ }
+
+ /**
+ * @return SettingsArray
+ */
+ protected function getSettings() {
+ return new SettingsArray( array(
+ 'repoUrl' => 'http://www.example.org',
+ 'repoScriptPath' => '/w',
+ 'repoArticlePath' => '/wiki/$1'
+ ) );
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/64037
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iba2a88813d177504fb71e47df2f8defc12d0abc8
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits