aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit
diff options
context:
space:
mode:
authorUmherirrender <umherirrender_de.wp@web.de>2022-08-05 21:39:42 +0200
committerUmherirrender <umherirrender_de.wp@web.de>2022-08-06 23:15:27 +0200
commitef0623ec06e2bf80080bf12cf370e42baf5475af (patch)
tree36df7f92a1c867df14a60a47efa2334e6c6dc760 /tests/phpunit
parent6a8f3b4c55124b0a28c67d4f019e9c724c28683e (diff)
downloadmediawikicore-ef0623ec06e2bf80080bf12cf370e42baf5475af.tar.gz
mediawikicore-ef0623ec06e2bf80080bf12cf370e42baf5475af.zip
tests/api: Add TestUser::getAuthority and use it
Change-Id: Icfb66f9927c8e67582010a208538b0b5e0ba353f
Diffstat (limited to 'tests/phpunit')
-rw-r--r--tests/phpunit/MediaWikiIntegrationTestCase.php4
-rw-r--r--tests/phpunit/includes/TestUser.php9
-rw-r--r--tests/phpunit/includes/api/ApiChangeContentModelTest.php4
-rw-r--r--tests/phpunit/includes/api/ApiComparePagesTest.php14
-rw-r--r--tests/phpunit/includes/api/ApiEditPageTest.php2
-rw-r--r--tests/phpunit/includes/api/ApiParseTest.php2
-rw-r--r--tests/phpunit/includes/api/ApiStashEditTest.php8
-rw-r--r--tests/phpunit/includes/api/Validator/ApiParamValidatorCallbacksTest.php4
-rw-r--r--tests/phpunit/includes/api/Validator/ApiParamValidatorTest.php2
-rw-r--r--tests/phpunit/includes/api/format/ApiFormatXmlTest.php8
-rw-r--r--tests/phpunit/includes/api/query/ApiQueryAllPagesTest.php2
-rw-r--r--tests/phpunit/includes/api/query/ApiQueryAllRevisionsTest.php4
-rw-r--r--tests/phpunit/includes/api/query/ApiQueryImageInfoTest.php2
-rw-r--r--tests/phpunit/includes/api/query/ApiQueryRecentChangesIntegrationTest.php5
-rw-r--r--tests/phpunit/includes/api/query/ApiQueryTokensTest.php8
-rw-r--r--tests/phpunit/includes/api/query/ApiQueryUserInfoTest.php6
-rw-r--r--tests/phpunit/includes/api/query/ApiQueryWatchlistIntegrationTest.php5
-rw-r--r--tests/phpunit/integration/includes/CommentFormatter/CommentParserTest.php1
18 files changed, 51 insertions, 39 deletions
diff --git a/tests/phpunit/MediaWikiIntegrationTestCase.php b/tests/phpunit/MediaWikiIntegrationTestCase.php
index 57b609eafeb2..094040ab0b56 100644
--- a/tests/phpunit/MediaWikiIntegrationTestCase.php
+++ b/tests/phpunit/MediaWikiIntegrationTestCase.php
@@ -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 ) ) {
diff --git a/tests/phpunit/includes/TestUser.php b/tests/phpunit/includes/TestUser.php
index 7dfe6a480433..d71035bd5516 100644
--- a/tests/phpunit/includes/TestUser.php
+++ b/tests/phpunit/includes/TestUser.php
@@ -1,6 +1,7 @@
<?php
use MediaWiki\MediaWikiServices;
+use MediaWiki\Permissions\Authority;
use MediaWiki\User\UserIdentity;
use MediaWiki\User\UserIdentityValue;
@@ -165,6 +166,14 @@ class TestUser {
}
/**
+ * @since 1.39
+ * @return Authority
+ */
+ public function getAuthority(): Authority {
+ return $this->user;
+ }
+
+ /**
* @since 1.36
* @return UserIdentity
*/
diff --git a/tests/phpunit/includes/api/ApiChangeContentModelTest.php b/tests/phpunit/includes/api/ApiChangeContentModelTest.php
index 627d750f2613..92fd6f266a68 100644
--- a/tests/phpunit/includes/api/ApiChangeContentModelTest.php
+++ b/tests/phpunit/includes/api/ApiChangeContentModelTest.php
@@ -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',
diff --git a/tests/phpunit/includes/api/ApiComparePagesTest.php b/tests/phpunit/includes/api/ApiComparePagesTest.php
index 28777f0046f1..7c07d4121307 100644
--- a/tests/phpunit/includes/api/ApiComparePagesTest.php
+++ b/tests/phpunit/includes/api/ApiComparePagesTest.php
@@ -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 );
diff --git a/tests/phpunit/includes/api/ApiEditPageTest.php b/tests/phpunit/includes/api/ApiEditPageTest.php
index 3ac3fc369942..bfd7378dfb43 100644
--- a/tests/phpunit/includes/api/ApiEditPageTest.php
+++ b/tests/phpunit/includes/api/ApiEditPageTest.php
@@ -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'
);
diff --git a/tests/phpunit/includes/api/ApiParseTest.php b/tests/phpunit/includes/api/ApiParseTest.php
index 4d43eb240936..ad1f39a918b2 100644
--- a/tests/phpunit/includes/api/ApiParseTest.php
+++ b/tests/phpunit/includes/api/ApiParseTest.php
@@ -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() {
diff --git a/tests/phpunit/includes/api/ApiStashEditTest.php b/tests/phpunit/includes/api/ApiStashEditTest.php
index acab37c8c6da..6b89bcfb3b3c 100644
--- a/tests/phpunit/includes/api/ApiStashEditTest.php
+++ b/tests/phpunit/includes/api/ApiStashEditTest.php
@@ -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() {
diff --git a/tests/phpunit/includes/api/Validator/ApiParamValidatorCallbacksTest.php b/tests/phpunit/includes/api/Validator/ApiParamValidatorCallbacksTest.php
index e70401940b5a..35eef282fe9e 100644
--- a/tests/phpunit/includes/api/Validator/ApiParamValidatorCallbacksTest.php
+++ b/tests/phpunit/includes/api/Validator/ApiParamValidatorCallbacksTest.php
@@ -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' ] )
diff --git a/tests/phpunit/includes/api/Validator/ApiParamValidatorTest.php b/tests/phpunit/includes/api/Validator/ApiParamValidatorTest.php
index 9e94ec3c35be..8054e392a886 100644
--- a/tests/phpunit/includes/api/Validator/ApiParamValidatorTest.php
+++ b/tests/phpunit/includes/api/Validator/ApiParamValidatorTest.php
@@ -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() ),
diff --git a/tests/phpunit/includes/api/format/ApiFormatXmlTest.php b/tests/phpunit/includes/api/format/ApiFormatXmlTest.php
index b0a542a90318..28a9e9e971e7 100644
--- a/tests/phpunit/includes/api/format/ApiFormatXmlTest.php
+++ b/tests/phpunit/includes/api/format/ApiFormatXmlTest.php
@@ -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
);
}
diff --git a/tests/phpunit/includes/api/query/ApiQueryAllPagesTest.php b/tests/phpunit/includes/api/query/ApiQueryAllPagesTest.php
index bf7b097cdeb8..d30196ecff9e 100644
--- a/tests/phpunit/includes/api/query/ApiQueryAllPagesTest.php
+++ b/tests/phpunit/includes/api/query/ApiQueryAllPagesTest.php
@@ -20,7 +20,7 @@ class ApiQueryAllPagesTest extends ApiTestCase {
'Some text',
'inserting content',
NS_MAIN,
- $this->getTestSysop()->getUser()
+ $this->getTestSysop()->getAuthority()
);
$result = $this->doApiRequest( [
diff --git a/tests/phpunit/includes/api/query/ApiQueryAllRevisionsTest.php b/tests/phpunit/includes/api/query/ApiQueryAllRevisionsTest.php
index cd78526d0aa4..3710ca453c11 100644
--- a/tests/phpunit/includes/api/query/ApiQueryAllRevisionsTest.php
+++ b/tests/phpunit/includes/api/query/ApiQueryAllRevisionsTest.php
@@ -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( [
diff --git a/tests/phpunit/includes/api/query/ApiQueryImageInfoTest.php b/tests/phpunit/includes/api/query/ApiQueryImageInfoTest.php
index fb5f729668ab..8c4bdf4800c3 100644
--- a/tests/phpunit/includes/api/query/ApiQueryImageInfoTest.php
+++ b/tests/phpunit/includes/api/query/ApiQueryImageInfoTest.php
@@ -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'] );
diff --git a/tests/phpunit/includes/api/query/ApiQueryRecentChangesIntegrationTest.php b/tests/phpunit/includes/api/query/ApiQueryRecentChangesIntegrationTest.php
index 9f92de297f47..334410eb5b17 100644
--- a/tests/phpunit/includes/api/query/ApiQueryRecentChangesIntegrationTest.php
+++ b/tests/phpunit/includes/api/query/ApiQueryRecentChangesIntegrationTest.php
@@ -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
);
}
diff --git a/tests/phpunit/includes/api/query/ApiQueryTokensTest.php b/tests/phpunit/includes/api/query/ApiQueryTokensTest.php
index 4055baf1cd08..219b300ed642 100644
--- a/tests/phpunit/includes/api/query/ApiQueryTokensTest.php
+++ b/tests/phpunit/includes/api/query/ApiQueryTokensTest.php
@@ -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'] );
diff --git a/tests/phpunit/includes/api/query/ApiQueryUserInfoTest.php b/tests/phpunit/includes/api/query/ApiQueryUserInfoTest.php
index 2dc2c1ce3932..abbac8224488 100644
--- a/tests/phpunit/includes/api/query/ApiQueryUserInfoTest.php
+++ b/tests/phpunit/includes/api/query/ApiQueryUserInfoTest.php
@@ -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'] );
diff --git a/tests/phpunit/includes/api/query/ApiQueryWatchlistIntegrationTest.php b/tests/phpunit/includes/api/query/ApiQueryWatchlistIntegrationTest.php
index 79bfeb02f524..9e88d5e1a239 100644
--- a/tests/phpunit/includes/api/query/ApiQueryWatchlistIntegrationTest.php
+++ b/tests/phpunit/includes/api/query/ApiQueryWatchlistIntegrationTest.php
@@ -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
);
}
diff --git a/tests/phpunit/integration/includes/CommentFormatter/CommentParserTest.php b/tests/phpunit/integration/includes/CommentFormatter/CommentParserTest.php
index b9820ce6d327..227e08e963c2 100644
--- a/tests/phpunit/integration/includes/CommentFormatter/CommentParserTest.php
+++ b/tests/phpunit/integration/includes/CommentFormatter/CommentParserTest.php
@@ -11,6 +11,7 @@ use SiteConfiguration;
use Title;
/**
+ * @group Database
* @covers \MediaWiki\CommentFormatter\CommentParser
*/
class CommentParserTest extends \MediaWikiIntegrationTestCase {