3 use MediaWiki\Block\AbstractBlock
;
4 use MediaWiki\Block\BlockErrorFormatter
;
5 use MediaWiki\Context\RequestContext
;
6 use MediaWiki\Language\FormatterFactory
;
7 use MediaWiki\Language\Language
;
8 use MediaWiki\Language\RawMessage
;
9 use MediaWiki\User\UserIdentity
;
12 * @covers \UserBlockedError
14 class UserBlockedErrorTest
extends MediaWikiIntegrationTestCase
{
16 private function setUpMockBlockFormatter(
17 $expectedBlock, $expectedUser, $expectedLanguage, $expectedIp, $returnMessages
19 $mockBlockErrorFormatter = $this->createMock( BlockErrorFormatter
::class );
20 $mockBlockErrorFormatter->expects( $this->once() )
21 ->method( 'getMessages' )
22 ->with( $expectedBlock, $expectedUser, $expectedIp )
23 ->willReturn( $returnMessages );
25 $formatterFactory = $this->createNoOpMock( FormatterFactory
::class, [ 'getBlockErrorFormatter' ] );
26 $formatterFactory->method( 'getBlockErrorFormatter' )->willReturn( $mockBlockErrorFormatter );
28 $this->setService( 'FormatterFactory', $formatterFactory );
31 public function testConstructionProvidedOnlyBlockParameter() {
32 $context = RequestContext
::getMain();
33 $block = $this->createMock( AbstractBlock
::class );
34 $this->setUpMockBlockFormatter(
35 $block, $context->getUser(), $context->getLanguage(), $context->getRequest()->getIP(),
36 [ new RawMessage( 'testing' ) ]
38 $e = new UserBlockedError( $block );
40 ( new RawMessage( 'testing' ) )->text(),
41 $e->getMessageObject()->text(),
42 'UserBlockedError did not use the expected message.'
46 public function testConstructionProvidedAllParametersWithMultipleBlockMessages() {
47 $mockUser = $this->createMock( UserIdentity
::class );
48 $mockLanguage = $this->createMock( Language
::class );
49 $block = $this->createMock( AbstractBlock
::class );
50 $this->setUpMockBlockFormatter(
51 $block, $mockUser, $mockLanguage, '1.2.3.4',
52 [ new RawMessage( 'testing' ), new RawMessage( 'testing2' ) ]
54 $e = new UserBlockedError( $block, $mockUser, $mockLanguage, '1.2.3.4' );
56 "* testing\n* testing2",
57 $e->getMessageObject()->text(),
58 'UserBlockedError did not use the expected message.'