Addshore has uploaded a new change for review. https://gerrit.wikimedia.org/r/77709
Change subject: All tests now use the base ...................................................................... All tests now use the base This allows us to use the requestWithToken Change-Id: I563266b33e4dc984f77918015df5e52926c1b219 --- M repo/tests/phpunit/includes/api/CreateClaimTest.php M repo/tests/phpunit/includes/api/RemoveClaimsTest.php M repo/tests/phpunit/includes/api/RemoveQualifiersTest.php M repo/tests/phpunit/includes/api/RemoveReferencesTest.php M repo/tests/phpunit/includes/api/SetClaimTest.php M repo/tests/phpunit/includes/api/SetClaimValueTest.php M repo/tests/phpunit/includes/api/SetQualifierTest.php M repo/tests/phpunit/includes/api/SetReferenceTest.php M repo/tests/phpunit/includes/api/SetStatementRankTest.php 9 files changed, 32 insertions(+), 58 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/09/77709/1 diff --git a/repo/tests/phpunit/includes/api/CreateClaimTest.php b/repo/tests/phpunit/includes/api/CreateClaimTest.php index 535c2be..498bc80 100644 --- a/repo/tests/phpunit/includes/api/CreateClaimTest.php +++ b/repo/tests/phpunit/includes/api/CreateClaimTest.php @@ -39,7 +39,7 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < jeroended...@gmail.com > */ -class CreateClaimTest extends \ApiTestCase { +class CreateClaimTest extends ModifyEntityTestBase { protected static function getNewEntityAndProperty() { $entity = \Wikibase\Item::newEmpty(); @@ -77,10 +77,9 @@ 'snaktype' => 'value', 'property' => $this->getFormattedIdForEntity( $property ), 'value' => '"Foo.png"', - 'token' => $GLOBALS['wgUser']->getEditToken() ); - list( $resultArray, ) = $this->doApiRequest( $params ); + list( $resultArray, ) = $this->doApiRequestWithToken( $params ); $this->assertRequestValidity( $resultArray ); @@ -226,8 +225,6 @@ */ list( $entity, $property ) = self::getEntityAndPropertyForInvalid(); - $params['token'] = $GLOBALS['wgUser']->getEditToken(); - if ( array_key_exists( 'entity', $params ) && $params['entity'] === '-' ) { $params['entity'] = $this->getFormattedIdForEntity( $entity ); } @@ -237,8 +234,8 @@ } try { - $this->doApiRequest( $params ); - $this->assertFalse( true, 'Invalid request should raise an exception' ); + $this->doApiRequestWithToken( $params ); + $this->fail( 'Invalid request should raise an exception' ); } catch ( \UsageException $e ) { $this->assertEquals( $errorCode, $e->getCodeString(), 'Invalid request raised correct error' ); @@ -267,10 +264,9 @@ 'snaktype' => 'value', 'property' => $this->getFormattedIdForEntity( $property ), 'value' => '"Foo.png"', - 'token' => $GLOBALS['wgUser']->getEditToken() ); - list( $resultArray, ) = $this->doApiRequest( $params ); + list( $resultArray, ) = $this->doApiRequestWithToken( $params ); $this->assertRequestValidity( $resultArray ); @@ -284,11 +280,10 @@ 'snaktype' => 'value', 'property' => $this->getFormattedIdForEntity( $property ), 'value' => '"Bar.jpg"', - 'token' => $GLOBALS['wgUser']->getEditToken(), 'baserevid' => $revId ); - list( $resultArray, ) = $this->doApiRequest( $params ); + list( $resultArray, ) = $this->doApiRequestWithToken( $params ); $this->assertRequestValidity( $resultArray ); diff --git a/repo/tests/phpunit/includes/api/RemoveClaimsTest.php b/repo/tests/phpunit/includes/api/RemoveClaimsTest.php index ea84cdc..ed2971a 100644 --- a/repo/tests/phpunit/includes/api/RemoveClaimsTest.php +++ b/repo/tests/phpunit/includes/api/RemoveClaimsTest.php @@ -40,7 +40,7 @@ * @author Jeroen De Dauw < jeroended...@gmail.com > * @author Katie Filbert < aude.w...@gmail.com > */ -class RemoveClaimsTest extends \ApiTestCase { +class RemoveClaimsTest extends ModifyEntityTestBase { /** * @param Entity $entity @@ -131,10 +131,9 @@ $params = array( 'action' => 'wbremoveclaims', 'claim' => implode( '|', $claimGuids ), - 'token' => $GLOBALS['wgUser']->getEditToken() ); - list( $resultArray, ) = $this->doApiRequest( $params ); + list( $resultArray, ) = $this->doApiRequestWithToken( $params ); $this->assertInternalType( 'array', $resultArray, 'top level element is an array' ); $this->assertArrayHasKey( 'claims', $resultArray, 'top level element has a claims key' ); @@ -155,10 +154,9 @@ $params = array( 'action' => 'wbremoveclaims', 'claim' => is_array( $claimGuids ) ? implode( '|', $claimGuids ) : $claimGuids, - 'token' => $GLOBALS['wgUser']->getEditToken() ); - $this->doApiRequest( $params ); + $this->doApiRequestWithToken( $params ); } public function invalidClaimProvider() { diff --git a/repo/tests/phpunit/includes/api/RemoveQualifiersTest.php b/repo/tests/phpunit/includes/api/RemoveQualifiersTest.php index 66e8ebd..3c6b171 100644 --- a/repo/tests/phpunit/includes/api/RemoveQualifiersTest.php +++ b/repo/tests/phpunit/includes/api/RemoveQualifiersTest.php @@ -40,7 +40,7 @@ * @author Jeroen De Dauw < jeroended...@gmail.com > * @author Katie Filbert < aude.w...@gmail.com > */ -class RemoveQualifiersTest extends \ApiTestCase { +class RemoveQualifiersTest extends ModifyEntityTestBase { /** * @return Snak[] @@ -127,10 +127,9 @@ 'action' => 'wbremovequalifiers', 'claim' => $statementGuid, 'qualifiers' => implode( '|', $hashes ), - 'token' => $GLOBALS['wgUser']->getEditToken() ); - list( $resultArray, ) = $this->doApiRequest( $params ); + list( $resultArray, ) = $this->doApiRequestWithToken( $params ); $this->assertInternalType( 'array', $resultArray, 'top level element is an array' ); $this->assertArrayHasKey( 'pageinfo', $resultArray, 'top level element has a pageinfo key' ); @@ -143,11 +142,10 @@ 'action' => 'wbremovequalifiers', 'claim' => $statementGuid, 'qualifiers' => implode( '|', $hashes ), - 'token' => $GLOBALS['wgUser']->getEditToken() ); try { - $this->doApiRequest( $params ); + $this->doApiRequestWithToken( $params ); $this->assertFalse( true, 'Invalid request should raise an exception' ); } catch ( \UsageException $e ) { @@ -170,11 +168,10 @@ 'action' => 'wbremovequalifiers', 'claim' => $claimGuid, 'qualifiers' => $hash, - 'token' => $GLOBALS['wgUser']->getEditToken() ); try { - $this->doApiRequest( $params ); + $this->doApiRequestWithToken( $params ); } catch ( \UsageException $e ) { $this->assertEquals( $e->getCodeString(), 'invalid-guid', 'Invalid claim guid raised correct error' ); $caughtException = true; diff --git a/repo/tests/phpunit/includes/api/RemoveReferencesTest.php b/repo/tests/phpunit/includes/api/RemoveReferencesTest.php index 6f6a6a6..e2961d5 100644 --- a/repo/tests/phpunit/includes/api/RemoveReferencesTest.php +++ b/repo/tests/phpunit/includes/api/RemoveReferencesTest.php @@ -41,7 +41,7 @@ * @author Jeroen De Dauw < jeroended...@gmail.com > * @author Katie Filbert < aude.w...@gmail.com > */ -class RemoveReferencesTest extends \ApiTestCase { +class RemoveReferencesTest extends ModifyEntityTestBase { /** * @return Snak[] @@ -128,10 +128,9 @@ 'action' => 'wbremovereferences', 'statement' => $statementGuid, 'references' => implode( '|', $hashes ), - 'token' => $GLOBALS['wgUser']->getEditToken() ); - list( $resultArray, ) = $this->doApiRequest( $params ); + list( $resultArray, ) = $this->doApiRequestWithToken( $params ); $this->assertInternalType( 'array', $resultArray, 'top level element is an array' ); $this->assertArrayHasKey( 'pageinfo', $resultArray, 'top level element has a pageinfo key' ); @@ -144,11 +143,10 @@ 'action' => 'wbremovereferences', 'statement' => $statementGuid, 'references' => implode( '|', $hashes ), - 'token' => $GLOBALS['wgUser']->getEditToken() ); try { - $this->doApiRequest( $params ); + $this->doApiRequestWithToken( $params ); $this->assertFalse( true, 'Invalid request should raise an exception' ); } catch ( \UsageException $e ) { @@ -171,11 +169,10 @@ 'action' => 'wbremovereferences', 'statement' => $statementGuid, 'references' => $hash, - 'token' => $GLOBALS['wgUser']->getEditToken() ); try { - $this->doApiRequest( $params ); + $this->doApiRequestWithToken( $params ); } catch ( \UsageException $e ) { $this->assertEquals( 'invalid-guid', $e->getCodeString(), 'Invalid claim guid raised correct error' ); $caughtException = true; diff --git a/repo/tests/phpunit/includes/api/SetClaimTest.php b/repo/tests/phpunit/includes/api/SetClaimTest.php index 1bd2a4d..f4f64ba 100644 --- a/repo/tests/phpunit/includes/api/SetClaimTest.php +++ b/repo/tests/phpunit/includes/api/SetClaimTest.php @@ -42,7 +42,7 @@ * @author Jeroen De Dauw < jeroended...@gmail.com > * @author Daniel Kinzler */ -class SetClaimTest extends \ApiTestCase { +class SetClaimTest extends ModifyEntityTestBase { /** * @return \Wikibase\Snak[] @@ -150,7 +150,6 @@ $params = array( 'action' => 'wbsetclaim', 'claim' => \FormatJson::encode( $serializer->getSerialized( $claim ) ), - 'token' => $GLOBALS['wgUser']->getEditToken() ); $this->makeValidRequest( $params ); @@ -167,7 +166,7 @@ } protected function makeValidRequest( array $params ) { - list( $resultArray, ) = $this->doApiRequest( $params ); + list( $resultArray, ) = $this->doApiRequestWithToken( $params ); $this->assertInternalType( 'array', $resultArray, 'top level element is an array' ); $this->assertArrayHasKey( 'pageinfo', $resultArray, 'top level element has a pageinfo key' ); diff --git a/repo/tests/phpunit/includes/api/SetClaimValueTest.php b/repo/tests/phpunit/includes/api/SetClaimValueTest.php index f92748d..623666f 100644 --- a/repo/tests/phpunit/includes/api/SetClaimValueTest.php +++ b/repo/tests/phpunit/includes/api/SetClaimValueTest.php @@ -41,7 +41,7 @@ * @author Jeroen De Dauw < jeroended...@gmail.com > * @author Katie Filbert < aude.w...@gmail.com > */ -class SetClaimValueTest extends \ApiTestCase { +class SetClaimValueTest extends ModifyEntityTestBase { /** * @param Entity $entity @@ -106,10 +106,9 @@ 'claim' => $claimGuid, 'value' => \FormatJson::encode( $value ), 'snaktype' => 'value', - 'token' => $GLOBALS['wgUser']->getEditToken() ); - list( $resultArray, ) = $this->doApiRequest( $params ); + list( $resultArray, ) = $this->doApiRequestWithToken( $params ); $this->assertInternalType( 'array', $resultArray, 'top level element is an array' ); $this->assertArrayHasKey( 'claim', $resultArray, 'top level element has a claim key' ); @@ -143,11 +142,10 @@ 'claim' => $claimGuid, 'snaktype' => 'value', 'value' => 'abc', - 'token' => $GLOBALS['wgUser']->getEditToken() ); try { - $this->doApiRequest( $params ); + $this->doApiRequestWithToken( $params ); } catch ( \UsageException $e ) { $this->assertEquals( 'invalid-guid', $e->getCodeString(), 'Invalid claim guid raised correct error' ); $caughtException = true; diff --git a/repo/tests/phpunit/includes/api/SetQualifierTest.php b/repo/tests/phpunit/includes/api/SetQualifierTest.php index e8ed394..5d2d9a3 100644 --- a/repo/tests/phpunit/includes/api/SetQualifierTest.php +++ b/repo/tests/phpunit/includes/api/SetQualifierTest.php @@ -172,14 +172,11 @@ } protected function makeAddRequest( $statementGuid, Snak $qualifier, EntityId $entityId ) { - $token = $this->getEditToken(); - $params = array( 'action' => 'wbsetqualifier', 'claim' => $statementGuid, 'snaktype' => $qualifier->getType(), 'property' => $qualifier->getPropertyId()->getPrefixedId(), - 'token' => $token ); if ( $qualifier instanceof \Wikibase\PropertyValueSnak ) { @@ -206,7 +203,7 @@ } protected function makeValidRequest( array $params ) { - list( $resultArray, ) = $this->doApiRequest( $params ); + list( $resultArray, ) = $this->doApiRequestWithToken( $params ); $this->assertInternalType( 'array', $resultArray, 'top level element is an array' ); $this->assertArrayHasKey( 'pageinfo', $resultArray, 'top level element has a pageinfo key' ); @@ -230,11 +227,10 @@ 'property' => 7, 'snaktype' => 'value', 'value' => 'abc', - 'token' => $GLOBALS['wgUser']->getEditToken() ); try { - $this->doApiRequest( $params ); + $this->doApiRequestWithToken( $params ); } catch ( \UsageException $e ) { $this->assertEquals( 'invalid-guid', $e->getCodeString(), 'Invalid claim guid raised correct error' ); $caughtException = true; diff --git a/repo/tests/phpunit/includes/api/SetReferenceTest.php b/repo/tests/phpunit/includes/api/SetReferenceTest.php index cfc9c4e..1d778a2 100644 --- a/repo/tests/phpunit/includes/api/SetReferenceTest.php +++ b/repo/tests/phpunit/includes/api/SetReferenceTest.php @@ -41,7 +41,7 @@ * @author Katie Filbert < aude.w...@gmail.com > * @author Daniel Kinzler */ -class SetReferenceTest extends \ApiTestCase { +class SetReferenceTest extends ModifyEntityTestBase { public function setUp() { static $hasProperties = false; @@ -110,10 +110,9 @@ 'statement' => $statementGuid, 'reference' => $referenceHash, 'snaks' => \FormatJson::encode( $serializedReference['snaks'] ), - 'token' => $GLOBALS['wgUser']->getEditToken() ); - list( $resultArray, ) = $this->doApiRequest( $params ); + list( $resultArray, ) = $this->doApiRequestWithToken( $params ); $this->assertInternalType( 'array', $resultArray, 'top level element is an array' ); $this->assertArrayHasKey( 'reference', $resultArray, 'top level element has a reference key' ); @@ -134,11 +133,10 @@ 'statement' => $statementGuid, 'reference' => $referenceHash, 'snaks' => \FormatJson::encode( $serializedReference['snaks'] ), - 'token' => $GLOBALS['wgUser']->getEditToken() ); try { - $this->doApiRequest( $params ); + $this->doApiRequestWithToken( $params ); $this->assertFalse( true, 'Invalid request should raise an exception' ); } catch ( \UsageException $e ) { @@ -157,11 +155,10 @@ 'statement' => $claimGuid, 'snaks' => $snakHash, 'reference' => $refHash, - 'token' => $GLOBALS['wgUser']->getEditToken() ); try { - $this->doApiRequest( $params ); + $this->doApiRequestWithToken( $params ); $this->fail( "Exception with code $expectedError expected" ); } catch ( \UsageException $e ) { $this->assertEquals( $expectedError, $e->getCodeString(), 'Error code' ); diff --git a/repo/tests/phpunit/includes/api/SetStatementRankTest.php b/repo/tests/phpunit/includes/api/SetStatementRankTest.php index 236112a..1e1092a 100644 --- a/repo/tests/phpunit/includes/api/SetStatementRankTest.php +++ b/repo/tests/phpunit/includes/api/SetStatementRankTest.php @@ -42,7 +42,7 @@ * @author Jeroen De Dauw < jeroended...@gmail.com > * @author Katie Filbert < aude.w...@gmail.com > */ -class SetStatementRankTest extends \ApiTestCase { +class SetStatementRankTest extends ModifyEntityTestBase { /** * @return Snak[] @@ -143,10 +143,9 @@ 'action' => 'wbsetstatementrank', 'statement' => $statementGuid, 'rank' => $statementRank, - 'token' => $GLOBALS['wgUser']->getEditToken() ); - list( $resultArray, ) = $this->doApiRequest( $params ); + list( $resultArray, ) = $this->doApiRequestWithToken( $params ); $this->assertInternalType( 'array', $resultArray, 'top level element is an array' ); $this->assertArrayHasKey( 'pageinfo', $resultArray, 'top level element has a pageinfo key' ); @@ -183,11 +182,10 @@ 'action' => 'wbsetstatementrank', 'statement' => $statementGuid, 'rank' => $statementRank, - 'token' => $GLOBALS['wgUser']->getEditToken() ); try { - $this->doApiRequest( $params ); + $this->doApiRequestWithToken( $params ); $this->assertFalse( true, 'Invalid request should raise an exception' ); } catch ( \Exception $e ) { @@ -220,11 +218,10 @@ 'action' => 'wbsetstatementrank', 'statement' => $claimGuid, 'rank' => $ranks[0], - 'token' => $GLOBALS['wgUser']->getEditToken() ); try { - $this->doApiRequest( $params ); + $this->doApiRequestWithToken( $params ); } catch ( \UsageException $e ) { $this->assertEquals( 'invalid-guid', $e->getCodeString(), 'Invalid claim guid raised correct error' ); $caughtException = true; -- To view, visit https://gerrit.wikimedia.org/r/77709 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I563266b33e4dc984f77918015df5e52926c1b219 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Addshore <addshorew...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits