wiki.techinc.nl/tests/phpunit/includes/exception/UserBlockedErrorTest.php
Umherirrender 388b0374fa tests: Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statements and changes to docs done manually

Change-Id: Ib326ae1e5c8409a98398c721e8b8ce42c73bd012
2023-12-11 15:59:55 +01:00

58 lines
1.9 KiB
PHP

<?php
use MediaWiki\Block\AbstractBlock;
use MediaWiki\Block\BlockErrorFormatter;
use MediaWiki\Language\RawMessage;
use MediaWiki\User\UserIdentity;
/**
* @covers UserBlockedError
*/
class UserBlockedErrorTest extends MediaWikiIntegrationTestCase {
private function setUpMockBlockFormatter(
$expectedBlock, $expectedUser, $expectedLanguage, $expectedIp, $returnMessages
) {
$mockBlockErrorFormatter = $this->createMock( BlockErrorFormatter::class );
$mockBlockErrorFormatter->expects( $this->once() )
->method( 'getMessages' )
->with( $expectedBlock, $expectedUser, $expectedLanguage, $expectedIp )
->willReturn( $returnMessages );
$this->overrideMwServices( null, [
'BlockErrorFormatter' => static function () use ( $mockBlockErrorFormatter ) {
return $mockBlockErrorFormatter;
}
] );
}
public function testConstructionProvidedOnlyBlockParameter() {
$context = RequestContext::getMain();
$block = $this->createMock( AbstractBlock::class );
$this->setUpMockBlockFormatter(
$block, $context->getUser(), $context->getLanguage(), $context->getRequest()->getIP(),
[ new RawMessage( 'testing' ) ]
);
$e = new UserBlockedError( $block );
$this->assertSame(
( new RawMessage( 'testing' ) )->text(),
$e->getMessageObject()->text(),
'UserBlockedError did not use the expected message.'
);
}
public function testConstructionProvidedAllParametersWithMultipleBlockMessages() {
$mockUser = $this->createMock( UserIdentity::class );
$mockLanguage = $this->createMock( Language::class );
$block = $this->createMock( AbstractBlock::class );
$this->setUpMockBlockFormatter(
$block, $mockUser, $mockLanguage, '1.2.3.4',
[ new RawMessage( 'testing' ), new RawMessage( 'testing2' ) ]
);
$e = new UserBlockedError( $block, $mockUser, $mockLanguage, '1.2.3.4' );
$this->assertSame(
"* testing\n* testing2",
$e->getMessageObject()->text(),
'UserBlockedError did not use the expected message.'
);
}
}