jenkins-bot has submitted this change and it was merged.
Change subject: Move queryExceptionTest to ApiTestBase
......................................................................
Move queryExceptionTest to ApiTestBase
This makes sense as all api queries can throw
these exceptions and the format of the check
is always the same
Change-Id: I476bfed19f8aadb48ff8ca2de192bc2d5410a21d
---
M repo/tests/phpunit/includes/api/LangAttributeTestCase.php
M repo/tests/phpunit/includes/api/LinkTitlesTest.php
M repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
3 files changed, 45 insertions(+), 62 deletions(-)
Approvals:
Tobias Gritschacher: Looks good to me, approved
jenkins-bot: Verified
diff --git a/repo/tests/phpunit/includes/api/LangAttributeTestCase.php
b/repo/tests/phpunit/includes/api/LangAttributeTestCase.php
index dfeafa7..b45f8b9 100644
--- a/repo/tests/phpunit/includes/api/LangAttributeTestCase.php
+++ b/repo/tests/phpunit/includes/api/LangAttributeTestCase.php
@@ -55,9 +55,15 @@
protected static $testAction;
protected static $testId;
+ private static $hasSetup;
public function setUp() {
parent::setUp();
+
+ if( !isset( self::$hasSetup ) ){
+ $this->initTestEntities( array( 'Empty') );
+ }
+ self::$hasSetup = true;
}
public static function provideData() {
@@ -88,10 +94,10 @@
'e' => array( 'value' => array( 'bat-smg' =>
'V?sata' ) ) ),
array( //7
'p' => array( 'language' => 'bat-smg', 'value'
=> '' ),
- 'e' => array() ),
+ 'e' => array( ) ),
);
}
-
+
public function doTestSetLangAttribute( $attribute ,$params, $expected
){
// -- set any defaults ------------------------------------
$params['action'] = self::$testAction;
@@ -112,18 +118,18 @@
// -- check the result only has our changed data (if any)
------------
$this->assertEquals( 1, count( $result['entity'][$attribute] ),
"Entity return contained more than a single language" );
- $this->assertArrayHasKey( $params['language'],
$result['entity'][$attribute], "Entity doesn't return expected language" );
+ $this->assertArrayHasKey( $params['language'],
$result['entity'][$attribute], "Entity doesn't return expected language");
$this->assertEquals( $params['language'],
$result['entity'][$attribute][ $params['language'] ]['language'], "Returned
incorrect language" );
if( array_key_exists( $params['language'], $expected['value'] )
){
$this->assertEquals( $expected['value'][
$params['language'] ],
$result['entity'][$attribute][$params['language']]['value'] , "Returned
incorrect label" );
} else if( empty( $value ) ){
- $this->assertArrayHasKey( 'removed',
$result['entity'][$attribute][ $params['language'] ], "Entity doesn't return
expected 'removed' marker" );
+ $this->assertArrayHasKey( 'removed',
$result['entity'][$attribute][ $params['language'] ], "Entity doesn't return
expected 'removed' marker");
}
// -- check any warnings
----------------------------------------------
if( array_key_exists( 'warning', $expected ) ){
$this->assertArrayHasKey( 'warnings', $result, "Missing
'warnings' section in response." );
- $this->assertEquals( $expected['warning'],
$result['warnings']['messages']['0']['name'] );
+ $this->assertEquals( $expected['warning'],
$result['warnings']['messages']['0']['name']);
$this->assertArrayHasKey( 'html',
$result['warnings']['messages'] );
}
@@ -143,7 +149,7 @@
// -- check the edit summary
--------------------------------------------
if( !array_key_exists( 'warning', $expected ) ||
$expected['warning'] != 'edit-no-change' ){
$this->assertRevisionSummary( array( self::$testAction,
$params['language'] ), $result['entity']['lastrevid'] );
- if( array_key_exists( 'summary', $params ) ){
+ if( array_key_exists( 'summary', $params) ){
$this->assertRevisionSummary(
"/{$params['summary']}/" , $result['entity']['lastrevid'] );
}
}
@@ -188,34 +194,7 @@
if( !array_key_exists( 'id', $params ) && !array_key_exists(
'site', $params ) && !array_key_exists( 'title', $params ) ){
$params['id'] = EntityTestHelper::getId( 'Empty' );
}
-
- // -- catch and check expected exceptions ---------------------
- try{
- if( $expected['exception']['code'] == 'badtoken' ){
- if ( !self::$usetoken ) {
- $this->markTestSkipped( "tokens
disabled" );
- }
- $this->doApiRequest( $params );
- } else {
- $this->doApiRequestWithToken( $params );
- }
- $this->fail( "Failed to throw exception,
{$expected['exception']['type']}" );
-
- } catch( \Exception $exception ){
-
- /** @var $exception \UsageException */ // trick IDEs
into not showing errors
- if( array_key_exists( 'type', $expected['exception'] )
){
- $this->assertInstanceOf(
$expected['exception']['type'], $exception );
- }
-
- if( array_key_exists( 'code', $expected['exception'] )
){
- $this->assertEquals(
$expected['exception']['code'], $exception->getCodeString() );
- }
-
- if( array_key_exists( 'message', $expected['exception']
) ){
- $this->assertContains(
$expected['exception']['message'], $exception->getMessage() );
- }
- }
+ $this->doTestQueryExceptions( $params, $expected['exception'] );
}
}
diff --git a/repo/tests/phpunit/includes/api/LinkTitlesTest.php
b/repo/tests/phpunit/includes/api/LinkTitlesTest.php
index e7aae2c..bd3404e 100644
--- a/repo/tests/phpunit/includes/api/LinkTitlesTest.php
+++ b/repo/tests/phpunit/includes/api/LinkTitlesTest.php
@@ -147,34 +147,7 @@
public function testLinkTitlesExceptions( $params, $expected ){
// -- set any defaults ------------------------------------
$params['action'] = 'wblinktitles';
-
- // -- catch and check expected exceptions ---------------------
- try{
- if( $expected['exception']['code'] == 'badtoken' ){
- if ( !self::$usetoken ) {
- $this->markTestSkipped( "tokens
disabled" );
- }
- $this->doApiRequest( $params );
- } else {
- $this->doApiRequestWithToken( $params );
- }
- $this->fail( "Failed to throw exception,
{$expected['exception']['type']} " );
-
- } catch( \Exception $exception ){
-
- /** @var $exception \UsageException */ // trick IDEs
into not showing errors
- if( array_key_exists( 'type', $expected['exception'] )
){
- $this->assertInstanceOf(
$expected['exception']['type'], $exception );
- }
-
- if( array_key_exists( 'code', $expected['exception'] )
){
- $this->assertEquals(
$expected['exception']['code'], $exception->getCodeString() );
- }
-
- if( array_key_exists( 'message', $expected['exception']
) ){
- $this->assertContains(
$expected['exception']['message'], $exception->getMessage() );
- }
- }
+ $this->doTestQueryExceptions( $params, $expected['exception'] );
}
}
diff --git a/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
b/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
index 88605a9..8bc215b 100644
--- a/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
+++ b/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
@@ -145,6 +145,37 @@
}
/**
+ * Do the test for exceptions from Api queries.
+ * @param $params array of params for the api query
+ * @param $exception array details of the exception to expect
(type,code,message)
+ */
+ public function doTestQueryExceptions( $params, $exception ){
+ try{
+ if( array_key_exists( 'code', $exception ) &&
$exception['code'] == 'badtoken' ){
+ if ( !self::$usetoken ) {
+ $this->markTestSkipped( "tokens
disabled" );
+ }
+ $this->doApiRequest( $params );
+ } else {
+ $this->doApiRequestWithToken( $params );
+ }
+ $this->fail( "Failed to throw exception,
{$exception['type']} " );
+
+ } catch( \Exception $e ){
+ /** @var $e \UsageException */ // trick IDEs into not
showing errors
+ if( array_key_exists( 'type', $exception ) ){
+ $this->assertInstanceOf( $exception['type'], $e
);
+ }
+ if( array_key_exists( 'code', $exception ) ){
+ $this->assertEquals( $exception['code'],
$e->getCodeString() );
+ }
+ if( array_key_exists( 'message', $exception ) ){
+ $this->assertContains( $exception['message'],
$e->getMessage() );
+ }
+ }
+ }
+
+ /**
* Utility function for converting an array from "deep" (indexed) to
"flat" (keyed) structure.
* Arrays that already use a flat structure are left unchanged.
*
--
To view, visit https://gerrit.wikimedia.org/r/78522
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I476bfed19f8aadb48ff8ca2de192bc2d5410a21d
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Daniel Werner <[email protected]>
Gerrit-Reviewer: Hoo man <[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