Hoo man has uploaded a new change for review.
https://gerrit.wikimedia.org/r/178140
Change subject: Adopt ApiConventionsTest to MediaWiki 1.25 API module changes
......................................................................
Adopt ApiConventionsTest to MediaWiki 1.25 API module changes
Also minor style enhancements
Change-Id: I69008ed8aebb819bd536d3e9e79d41cc64d3495d
---
M repo/tests/phpunit/includes/api/ApiConventionsTest.php
1 file changed, 30 insertions(+), 21 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/40/178140/1
diff --git a/repo/tests/phpunit/includes/api/ApiConventionsTest.php
b/repo/tests/phpunit/includes/api/ApiConventionsTest.php
index 6016f7e..8814e14 100644
--- a/repo/tests/phpunit/includes/api/ApiConventionsTest.php
+++ b/repo/tests/phpunit/includes/api/ApiConventionsTest.php
@@ -3,10 +3,15 @@
namespace Wikibase\Test\Api;
use PHPUnit_Framework_TestCase;
+use ApiBase;
+use ApiMain;
+use FauxRequest;
+use ReflectionMethod;
/**
*
* @group Wikibase
+ * @group WikibaseRepo
* @group WikibaseAPI
*
* @group medium
@@ -20,7 +25,7 @@
$argList = array();
foreach ( $GLOBALS['wgAPIModules'] as $moduleClass ) {
- //make sure to only test Wikibase Api modules
+ // Make sure to only test Wikibase Api modules
if ( strpos( $moduleClass, 'Wikibase' ) !== false ) {
$argList[] = array( $moduleClass );
}
@@ -30,33 +35,35 @@
}
/**
- * Connects the assertions for the different methods and iterates
through the api modules
- * @dataProvider wikibaseApiModuleProvider
+ * Connects the assertions for the different methods and iterates
through the api modules
+ *
+ * @dataProvider wikibaseApiModuleProvider
*/
public function testApiConventions( $moduleClass ) {
$params = array();
$user = $GLOBALS['wgUser'];
- $request = new \FauxRequest( $params, true );
- $main = new \ApiMain( $request );
+ $request = new FauxRequest( $params, true );
+ $main = new ApiMain( $request );
$main->getContext()->setUser( $user );
$module = new $moduleClass( $main, 'moduleClass' );
$this->assertGetFinalParamDescription( $moduleClass, $module );
- $this->assertGetExamples( $moduleClass, $module );
$this->assertGetFinalDescription( $moduleClass, $module );
+ $this->assertGetExamplesMessages( $moduleClass, $module );
}
/**
* This method is for the assertions in particular for
getFinalDescription as defined in ApiBase
+ *
* @param string $moduleClass one of the modules in
$GLOBALS['wgAPIModules'], only in this function for the error messages
- * @param Module $module is an instance of $moduleClass
+ * @param ApiBase $module is an instance of $moduleClass
**/
- private function assertGetFinalDescription ( $moduleClass, $module ) {
+ private function assertGetFinalDescription ( $moduleClass, ApiBase
$module ) {
$method = 'getFinalDescription';
$descArray = $module->$method();
- $rMethod = new \ReflectionMethod( $module, $method );
+ $rMethod = new ReflectionMethod( $module, $method );
$this->assertTrue( $rMethod->isPublic(), 'the method ' .
$method . ' of module ' . $moduleClass . ' is not public' );
$this->assertNotEmpty( $module->$method(), 'the Module ' .
$moduleClass . ' does not have the method ' . $method );
@@ -68,39 +75,41 @@
/**
* This method is for the assertions for getFinalParamDescription as
defined in ApiBase, depending on getFinalParams
+ *
* @param string $moduleClass one of the modules in
$GLOBALS['wgAPIModules'], only in this function for the error messages
- * @param Module $module is an instance of $moduleClass
+ * @param ApiBase $module is an instance of $moduleClass
**/
- private function assertGetFinalParamDescription ( $moduleClass, $module
) {
+ private function assertGetFinalParamDescription ( $moduleClass, ApiBase
$module ) {
$method = 'getFinalParamDescription';
- $paramsMethod = 'getFinalParams';
- $paramsArray = $module->$paramsMethod();
+ $paramsArray = $module->getFinalParams();
+
if ( !empty( $paramsArray ) ) {
$paramDescArray = $module->$method();
$this->assertNotEmpty( $paramDescArray, 'the array
returned by the method ' . $method . ' of module ' . $moduleClass . ' is empty'
);
- //comparing the keys of the arrays of
getParamDescription and getParams
+ // Comparing the keys of the arrays of
getParamDescription and getParams
$arrayKeysMatch = !array_diff_key( $paramDescArray,
$paramsArray ) && !array_diff_key( $paramsArray, $paramDescArray );
$this->assertTrue( $arrayKeysMatch, 'keys different at
' . $moduleClass );
}
}
/**
- * This method is for the assertions of getExamples as defined in
ApiBase
+ * This method is for the assertions of getExamplesMessages/
getExamples as defined in ApiBase
+ *
* @param string $moduleClass one of the modules in
$GLOBALS['wgAPIModules'], only in this function for the error messages
- * @param Module $module is an instance of $moduleClass
+ * @param ApiBase $module is an instance of $moduleClass
**/
- private function assertGetExamples( $moduleClass, $module ) {
- $method = 'getExamples';
- $rMethod = new \ReflectionMethod( $moduleClass, $method );
+ private function assertGetExamplesMessages( $moduleClass, ApiBase
$module ) {
+ $method = 'getExamplesMessages';
+ $rMethod = new ReflectionMethod( $moduleClass, $method );
$rMethod->setAccessible( true );
$exArray = $rMethod->invoke( $module );
$this->assertNotEmpty( $exArray, 'there are no examples for ' .
$moduleClass );
foreach ( $exArray as $key => $value ) {
- $this->assertContains('api.php?action=', $key, 'the key
' . $key . ' is not an url at ' . $moduleClass );
- $this->assertInternalType( 'string', $value, 'the value
of the example for ' . $key . ' in ' . $moduleClass . ' is not a string' );
+ $this->assertRegExp( '/^action=\w/', $key, 'the key ' .
$key . ' is not an url at ' . $moduleClass );
+ $this->assertInstanceOf( 'Message', $value, 'the value
of the example for ' . $key . ' in ' . $moduleClass . ' is not a Message' );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/178140
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I69008ed8aebb819bd536d3e9e79d41cc64d3495d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits