use MediaWiki\Block\BlockRestrictionStore;
use MediaWiki\Block\CompositeBlock;
+use MediaWiki\Block\DatabaseBlock;
use MediaWiki\Block\Restriction\PageRestriction;
use MediaWiki\Block\Restriction\NamespaceRestriction;
use MediaWiki\Block\SystemBlock;
private function getPartialBlocks() {
$sysopId = $this->getTestSysop()->getUser()->getId();
- $userBlock = new Block( [
+ $userBlock = new DatabaseBlock( [
'address' => $this->getTestUser()->getUser(),
'by' => $sysopId,
'sitewide' => false,
] );
- $ipBlock = new Block( [
+ $ipBlock = new DatabaseBlock( [
'address' => '127.0.0.1',
'by' => $sysopId,
'sitewide' => false,
return [
'Sitewide block and partial block' => [
[
- new Block( [
+ new DatabaseBlock( [
'sitewide' => false,
'blockEmail' => true,
'allowUsertalk' => true,
] ),
- new Block( [
+ new DatabaseBlock( [
'sitewide' => true,
'blockEmail' => false,
'allowUsertalk' => false,
],
'Partial block and system block' => [
[
- new Block( [
+ new DatabaseBlock( [
'sitewide' => false,
'blockEmail' => true,
'allowUsertalk' => false,
],
'System block and user name hiding block' => [
[
- new Block( [
+ new DatabaseBlock( [
'hideName' => true,
'sitewide' => true,
'blockEmail' => true,
],
'Two lenient partial blocks' => [
[
- new Block( [
+ new DatabaseBlock( [
'sitewide' => false,
'blockEmail' => false,
'allowUsertalk' => true,
] ),
- new Block( [
+ new DatabaseBlock( [
'sitewide' => false,
'blockEmail' => false,
'allowUsertalk' => true,
return [
'Read is not blocked' => [
[
- new Block(),
- new Block(),
+ new DatabaseBlock(),
+ new DatabaseBlock(),
],
'read',
false,
],
'Email is blocked if blocked by any blocks' => [
[
- new Block( [
+ new DatabaseBlock( [
'blockEmail' => true,
] ),
- new Block( [
+ new DatabaseBlock( [
'blockEmail' => false,
] ),
],
];
}
+ /**
+ * @covers ::getPermissionsError
+ * @dataProvider provideGetPermissionsError
+ */
+ public function testGetPermissionsError( $ids, $expectedIdsMsg ) {
+ // Some block options
+ $timestamp = time();
+ $target = '1.2.3.4';
+ $byText = 'MediaWiki default';
+ $formattedByText = "\u{202A}{$byText}\u{202C}";
+ $reason = '';
+ $expiry = 'infinite';
+
+ $block = $this->getMockBuilder( CompositeBlock::class )
+ ->setMethods( [ 'getIds', 'getBlockErrorParams' ] )
+ ->getMock();
+ $block->method( 'getIds' )
+ ->willReturn( $ids );
+ $block->method( 'getBlockErrorParams' )
+ ->willReturn( [
+ $formattedByText,
+ $reason,
+ $target,
+ $formattedByText,
+ null,
+ $timestamp,
+ $target,
+ $expiry,
+ ] );
+
+ $this->assertSame( [
+ 'blockedtext-composite',
+ $formattedByText,
+ $reason,
+ $target,
+ $formattedByText,
+ $expectedIdsMsg,
+ $timestamp,
+ $target,
+ $expiry,
+ ], $block->getPermissionsError( RequestContext::getMain() ) );
+ }
+
+ public static function provideGetPermissionsError() {
+ return [
+ 'All original blocks are system blocks' => [
+ [],
+ 'Your IP address appears in multiple blacklists',
+ ],
+ 'One original block is a database block' => [
+ [ 100 ],
+ 'Relevant block IDs: #100 (your IP address may also be blacklisted)',
+ ],
+ 'Several original blocks are database blocks' => [
+ [ 100, 101, 102 ],
+ 'Relevant block IDs: #100, #101, #102 (your IP address may also be blacklisted)',
+ ],
+ ];
+ }
+
/**
* Get an instance of BlockRestrictionStore
*