The DatabaseBlockStoreFactory is a new service which allows fetching of a wiki-specific DatabaseBlockStore by fetching the correct LoadBalancer via a LBFactory and then injecting it into the DatabaseBlockStore. It also creates a wiki-specific ReadOnlyMode and BlockRestrictionStore, which are also being injected. This is being done as a part of the project of supporting cross-wiki blocking. The future plan is that BlockUser and UnblockUser are being updated to properly support creating, updating and deleting cross-wiki blocks. BlockUser and UnblockUser are then going to use a newly injected DatabaseBlockStoreFactory to fetch the correct DatabaseBlockStore to then insert/update/remove the block into/from the correct database. Bug: T291849 Change-Id: I1051beedfd67c4e2c546b9eec04b6d592d969af3
67 lines
2 KiB
PHP
67 lines
2 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Tests\Block;
|
|
|
|
use ConfiguredReadOnlyMode;
|
|
use MediaWiki\Block\BlockRestrictionStore;
|
|
use MediaWiki\Block\BlockRestrictionStoreFactory;
|
|
use MediaWiki\Block\DatabaseBlockStore;
|
|
use MediaWiki\Block\DatabaseBlockStoreFactory;
|
|
use MediaWiki\CommentStore\CommentStore;
|
|
use MediaWiki\Config\ServiceOptions;
|
|
use MediaWiki\DAO\WikiAwareEntity;
|
|
use MediaWiki\HookContainer\HookContainer;
|
|
use MediaWiki\User\ActorStoreFactory;
|
|
use MediaWiki\User\UserFactory;
|
|
use MediaWikiUnitTestCase;
|
|
use Psr\Log\LoggerInterface;
|
|
use Wikimedia\Rdbms\LBFactory;
|
|
use Wikimedia\Rdbms\LoadBalancer;
|
|
|
|
/**
|
|
* @covers \MediaWiki\Block\DatabaseBlockStoreFactory
|
|
*/
|
|
class DatabaseBlockStoreFactoryTest extends MediaWikiUnitTestCase {
|
|
|
|
/**
|
|
* @dataProvider provideDomains
|
|
*/
|
|
public function testGetDatabaseBlockStore( $domain ) {
|
|
$lb = $this->createMock( LoadBalancer::class );
|
|
$lbFactory = $this->createMock( LBFactory::class );
|
|
$lbFactory
|
|
->method( 'getMainLB' )
|
|
->with( $domain )
|
|
->willReturn( $lb );
|
|
|
|
$blockRestrictionStore = $this->createMock( BlockRestrictionStore::class );
|
|
$blockRestrictionStoreFactory = $this->createMock(
|
|
BlockRestrictionStoreFactory::class
|
|
);
|
|
$blockRestrictionStoreFactory
|
|
->method( 'getBlockRestrictionStore' )
|
|
->with( $domain )
|
|
->willReturn( $blockRestrictionStore );
|
|
|
|
$factory = new DatabaseBlockStoreFactory(
|
|
$this->createMock( ServiceOptions::class ),
|
|
$this->createMock( LoggerInterface::class ),
|
|
$this->createMock( ActorStoreFactory::class ),
|
|
$blockRestrictionStoreFactory,
|
|
$this->createMock( CommentStore::class ),
|
|
$this->createMock( HookContainer::class ),
|
|
$lbFactory,
|
|
$this->createMock( ConfiguredReadOnlyMode::class ),
|
|
$this->createMock( UserFactory::class )
|
|
);
|
|
|
|
$databaseBlockStore = $factory->getDatabaseBlockStore( $domain );
|
|
$this->assertInstanceOf( DatabaseBlockStore::class, $databaseBlockStore );
|
|
}
|
|
|
|
public function provideDomains() {
|
|
yield 'local wiki' => [ WikiAwareEntity::LOCAL ];
|
|
yield 'foreign wiki' => [ 'meta' ];
|
|
}
|
|
|
|
}
|