Merge "tests/api: Add TestUser::getAuthority and use it"
This commit is contained in:
commit
c17df8ff78
17 changed files with 50 additions and 39 deletions
|
|
@ -2534,7 +2534,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
|
|||
* @param string|Content $content the new content of the page
|
||||
* @param string $summary Optional summary string for the revision
|
||||
* @param int $defaultNs Optional namespace id
|
||||
* @param Authority|null $performer If null, static::getTestUser()->getUser() is used.
|
||||
* @param Authority|null $performer If null, static::getTestUser()->getAuthority() is used.
|
||||
* @return Status Object as returned by WikiPage::doUserEditContent()
|
||||
* @throws MWException If this test cases's needsDB() method doesn't return true.
|
||||
* Test cases can use "@group Database" to enable database test support,
|
||||
|
|
@ -2568,7 +2568,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
|
|||
}
|
||||
|
||||
if ( $performer === null ) {
|
||||
$performer = static::getTestUser()->getUser();
|
||||
$performer = static::getTestUser()->getAuthority();
|
||||
}
|
||||
|
||||
if ( is_string( $content ) ) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Permissions\Authority;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
use MediaWiki\User\UserIdentityValue;
|
||||
|
||||
|
|
@ -164,6 +165,14 @@ class TestUser {
|
|||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.39
|
||||
* @return Authority
|
||||
*/
|
||||
public function getAuthority(): Authority {
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.36
|
||||
* @return UserIdentity
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ class ApiChangeContentModelTest extends ApiTestCase {
|
|||
$invalidJSON = 'Foo\nBar\nEaster egg\nT22281';
|
||||
$wikipage->doUserEditContent(
|
||||
ContentHandler::makeContent( $invalidJSON, $wikipage->getTitle() ),
|
||||
$this->getTestSysop()->getUser(),
|
||||
$this->getTestSysop()->getAuthority(),
|
||||
'EditSummaryForThisTest',
|
||||
EDIT_UPDATE | EDIT_SUPPRESS_RC
|
||||
);
|
||||
|
|
@ -224,7 +224,7 @@ class ApiChangeContentModelTest extends ApiTestCase {
|
|||
$dummyContent,
|
||||
'EditSummaryForThisTest',
|
||||
NS_MAIN,
|
||||
$this->getTestSysop()->getUser()
|
||||
$this->getTestSysop()->getAuthority()
|
||||
);
|
||||
$this->assertSame(
|
||||
'testing',
|
||||
|
|
|
|||
|
|
@ -18,13 +18,13 @@ class ApiComparePagesTest extends ApiTestCase {
|
|||
$content = $this->getServiceContainer()->getContentHandlerFactory()
|
||||
->getContentHandler( $model )
|
||||
->unserializeContent( $text );
|
||||
$user = static::getTestSysop()->getUser();
|
||||
$performer = static::getTestSysop()->getAuthority();
|
||||
$status = $this->editPage(
|
||||
$title,
|
||||
$content,
|
||||
'Test for ApiComparePagesTest: ' . $text,
|
||||
NS_MAIN,
|
||||
$user
|
||||
$performer
|
||||
);
|
||||
if ( !$status->isOK() ) {
|
||||
$this->fail( "Failed to create $title: " . $status->getWikiText( false, false, 'en' ) );
|
||||
|
|
@ -152,19 +152,19 @@ class ApiComparePagesTest extends ApiTestCase {
|
|||
'errorformat' => 'none',
|
||||
];
|
||||
|
||||
$user = $sysop
|
||||
? static::getTestSysop()->getUser()
|
||||
: static::getTestUser()->getUser();
|
||||
$performer = $sysop
|
||||
? static::getTestSysop()->getAuthority()
|
||||
: static::getTestUser()->getAuthority();
|
||||
if ( $exceptionCode ) {
|
||||
try {
|
||||
$this->doApiRequest( $params, null, false, $user );
|
||||
$this->doApiRequest( $params, null, false, $performer );
|
||||
$this->fail( 'Expected exception not thrown' );
|
||||
} catch ( ApiUsageException $ex ) {
|
||||
$this->assertTrue( $this->apiExceptionHasCode( $ex, $exceptionCode ),
|
||||
"Exception with code $exceptionCode" );
|
||||
}
|
||||
} else {
|
||||
$apiResult = $this->doApiRequest( $params, null, false, $user );
|
||||
$apiResult = $this->doApiRequest( $params, null, false, $performer );
|
||||
$apiResult = $apiResult[0];
|
||||
$this->doReplacements( $expect );
|
||||
$this->assertEquals( $expect, $apiResult );
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ class ApiEditPageTest extends ApiTestCase {
|
|||
// Preload the page with some text
|
||||
$page->doUserEditContent(
|
||||
ContentHandler::makeContent( $text, $page->getTitle() ),
|
||||
$this->getTestSysop()->getUser(),
|
||||
$this->getTestSysop()->getAuthority(),
|
||||
'summary'
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -230,7 +230,7 @@ class ApiParseTest extends ApiTestCase {
|
|||
$this->doApiRequest( [
|
||||
'action' => 'parse',
|
||||
'oldid' => self::$revIds['revdel'],
|
||||
], null, null, static::getTestUser()->getUser() );
|
||||
], null, null, static::getTestUser()->getAuthority() );
|
||||
}
|
||||
|
||||
public function testSuppressed() {
|
||||
|
|
|
|||
|
|
@ -244,26 +244,26 @@ class ApiStashEditTest extends ApiTestCase {
|
|||
$name = ucfirst( __FUNCTION__ );
|
||||
$title = Title::makeTitle( NS_MAIN, $name );
|
||||
$content = new CssContent( 'Css' );
|
||||
$user = $this->getTestSysop()->getUser();
|
||||
$performer = $this->getTestSysop()->getAuthority();
|
||||
$revRecord = $this->editPage(
|
||||
$title,
|
||||
$content,
|
||||
'',
|
||||
NS_MAIN,
|
||||
$user
|
||||
$performer
|
||||
)->value['revision-record'];
|
||||
$this->editPage(
|
||||
$title,
|
||||
new WikitextContent( 'Text' ),
|
||||
'',
|
||||
NS_MAIN,
|
||||
$user
|
||||
$performer
|
||||
);
|
||||
|
||||
$this->setExpectedApiException(
|
||||
[ 'apierror-contentmodel-mismatch', 'wikitext', 'css' ]
|
||||
);
|
||||
$this->doStash( [ 'title' => $name, 'baserevid' => $revRecord->getId() ] );
|
||||
$this->doStash( [ 'title' => $title->getPrefixedText(), 'baserevid' => $revRecord->getId() ] );
|
||||
}
|
||||
|
||||
public function testDeletedRevision() {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ use Wikimedia\TestingAccessWrapper;
|
|||
class ApiParamValidatorCallbacksTest extends ApiUploadTestCase {
|
||||
|
||||
private function getCallbacks( FauxRequest $request ): array {
|
||||
$context = $this->apiContext->newTestContext( $request, $this->getTestUser()->getUser() );
|
||||
$context = $this->apiContext->newTestContext( $request, $this->getTestUser()->getAuthority() );
|
||||
$main = new ApiMain( $context );
|
||||
return [ new ApiParamValidatorCallbacks( $main ), $main ];
|
||||
}
|
||||
|
|
@ -278,7 +278,7 @@ class ApiParamValidatorCallbacksTest extends ApiUploadTestCase {
|
|||
}
|
||||
|
||||
public function testUseHighLimits(): void {
|
||||
$context = $this->apiContext->newTestContext( new FauxRequest, $this->getTestUser()->getUser() );
|
||||
$context = $this->apiContext->newTestContext( new FauxRequest, $this->getTestUser()->getAuthority() );
|
||||
$main = $this->getMockBuilder( ApiMain::class )
|
||||
->setConstructorArgs( [ $context ] )
|
||||
->onlyMethods( [ 'canApiHighLimits' ] )
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use Wikimedia\TestingAccessWrapper;
|
|||
class ApiParamValidatorTest extends ApiTestCase {
|
||||
|
||||
private function getValidator( FauxRequest $request ): array {
|
||||
$context = $this->apiContext->newTestContext( $request, $this->getTestUser()->getUser() );
|
||||
$context = $this->apiContext->newTestContext( $request, $this->getTestUser()->getAuthority() );
|
||||
$main = new ApiMain( $context );
|
||||
return [
|
||||
new ApiParamValidator( $main, $this->getServiceContainer()->getObjectFactory() ),
|
||||
|
|
|
|||
|
|
@ -11,27 +11,27 @@ class ApiFormatXmlTest extends ApiFormatTestBase {
|
|||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
$user = self::getTestSysop()->getUser();
|
||||
$performer = self::getTestSysop()->getAuthority();
|
||||
$this->editPage(
|
||||
Title::makeTitle( NS_MEDIAWIKI, 'ApiFormatXmlTest.xsl' ),
|
||||
'<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" />',
|
||||
'Summary',
|
||||
NS_MAIN,
|
||||
$user
|
||||
$performer
|
||||
);
|
||||
$this->editPage(
|
||||
Title::makeTitle( NS_MEDIAWIKI, 'ApiFormatXmlTest' ),
|
||||
'Bogus',
|
||||
'Summary',
|
||||
NS_MAIN,
|
||||
$user
|
||||
$performer
|
||||
);
|
||||
$this->editPage(
|
||||
Title::makeTitle( NS_MAIN, 'ApiFormatXmlTest' ),
|
||||
'Bogus',
|
||||
'Summary',
|
||||
NS_MAIN,
|
||||
$user
|
||||
$performer
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class ApiQueryAllPagesTest extends ApiTestCase {
|
|||
'Some text',
|
||||
'inserting content',
|
||||
NS_MAIN,
|
||||
$this->getTestSysop()->getUser()
|
||||
$this->getTestSysop()->getAuthority()
|
||||
);
|
||||
|
||||
$result = $this->doApiRequest( [
|
||||
|
|
|
|||
|
|
@ -23,14 +23,14 @@ class ApiQueryAllRevisionsTest extends ApiTestCase {
|
|||
'Some text',
|
||||
'inserting content',
|
||||
NS_MAIN,
|
||||
$this->getTestSysop()->getUser()
|
||||
$this->getTestSysop()->getAuthority()
|
||||
);
|
||||
$this->editPage(
|
||||
$title,
|
||||
'Some other text',
|
||||
'adding revision',
|
||||
NS_MAIN,
|
||||
$this->getTestSysop()->getUser()
|
||||
$this->getTestSysop()->getAuthority()
|
||||
);
|
||||
|
||||
$apiResult = $this->doApiRequest( [
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ class ApiQueryImageInfoTest extends ApiTestCase {
|
|||
],
|
||||
null,
|
||||
false,
|
||||
$this->getTestUser()->getUser()
|
||||
$this->getTestUser()->getAuthority()
|
||||
);
|
||||
$image = $this->getImageInfoFromResult( $result );
|
||||
$this->assertSame( MWTimestamp::convert( TS_ISO_8601, self::OLD_IMAGE_TIMESTAMP ), $image['timestamp'] );
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Linker\LinkTarget;
|
||||
use MediaWiki\Permissions\Authority;
|
||||
|
||||
/**
|
||||
* @group API
|
||||
|
|
@ -20,7 +21,7 @@ class ApiQueryRecentChangesIntegrationTest extends ApiTestCase {
|
|||
return $this->getTestUser()->getUser();
|
||||
}
|
||||
|
||||
private function doPageEdit( User $user, LinkTarget $target, $summary ) {
|
||||
private function doPageEdit( Authority $performer, LinkTarget $target, $summary ) {
|
||||
static $i = 0;
|
||||
|
||||
$this->editPage(
|
||||
|
|
@ -28,7 +29,7 @@ class ApiQueryRecentChangesIntegrationTest extends ApiTestCase {
|
|||
__CLASS__ . $i++,
|
||||
$summary,
|
||||
NS_MAIN,
|
||||
$user
|
||||
$performer
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ class ApiQueryTokensTest extends ApiTestCase {
|
|||
'type' => 'csrf',
|
||||
];
|
||||
|
||||
$user = $this->getTestUser()->getUser();
|
||||
$performer = $this->getTestUser()->getAuthority();
|
||||
|
||||
$apiResult = $this->doApiRequest( $params, null, false, $user );
|
||||
$apiResult = $this->doApiRequest( $params, null, false, $performer );
|
||||
$this->assertArrayHasKey( 'query', $apiResult[0] );
|
||||
$this->assertArrayHasKey( 'tokens', $apiResult[0]['query'] );
|
||||
$this->assertArrayHasKey( 'csrftoken', $apiResult[0]['query']['tokens'] );
|
||||
|
|
@ -32,9 +32,9 @@ class ApiQueryTokensTest extends ApiTestCase {
|
|||
'type' => '*',
|
||||
];
|
||||
|
||||
$user = $this->getTestUser()->getUser();
|
||||
$performer = $this->getTestUser()->getAuthority();
|
||||
|
||||
$apiResult = $this->doApiRequest( $params, null, false, $user );
|
||||
$apiResult = $this->doApiRequest( $params, null, false, $performer );
|
||||
$this->assertArrayHasKey( 'query', $apiResult[0] );
|
||||
$this->assertArrayHasKey( 'tokens', $apiResult[0]['query'] );
|
||||
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@ class ApiQueryUserInfoTest extends ApiTestCase {
|
|||
];
|
||||
|
||||
$page = $this->getNonexistingTestPage();
|
||||
$user = $this->getTestUser()->getUser();
|
||||
$performer = $this->getTestUser()->getAuthority();
|
||||
|
||||
$apiResult = $this->doApiRequest( $params, null, false, $user );
|
||||
$apiResult = $this->doApiRequest( $params, null, false, $performer );
|
||||
$this->assertArrayNotHasKey( 'continue', $apiResult[0] );
|
||||
$this->assertArrayHasKey( 'query', $apiResult[0] );
|
||||
$this->assertArrayHasKey( 'userinfo', $apiResult[0]['query'] );
|
||||
|
|
@ -41,7 +41,7 @@ class ApiQueryUserInfoTest extends ApiTestCase {
|
|||
|
||||
$revisionTimestamp = MWTimestamp::convert( TS_ISO_8601, $page->getTimestamp() );
|
||||
|
||||
$apiResult = $this->doApiRequest( $params, null, false, $user );
|
||||
$apiResult = $this->doApiRequest( $params, null, false, $performer );
|
||||
$this->assertArrayNotHasKey( 'continue', $apiResult[0] );
|
||||
$this->assertArrayHasKey( 'query', $apiResult[0] );
|
||||
$this->assertArrayHasKey( 'userinfo', $apiResult[0]['query'] );
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Linker\LinkTarget;
|
||||
use MediaWiki\Permissions\Authority;
|
||||
use MediaWiki\Revision\SlotRecord;
|
||||
|
||||
/**
|
||||
|
|
@ -29,13 +30,13 @@ class ApiQueryWatchlistIntegrationTest extends ApiTestCase {
|
|||
return self::$users['ApiQueryWatchlistIntegrationTestUser2']->getUser();
|
||||
}
|
||||
|
||||
private function doPageEdit( User $user, LinkTarget $target, $content, $summary ) {
|
||||
private function doPageEdit( Authority $performer, LinkTarget $target, $content, $summary ) {
|
||||
$this->editPage(
|
||||
$target,
|
||||
$content,
|
||||
$summary,
|
||||
NS_MAIN,
|
||||
$user
|
||||
$performer
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue