BlockPermissionChecker: inject BlockUtils
Instead of using AbstractBlock::parseTarget, which just calls the BlockUtils service but makes it impossible to convert the tests to unit tests Follow-up will actually convert the tests to unit tests Change-Id: I939c44811669e7a09dcffc7589e3b1176a2f68d4
This commit is contained in:
parent
a8e44cceb2
commit
2065c3df2c
4 changed files with 16 additions and 10 deletions
|
|
@ -232,6 +232,7 @@ return [
|
|||
BlockPermissionCheckerFactory::CONSTRUCTOR_OPTIONS,
|
||||
$services->getMainConfig()
|
||||
),
|
||||
$services->getBlockUtils(),
|
||||
$services->getUserFactory()
|
||||
);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -59,24 +59,22 @@ class BlockPermissionChecker {
|
|||
'EnableUserEmail',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var ServiceOptions
|
||||
*/
|
||||
/** @var ServiceOptions */
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* @var UserFactory
|
||||
*/
|
||||
/** @var UserFactory */
|
||||
private $userFactory;
|
||||
|
||||
/**
|
||||
* @param ServiceOptions $options
|
||||
* @param BlockUtils $blockUtils
|
||||
* @param UserFactory $userFactory
|
||||
* @param UserIdentity|string|null $target
|
||||
* @param Authority $performer
|
||||
*/
|
||||
public function __construct(
|
||||
ServiceOptions $options,
|
||||
BlockUtils $blockUtils,
|
||||
UserFactory $userFactory,
|
||||
$target,
|
||||
Authority $performer
|
||||
|
|
@ -84,7 +82,7 @@ class BlockPermissionChecker {
|
|||
$options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
|
||||
$this->options = $options;
|
||||
$this->userFactory = $userFactory;
|
||||
list( $this->target, $this->targetType ) = AbstractBlock::parseTarget( $target );
|
||||
list( $this->target, $this->targetType ) = $blockUtils->parseBlockTarget( $target );
|
||||
$this->performer = $performer;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,21 +42,25 @@ class BlockPermissionCheckerFactory {
|
|||
*/
|
||||
public const CONSTRUCTOR_OPTIONS = BlockPermissionChecker::CONSTRUCTOR_OPTIONS;
|
||||
|
||||
/**
|
||||
* @var UserFactory
|
||||
*/
|
||||
/** @var BlockUtils */
|
||||
private $blockUtils;
|
||||
|
||||
/** @var UserFactory */
|
||||
private $userFactory;
|
||||
|
||||
/**
|
||||
* @param ServiceOptions $options
|
||||
* @param BlockUtils $blockUtils
|
||||
* @param UserFactory $userFactory
|
||||
*/
|
||||
public function __construct(
|
||||
ServiceOptions $options,
|
||||
BlockUtils $blockUtils,
|
||||
UserFactory $userFactory
|
||||
) {
|
||||
$options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
|
||||
$this->options = $options;
|
||||
$this->blockUtils = $blockUtils;
|
||||
$this->userFactory = $userFactory;
|
||||
}
|
||||
|
||||
|
|
@ -72,6 +76,7 @@ class BlockPermissionCheckerFactory {
|
|||
) {
|
||||
return new BlockPermissionChecker(
|
||||
$this->options,
|
||||
$this->blockUtils,
|
||||
$this->userFactory,
|
||||
$target,
|
||||
$performer
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ use MediaWiki\MediaWikiServices;
|
|||
* @group Database
|
||||
* @group Blocking
|
||||
* @coversDefaultClass \MediaWiki\Block\BlockPermissionChecker
|
||||
*
|
||||
* TODO convert to Unit tests, all dependencies are injected
|
||||
*/
|
||||
class BlockPermissionCheckerTest extends MediaWikiLangTestCase {
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue