Page MenuHomePhorge

No OneTemporary

Size
26 KB
Referenced Files
None
Subscribers
None
diff --git a/tests/phpunit/includes/Output/OutputPageTest.php b/tests/phpunit/includes/Output/OutputPageTest.php
index a40efb41c84..fe5e1dbaddc 100644
--- a/tests/phpunit/includes/Output/OutputPageTest.php
+++ b/tests/phpunit/includes/Output/OutputPageTest.php
@@ -3205,28 +3205,28 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
];
}
- public function provideGetJsVarsEditable() {
+ public static function provideGetJsVarsEditable() {
yield 'can edit and create' => [
- 'performer' => $this->mockAnonAuthorityWithPermissions( [ 'edit', 'create' ] ),
+ 'performerSpec' => 'with',
'expectedEditableConfig' => [
'wgIsProbablyEditable' => true,
'wgRelevantPageIsProbablyEditable' => true,
]
];
yield 'cannot edit or create' => [
- 'performer' => $this->mockAnonAuthorityWithoutPermissions( [ 'edit', 'create' ] ),
+ 'performerSpec' => 'without',
'expectedEditableConfig' => [
'wgIsProbablyEditable' => false,
'wgRelevantPageIsProbablyEditable' => false,
]
];
yield 'only can edit relevant title' => [
- 'performer' => $this->mockAnonAuthority( static function (
+ 'performerSpec' => static function (
string $permission,
PageIdentity $page
) {
return ( $permission === 'edit' || $permission === 'create' ) && $page->getDBkey() === 'RelevantTitle';
- } ),
+ },
'expectedEditableConfig' => [
'wgIsProbablyEditable' => false,
'wgRelevantPageIsProbablyEditable' => true,
@@ -3237,7 +3237,14 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
/**
* @dataProvider provideGetJsVarsEditable
*/
- public function testGetJsVarsEditable( Authority $performer, array $expectedEditableConfig ) {
+ public function testGetJsVarsEditable( $performerSpec, array $expectedEditableConfig ) {
+ if ( is_string( $performerSpec ) ) {
+ $performer = $performerSpec === 'with'
+ ? $this->mockAnonAuthorityWithPermissions( [ 'edit', 'create' ] )
+ : $this->mockAnonAuthorityWithoutPermissions( [ 'edit', 'create' ] );
+ } else {
+ $performer = $this->mockAnonAuthority( $performerSpec );
+ }
$op = $this->newInstance( [], null, null, $performer );
$op->getContext()->getSkin()->setRelevantTitle( Title::makeTitle( NS_MAIN, 'RelevantTitle' ) );
$this->assertArraySubmapSame( $expectedEditableConfig, $op->getJSVars() );
@@ -3318,52 +3325,34 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
return $user;
}
- public function provideUserCanPreview() {
+ public static function provideUserCanPreview() {
yield 'all good' => [
- 'performer' => $this->mockUserAuthorityWithPermissions(
- $this->mockUser( true, true ),
- [ 'edit' ]
- ),
+ 'performerSpec' => [ 'with', true, true ],
'request' => new FauxRequest( [ 'action' => 'submit' ], true ),
true
];
yield 'get request' => [
- 'performer' => $this->mockUserAuthorityWithPermissions(
- $this->mockUser( true, true ),
- [ 'edit' ]
- ),
+ 'performerSpec' => [ 'with', true, true ],
'request' => new FauxRequest( [ 'action' => 'submit' ], false ),
false
];
yield 'not a submit action' => [
- 'performer' => $this->mockUserAuthorityWithPermissions(
- $this->mockUser( true, true ),
- [ 'edit' ]
- ),
+ 'performerSpec' => [ 'with', true, true ],
'request' => new FauxRequest( [ 'action' => 'something' ], true ),
false
];
yield 'anon can not' => [
- 'performer' => $this->mockUserAuthorityWithPermissions(
- $this->mockUser( false, true ),
- [ 'edit' ]
- ),
+ 'performerSpec' => [ 'with', false, true ],
'request' => new FauxRequest( [ 'action' => 'submit' ], true ),
false
];
yield 'token not match' => [
- 'performer' => $this->mockUserAuthorityWithPermissions(
- $this->mockUser( true, false ),
- [ 'edit' ]
- ),
+ 'performerSpec' => [ 'with', true, false ],
'request' => new FauxRequest( [ 'action' => 'submit' ], true ),
false
];
yield 'no permission' => [
- 'performer' => $this->mockUserAuthorityWithoutPermissions(
- $this->mockUser( true, true ),
- [ 'edit' ]
- ),
+ 'performerSpec' => [ 'without', true, true ],
'request' => new FauxRequest( [ 'action' => 'submit' ], true ),
false
];
@@ -3372,7 +3361,11 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
/**
* @dataProvider provideUserCanPreview
*/
- public function testUserCanPreview( Authority $performer, WebRequest $request, bool $expected ) {
+ public function testUserCanPreview( $performerSpec, WebRequest $request, bool $expected ) {
+ $mockedUser = $this->mockUser( $performerSpec[1], $performerSpec[2] );
+ $performer = $performerSpec[0] === 'with'
+ ? $this->mockUserAuthorityWithPermissions( $mockedUser, [ 'edit' ] )
+ : $this->mockUserAuthorityWithoutPermissions( $mockedUser, [ 'edit' ] );
$op = $this->newInstance( [], $request, null, $performer );
$this->assertSame( $expected, $op->userCanPreview() );
}
diff --git a/tests/phpunit/includes/api/ApiMainTest.php b/tests/phpunit/includes/api/ApiMainTest.php
index 8dc8f31f002..c797a8618fa 100644
--- a/tests/phpunit/includes/api/ApiMainTest.php
+++ b/tests/phpunit/includes/api/ApiMainTest.php
@@ -21,7 +21,6 @@ use MediaWiki\Exception\ShellDisabledError;
use MediaWiki\Json\FormatJson;
use MediaWiki\Language\RawMessage;
use MediaWiki\MainConfigNames;
-use MediaWiki\Permissions\Authority;
use MediaWiki\Request\FauxRequest;
use MediaWiki\Request\FauxResponse;
use MediaWiki\Request\WebRequest;
@@ -411,15 +410,15 @@ class ApiMainTest extends ApiTestCase {
$this->doTestCheckMaxLag( 4 );
}
- public function provideAssert() {
+ public static function provideAssert() {
return [
- [ $this->mockAnonNullAuthority(), 'user', 'assertuserfailed' ],
- [ $this->mockRegisteredNullAuthority(), 'user', false ],
- [ $this->mockAnonNullAuthority(), 'anon', false ],
- [ $this->mockRegisteredNullAuthority(), 'anon', 'assertanonfailed' ],
- [ $this->mockRegisteredNullAuthority(), 'bot', 'assertbotfailed' ],
- [ $this->mockRegisteredAuthorityWithPermissions( [ 'bot' ] ), 'user', false ],
- [ $this->mockRegisteredAuthorityWithPermissions( [ 'bot' ] ), 'bot', false ],
+ [ 'anon', 'user', 'assertuserfailed' ],
+ [ 'registered', 'user', false ],
+ [ 'anon', 'anon', false ],
+ [ 'registered', 'anon', 'assertanonfailed' ],
+ [ 'registered', 'bot', 'assertbotfailed' ],
+ [ [ 'bot' ], 'user', false ],
+ [ [ 'bot' ], 'bot', false ],
];
}
@@ -428,7 +427,14 @@ class ApiMainTest extends ApiTestCase {
*
* @dataProvider provideAssert
*/
- public function testAssert( Authority $performer, $assert, $error ) {
+ public function testAssert( $performerSpec, $assert, $error ) {
+ if ( is_array( $performerSpec ) ) {
+ $performer = $this->mockRegisteredAuthorityWithPermissions( $performerSpec );
+ } else {
+ $performer = $performerSpec === 'registered'
+ ? $this->mockRegisteredNullAuthority()
+ : $this->mockAnonNullAuthority();
+ }
try {
$this->doApiRequest( [
'action' => 'query',
diff --git a/tests/phpunit/includes/filerepo/file/LocalFileTest.php b/tests/phpunit/includes/filerepo/file/LocalFileTest.php
index c3935f68d8b..563dcf47d7c 100644
--- a/tests/phpunit/includes/filerepo/file/LocalFileTest.php
+++ b/tests/phpunit/includes/filerepo/file/LocalFileTest.php
@@ -13,7 +13,6 @@ use MediaWiki\FileRepo\LocalRepo;
use MediaWiki\MainConfigNames;
use MediaWiki\MediaWikiServices;
use MediaWiki\Page\Event\PageRevisionUpdatedEvent;
-use MediaWiki\Permissions\Authority;
use MediaWiki\Tests\ExpectCallbackTrait;
use MediaWiki\Tests\recentchanges\ChangeTrackingUpdateSpyTrait;
use MediaWiki\Tests\Search\SearchUpdateSpyTrait;
@@ -303,41 +302,39 @@ class LocalFileTest extends MediaWikiIntegrationTestCase {
$this->assertNull( $file->getUploader() );
}
- public function providePermissionChecks() {
- $capablePerformer = $this->mockRegisteredAuthorityWithPermissions( [ 'deletedhistory', 'deletedtext' ] );
- $incapablePerformer = $this->mockRegisteredAuthorityWithoutPermissions( [ 'deletedhistory', 'deletedtext' ] );
+ public static function providePermissionChecks() {
yield 'Deleted, RAW' => [
- 'performer' => $incapablePerformer,
+ 'performerMock' => 'without',
'audience' => File::RAW,
'deleted' => File::DELETED_USER | File::DELETED_COMMENT,
'expected' => true,
];
yield 'No permission, not deleted' => [
- 'performer' => $incapablePerformer,
+ 'performerMock' => 'without',
'audience' => File::FOR_THIS_USER,
'deleted' => 0,
'expected' => true,
];
yield 'No permission, deleted' => [
- 'performer' => $incapablePerformer,
+ 'performerMock' => 'without',
'audience' => File::FOR_THIS_USER,
'deleted' => File::DELETED_USER | File::DELETED_COMMENT,
'expected' => false,
];
yield 'Not deleted, public' => [
- 'performer' => $capablePerformer,
+ 'performerMock' => 'with',
'audience' => File::FOR_PUBLIC,
'deleted' => 0,
'expected' => true,
];
yield 'Deleted, public' => [
- 'performer' => $capablePerformer,
+ 'performerMock' => 'with',
'audience' => File::FOR_PUBLIC,
'deleted' => File::DELETED_USER | File::DELETED_COMMENT,
'expected' => false,
];
yield 'With permission, deleted' => [
- 'performer' => $capablePerformer,
+ 'performerMock' => 'with',
'audience' => File::FOR_THIS_USER,
'deleted' => File::DELETED_USER | File::DELETED_COMMENT,
'expected' => true,
@@ -420,11 +417,14 @@ class LocalFileTest extends MediaWikiIntegrationTestCase {
* @covers \MediaWiki\FileRepo\File\LocalFile::getUploader
*/
public function testGetUploader(
- Authority $performer,
+ string $performerMock,
int $audience,
int $deleted,
bool $expected
) {
+ $performer = $performerMock === 'with'
+ ? $this->mockRegisteredAuthorityWithPermissions( [ 'deletedhistory', 'deletedtext' ] )
+ : $this->mockRegisteredAuthorityWithoutPermissions( [ 'deletedhistory', 'deletedtext' ] );
$file = $this->getOldLocalFileWithDeletion( $performer->getUser(), $deleted );
if ( $expected ) {
$this->assertTrue( $performer->getUser()->equals( $file->getUploader( $audience, $performer ) ) );
@@ -438,11 +438,14 @@ class LocalFileTest extends MediaWikiIntegrationTestCase {
* @covers \MediaWiki\FileRepo\File\ArchivedFile::getDescription
*/
public function testGetDescription(
- Authority $performer,
+ string $performerMock,
int $audience,
int $deleted,
bool $expected
) {
+ $performer = $performerMock === 'with'
+ ? $this->mockRegisteredAuthorityWithPermissions( [ 'deletedhistory', 'deletedtext' ] )
+ : $this->mockRegisteredAuthorityWithoutPermissions( [ 'deletedhistory', 'deletedtext' ] );
$file = $this->getArchivedFileWithDeletion( $performer->getUser(), $deleted );
if ( $expected ) {
$this->assertSame( 'comment', $file->getDescription( $audience, $performer ) );
@@ -456,11 +459,14 @@ class LocalFileTest extends MediaWikiIntegrationTestCase {
* @covers \MediaWiki\FileRepo\File\ArchivedFile::getUploader
*/
public function testArchivedGetUploader(
- Authority $performer,
+ string $performerMock,
int $audience,
int $deleted,
bool $expected
) {
+ $performer = $performerMock === 'with'
+ ? $this->mockRegisteredAuthorityWithPermissions( [ 'deletedhistory', 'deletedtext' ] )
+ : $this->mockRegisteredAuthorityWithoutPermissions( [ 'deletedhistory', 'deletedtext' ] );
$file = $this->getArchivedFileWithDeletion( $performer->getUser(), $deleted );
if ( $expected ) {
$this->assertTrue( $performer->getUser()->equals( $file->getUploader( $audience, $performer ) ) );
@@ -474,11 +480,14 @@ class LocalFileTest extends MediaWikiIntegrationTestCase {
* @covers \MediaWiki\FileRepo\File\LocalFile::getDescription
*/
public function testArchivedGetDescription(
- Authority $performer,
+ string $performerMock,
int $audience,
int $deleted,
bool $expected
) {
+ $performer = $performerMock === 'with'
+ ? $this->mockRegisteredAuthorityWithPermissions( [ 'deletedhistory', 'deletedtext' ] )
+ : $this->mockRegisteredAuthorityWithoutPermissions( [ 'deletedhistory', 'deletedtext' ] );
$file = $this->getOldLocalFileWithDeletion( $performer->getUser(), $deleted );
if ( $expected ) {
$this->assertSame( 'comment', $file->getDescription( $audience, $performer ) );
diff --git a/tests/phpunit/includes/skins/SkinTest.php b/tests/phpunit/includes/skins/SkinTest.php
index b449f526ec2..871005860c7 100644
--- a/tests/phpunit/includes/skins/SkinTest.php
+++ b/tests/phpunit/includes/skins/SkinTest.php
@@ -8,7 +8,6 @@ use MediaWiki\Linker\LinkTarget;
use MediaWiki\MainConfigNames;
use MediaWiki\Output\OutputPage;
use MediaWiki\Page\PageReferenceValue;
-use MediaWiki\Permissions\Authority;
use MediaWiki\Request\FauxRequest;
use MediaWiki\Skin\Skin;
use MediaWiki\Skin\SkinFallback;
@@ -111,13 +110,13 @@ class SkinTest extends MediaWikiIntegrationTestCase {
}
}
- public function provideGetDefaultModulesForRights() {
+ public static function provideGetDefaultModulesForRights() {
yield 'no rights' => [
- $this->mockRegisteredNullAuthority(), // $authority
+ 'null', // $authoritySpec
false, // $hasModule
];
yield 'has all rights' => [
- $this->mockRegisteredUltimateAuthority(), // $authority
+ 'ultimate', // $authoritySpec
true, // $hasModule
];
}
@@ -125,7 +124,10 @@ class SkinTest extends MediaWikiIntegrationTestCase {
/**
* @dataProvider provideGetDefaultModulesForRights
*/
- public function testGetDefaultModulesForRights( Authority $authority, bool $hasModule ) {
+ public function testGetDefaultModulesForRights( string $authoritySpec, bool $hasModule ) {
+ $authority = $authoritySpec === 'ultimate'
+ ? $this->mockRegisteredUltimateAuthority()
+ : $this->mockRegisteredNullAuthority();
$skin = new class extends Skin {
public function outputPage() {
}
@@ -144,40 +146,40 @@ class SkinTest extends MediaWikiIntegrationTestCase {
}
}
- public function provideGetPageClasses() {
+ public static function provideGetPageClasses() {
yield 'normal page has namespace' => [
new TitleValue( NS_MAIN, 'Test' ), // $title
- $this->mockRegisteredUltimateAuthority(), // $authority
+ 'ultimate', // $authoritySpec
[ 'ns-0' ], // $expectedClasses
];
yield 'valid special page' => [
new TitleValue( NS_SPECIAL, 'Userlogin' ), // $title
- $this->mockRegisteredUltimateAuthority(), // $authority
+ 'ultimate', // $authoritySpec
[ 'mw-special-Userlogin' ], // $expectedClasses
];
yield 'invalid special page' => [
new TitleValue( NS_SPECIAL, 'BLABLABLABLA_I_AM_INVALID' ), // $title
- $this->mockRegisteredUltimateAuthority(), // $authority
+ 'ultimate', // $authoritySpec
[ 'mw-invalidspecialpage' ], // $expectedClasses
];
yield 'talk page' => [
new TitleValue( NS_TALK, 'Test' ), // $title
- $this->mockRegisteredUltimateAuthority(), // $authority
+ 'ultimate', // $authoritySpec
[ 'ns-talk' ], // $expectedClasses
];
yield 'subject' => [
new TitleValue( NS_MAIN, 'Test' ), // $title
- $this->mockRegisteredUltimateAuthority(), // $authority
+ 'ultimate', // $authoritySpec
[ 'ns-subject' ], // $expectedClasses
];
yield 'editable' => [
new TitleValue( NS_MAIN, 'Test' ), // $title
- $this->mockRegisteredAuthorityWithPermissions( [ 'edit' ] ), // $authority
+ [ 'edit' ], // $authoritySpec
[ 'mw-editable' ], // $expectedClasses
];
yield 'not editable' => [
new TitleValue( NS_MAIN, 'Test' ), // $title
- $this->mockRegisteredNullAuthority(), // $authority
+ 'null', // $authoritySpec
[], // $expectedClasses
[ 'mw-editable' ], // $unexpectedClasses
];
@@ -188,10 +190,17 @@ class SkinTest extends MediaWikiIntegrationTestCase {
*/
public function testGetPageClasses(
LinkTarget $title,
- Authority $authority,
+ $authoritySpec,
array $expectedClasses,
array $unexpectedClasses = []
) {
+ if ( is_array( $authoritySpec ) ) {
+ $authority = $this->mockRegisteredAuthorityWithPermissions( $authoritySpec );
+ } else {
+ $authority = $authoritySpec === 'ultimate'
+ ? $this->mockRegisteredUltimateAuthority()
+ : $this->mockRegisteredNullAuthority();
+ }
$skin = new class extends Skin {
public function outputPage() {
}
diff --git a/tests/phpunit/integration/includes/page/RollbackPageTest.php b/tests/phpunit/integration/includes/page/RollbackPageTest.php
index 18452adb128..c0f33b0a421 100644
--- a/tests/phpunit/integration/includes/page/RollbackPageTest.php
+++ b/tests/phpunit/integration/includes/page/RollbackPageTest.php
@@ -61,17 +61,17 @@ class RollbackPageTest extends MediaWikiIntegrationTestCase {
);
}
- public function provideAuthorize() {
+ public static function provideAuthorize() {
yield 'Allowed' => [
- 'authority' => $this->mockRegisteredUltimateAuthority(),
+ 'authoritySpec' => 'ultimate',
'expect' => true,
];
yield 'No edit' => [
- 'authority' => $this->mockRegisteredAuthorityWithoutPermissions( [ 'edit' ] ),
+ 'authoritySpec' => [ 'edit' ],
'expect' => false,
];
yield 'No rollback' => [
- 'authority' => $this->mockRegisteredAuthorityWithoutPermissions( [ 'rollback' ] ),
+ 'authoritySpec' => [ 'rollback' ],
'expect' => false,
];
}
@@ -80,7 +80,10 @@ class RollbackPageTest extends MediaWikiIntegrationTestCase {
* @covers ::authorizeRollback
* @dataProvider provideAuthorize
*/
- public function testAuthorize( Authority $authority, bool $expect ) {
+ public function testAuthorize( $authoritySpec, bool $expect ) {
+ $authority = $authoritySpec === 'ultimate'
+ ? $this->mockRegisteredUltimateAuthority()
+ : $this->mockRegisteredAuthorityWithoutPermissions( $authoritySpec );
$this->assertSame(
$expect,
$this->getServiceContainer()
diff --git a/tests/phpunit/unit/includes/editpage/Constraint/AuthorizationConstraintTest.php b/tests/phpunit/unit/includes/editpage/Constraint/AuthorizationConstraintTest.php
index 68d8c654185..b67e6be42a9 100644
--- a/tests/phpunit/unit/includes/editpage/Constraint/AuthorizationConstraintTest.php
+++ b/tests/phpunit/unit/includes/editpage/Constraint/AuthorizationConstraintTest.php
@@ -22,7 +22,6 @@ use MediaWiki\EditPage\Constraint\AuthorizationConstraint;
use MediaWiki\EditPage\Constraint\IEditConstraint;
use MediaWiki\Page\PageIdentity;
use MediaWiki\Page\PageIdentityValue;
-use MediaWiki\Permissions\Authority;
use MediaWiki\Tests\Unit\MockBlockTrait;
use MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait;
use MediaWiki\User\UserIdentityValue;
@@ -39,7 +38,8 @@ class AuthorizationConstraintTest extends MediaWikiUnitTestCase {
/**
* @dataProvider provideTestPass
*/
- public function testPass( Authority $performer, PageIdentity $page, bool $new ): void {
+ public function testPass( array $permissions, PageIdentity $page, bool $new ): void {
+ $performer = $this->mockAnonAuthorityWithPermissions( $permissions );
$constraint = new AuthorizationConstraint(
$performer,
$page,
@@ -48,14 +48,14 @@ class AuthorizationConstraintTest extends MediaWikiUnitTestCase {
$this->assertConstraintPassed( $constraint );
}
- public function provideTestPass(): iterable {
+ public static function provideTestPass(): iterable {
yield 'Edit existing page' => [
- 'performer' => $this->mockAnonAuthorityWithPermissions( [ 'edit' ] ),
+ 'permissions' => [ 'edit' ],
'page' => PageIdentityValue::localIdentity( 123, NS_MAIN, 'AuthorizationConstraintTest' ),
'new' => false,
];
yield 'Create a new page' => [
- 'performer' => $this->mockAnonAuthorityWithPermissions( [ 'edit', 'create' ] ),
+ 'permissions' => [ 'edit', 'create' ],
'page' => PageIdentityValue::localIdentity( 0, NS_MAIN, 'AuthorizationConstraintTest' ),
'new' => true,
];
@@ -65,8 +65,21 @@ class AuthorizationConstraintTest extends MediaWikiUnitTestCase {
* @dataProvider provideTestFailure
*/
public function testFailure(
- Authority $performer, PageIdentity $page, bool $new, int $expectedValue
+ $performerSpec, PageIdentity $page, bool $new, int $expectedValue
): void {
+ if ( is_array( $performerSpec ) ) {
+ $performer = $this->mockAnonAuthorityWithoutPermissions( $performerSpec );
+ } else {
+ $performer = $performerSpec === 'registered'
+ ? $this->mockRegisteredAuthorityWithoutPermissions( [ 'edit' ] )
+ : $this->mockUserAuthorityWithBlock(
+ UserIdentityValue::newRegistered( 42, 'AuthorizationConstraintTest User' ),
+ $this->makeMockBlock( [
+ 'decodedExpiry' => 'infinity',
+ ] ),
+ [ 'edit' ]
+ );
+ }
$constraint = new AuthorizationConstraint(
$performer,
$page,
@@ -75,33 +88,27 @@ class AuthorizationConstraintTest extends MediaWikiUnitTestCase {
$this->assertConstraintFailed( $constraint, $expectedValue );
}
- public function provideTestFailure(): iterable {
+ public static function provideTestFailure(): iterable {
yield 'Anonymous user' => [
- 'performer' => $this->mockAnonAuthorityWithoutPermissions( [ 'edit' ] ),
+ 'performerSpec' => [ 'edit' ],
'page' => PageIdentityValue::localIdentity( 123, NS_MAIN, 'AuthorizationConstraintTest' ),
'new' => false,
'expectedValue' => IEditConstraint::AS_READ_ONLY_PAGE_ANON,
];
yield 'Registered user' => [
- 'performer' => $this->mockRegisteredAuthorityWithoutPermissions( [ 'edit' ] ),
+ 'performerSpec' => 'registered',
'page' => PageIdentityValue::localIdentity( 123, NS_MAIN, 'AuthorizationConstraintTest' ),
'new' => false,
'expectedValue' => IEditConstraint::AS_READ_ONLY_PAGE_LOGGED,
];
yield 'User without create permission creates a page' => [
- 'performer' => $this->mockAnonAuthorityWithoutPermissions( [ 'create' ] ),
+ 'performerSpec' => [ 'create' ],
'page' => PageIdentityValue::localIdentity( 0, NS_MAIN, 'AuthorizationConstraintTest' ),
'new' => true,
'expectedValue' => IEditConstraint::AS_NO_CREATE_PERMISSION,
];
yield 'Blocked user' => [
- 'performer' => $this->mockUserAuthorityWithBlock(
- UserIdentityValue::newRegistered( 42, 'AuthorizationConstraintTest User' ),
- $this->makeMockBlock( [
- 'decodedExpiry' => 'infinity',
- ] ),
- [ 'edit' ]
- ),
+ 'performerSpec' => 'blocked',
'page' => PageIdentityValue::localIdentity( 123, NS_MAIN, 'AuthorizationConstraintTest' ),
'new' => false,
'expectedValue' => IEditConstraint::AS_BLOCKED_PAGE_FOR_USER,
diff --git a/tests/phpunit/unit/includes/editpage/Constraint/ImageRedirectConstraintTest.php b/tests/phpunit/unit/includes/editpage/Constraint/ImageRedirectConstraintTest.php
index da9c779beb6..ccae3df3688 100644
--- a/tests/phpunit/unit/includes/editpage/Constraint/ImageRedirectConstraintTest.php
+++ b/tests/phpunit/unit/includes/editpage/Constraint/ImageRedirectConstraintTest.php
@@ -61,21 +61,22 @@ class ImageRedirectConstraintTest extends MediaWikiUnitTestCase {
/**
* @dataProvider provideTestFailure
- * @param Authority $performer
- * @param int $expectedValue
*/
- public function testFailure( Authority $performer, int $expectedValue ) {
+ public function testFailure( string $performerSpec, int $expectedValue ) {
+ $performer = $performerSpec === 'anon'
+ ? $this->mockAnonAuthorityWithoutPermissions( [ 'upload' ] )
+ : $this->mockRegisteredAuthorityWithoutPermissions( [ 'upload' ] );
$constraint = $this->getConstraint( $performer );
$this->assertConstraintFailed( $constraint, $expectedValue );
}
- public function provideTestFailure() {
+ public static function provideTestFailure() {
yield 'Anonymous user' => [
- 'performer' => $this->mockAnonAuthorityWithoutPermissions( [ 'upload' ] ),
+ 'performerSpec' => 'anon',
'expectedValue' => IEditConstraint::AS_IMAGE_REDIRECT_ANON
];
yield 'Registered user' => [
- 'performer' => $this->mockRegisteredAuthorityWithoutPermissions( [ 'upload' ] ),
+ 'performerSpec' => 'registered',
'expectedValue' => IEditConstraint::AS_IMAGE_REDIRECT_LOGGED
];
}
diff --git a/tests/phpunit/unit/includes/page/MovePageTest.php b/tests/phpunit/unit/includes/page/MovePageTest.php
index eb4cc914054..03436d947e1 100644
--- a/tests/phpunit/unit/includes/page/MovePageTest.php
+++ b/tests/phpunit/unit/includes/page/MovePageTest.php
@@ -5,11 +5,11 @@ namespace MediaWiki\Tests\Unit;
use MediaWiki\EditPage\SpamChecker;
use MediaWiki\Page\MovePage;
use MediaWiki\Page\PageIdentity;
-use MediaWiki\Permissions\Authority;
use MediaWiki\Permissions\PermissionStatus;
use MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait;
use MediaWikiUnitTestCase;
use MockTitleTrait;
+use PHPUnit\Framework\Assert;
/**
* @coversDefaultClass \MediaWiki\Page\MovePage
@@ -20,28 +20,28 @@ class MovePageTest extends MediaWikiUnitTestCase {
use MockAuthorityTrait;
use MockServiceDependenciesTrait;
- public function provideCheckPermissions() {
+ public static function provideCheckPermissions() {
yield 'all good and allowed' => [
- 'authority' => $this->mockRegisteredUltimateAuthority(),
+ 'authority' => 'ultimate',
'good' => true,
];
yield 'cannot move' => [
- 'authority' => $this->mockAnonAuthority( function (
+ 'authority' => static function (
string $permission,
PageIdentity $page,
PermissionStatus $status
) {
if ( $permission === 'move' ) {
- $this->assertSame( 'Existent', $page->getDBkey() );
+ Assert::assertSame( 'Existent', $page->getDBkey() );
$status->fatal( 'test' );
return false;
}
return true;
- } ),
+ },
'good' => false,
];
yield 'cannot edit old page' => [
- 'authority' => $this->mockAnonAuthority( static function (
+ 'authority' => static function (
string $permission,
PageIdentity $page,
PermissionStatus $status
@@ -51,26 +51,26 @@ class MovePageTest extends MediaWikiUnitTestCase {
return false;
}
return true;
- } ),
+ },
'good' => false,
];
yield 'cannot move-target' => [
- 'authority' => $this->mockAnonAuthority( function (
+ 'authority' => static function (
string $permission,
PageIdentity $page,
PermissionStatus $status
) {
if ( $permission === 'move-target' ) {
- $this->assertSame( 'Existent2', $page->getDBkey() );
+ Assert::assertSame( 'Existent2', $page->getDBkey() );
$status->fatal( 'test' );
return false;
}
return true;
- } ),
+ },
'good' => false,
];
yield 'cannot edit new page' => [
- 'authority' => $this->mockAnonAuthority( static function (
+ 'authority' => static function (
string $permission,
PageIdentity $page,
PermissionStatus $status
@@ -80,7 +80,7 @@ class MovePageTest extends MediaWikiUnitTestCase {
return false;
}
return true;
- } ),
+ },
'good' => false,
];
}
@@ -91,7 +91,10 @@ class MovePageTest extends MediaWikiUnitTestCase {
* @covers \MediaWiki\Page\MovePage::authorizeMove
* @covers \MediaWiki\Page\MovePage::probablyCanMove
*/
- public function testCheckPermissions( Authority $authority, bool $good ) {
+ public function testCheckPermissions( $authoritySpec, bool $good ) {
+ $authority = $authoritySpec === 'ultimate'
+ ? $this->mockRegisteredUltimateAuthority()
+ : $this->mockAnonAuthority( $authoritySpec );
$spamChecker = $this->createNoOpMock( SpamChecker::class, [ 'checkSummary' ] );
$spamChecker->method( 'checkSummary' )->willReturn( false );
$mp = $this->newServiceInstance(

File Metadata

Mime Type
text/x-diff
Expires
Sat, Jul 5, 5:31 AM (15 h, 8 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
227494
Default Alt Text
(26 KB)

Event Timeline