Convert ChangeTagsConstraint to Authority
Change-Id: Ib31f3d590fcd0d609cc11f06183da8283cfe7673
This commit is contained in:
parent
a8e44cceb2
commit
1e50ec98ed
2 changed files with 12 additions and 16 deletions
|
|
@ -21,8 +21,8 @@
|
|||
namespace MediaWiki\EditPage\Constraint;
|
||||
|
||||
use ChangeTags;
|
||||
use MediaWiki\Permissions\Authority;
|
||||
use StatusValue;
|
||||
use User;
|
||||
|
||||
/**
|
||||
* Verify user can add change tags
|
||||
|
|
@ -33,8 +33,8 @@ use User;
|
|||
*/
|
||||
class ChangeTagsConstraint implements IEditConstraint {
|
||||
|
||||
/** @var User */
|
||||
private $user;
|
||||
/** @var Authority */
|
||||
private $performer;
|
||||
|
||||
/** @var array */
|
||||
private $tags;
|
||||
|
|
@ -43,14 +43,14 @@ class ChangeTagsConstraint implements IEditConstraint {
|
|||
private $result;
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param Authority $performer
|
||||
* @param string[] $tags
|
||||
*/
|
||||
public function __construct(
|
||||
User $user,
|
||||
Authority $performer,
|
||||
array $tags
|
||||
) {
|
||||
$this->user = $user;
|
||||
$this->performer = $performer;
|
||||
$this->tags = $tags;
|
||||
}
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ class ChangeTagsConstraint implements IEditConstraint {
|
|||
// service as part of T245964
|
||||
$changeTagStatus = ChangeTags::canAddTagsAccompanyingChange(
|
||||
$this->tags,
|
||||
$this->user
|
||||
$this->performer
|
||||
);
|
||||
|
||||
if ( $changeTagStatus->isOK() ) {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
use MediaWiki\EditPage\Constraint\ChangeTagsConstraint;
|
||||
use MediaWiki\EditPage\Constraint\IEditConstraint;
|
||||
use MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait;
|
||||
|
||||
/**
|
||||
* Tests the ChangeTagsConstraint
|
||||
|
|
@ -31,6 +32,7 @@ use MediaWiki\EditPage\Constraint\IEditConstraint;
|
|||
*/
|
||||
class ChangeTagsConstraintTest extends MediaWikiIntegrationTestCase {
|
||||
use EditConstraintTestTrait;
|
||||
use MockAuthorityTrait;
|
||||
|
||||
protected function setUp() : void {
|
||||
parent::setUp();
|
||||
|
|
@ -38,12 +40,6 @@ class ChangeTagsConstraintTest extends MediaWikiIntegrationTestCase {
|
|||
$this->tablesUsed,
|
||||
[ 'change_tag', 'change_tag_def', 'logging' ]
|
||||
);
|
||||
$this->mergeMwGlobalArrayValue( 'wgGroupPermissions', [
|
||||
'sysop' => [ 'applychangetags' => true ]
|
||||
] );
|
||||
$this->mergeMwGlobalArrayValue( 'wgRevokePermissions', [
|
||||
'noapplytags' => [ 'applychangetags' => true ]
|
||||
] );
|
||||
}
|
||||
|
||||
public function testPass() {
|
||||
|
|
@ -51,7 +47,7 @@ class ChangeTagsConstraintTest extends MediaWikiIntegrationTestCase {
|
|||
ChangeTags::defineTag( $tagName );
|
||||
|
||||
$constraint = new ChangeTagsConstraint(
|
||||
$this->getTestSysop()->getUser(),
|
||||
$this->mockRegisteredUltimateAuthority(),
|
||||
[ $tagName ]
|
||||
);
|
||||
$this->assertConstraintPassed( $constraint );
|
||||
|
|
@ -60,7 +56,7 @@ class ChangeTagsConstraintTest extends MediaWikiIntegrationTestCase {
|
|||
public function testNoTags() {
|
||||
// Early return for no tags being added
|
||||
$constraint = new ChangeTagsConstraint(
|
||||
$this->getTestSysop()->getUser(),
|
||||
$this->mockRegisteredUltimateAuthority(),
|
||||
[]
|
||||
);
|
||||
$this->assertConstraintPassed( $constraint );
|
||||
|
|
@ -71,7 +67,7 @@ class ChangeTagsConstraintTest extends MediaWikiIntegrationTestCase {
|
|||
ChangeTags::defineTag( $tagName );
|
||||
|
||||
$constraint = new ChangeTagsConstraint(
|
||||
$this->getTestUser( [ 'noapplytags' ] )->getUser(),
|
||||
$this->mockRegisteredAuthorityWithoutPermissions( [ 'applychangetags' ] ),
|
||||
[ $tagName ]
|
||||
);
|
||||
$this->assertConstraintFailed(
|
||||
|
|
|
|||
Loading…
Reference in a new issue