Report more information about composite blocks in block error messages
[lhc/web/wiklou.git] / tests / phpunit / includes / block / CompositeBlockTest.php
index 5cd86b8..fe8cee7 100644 (file)
@@ -243,6 +243,66 @@ class CompositeBlockTest extends MediaWikiLangTestCase {
                ];
        }
 
+       /**
+        * @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
         *