wiki.techinc.nl/tests/phpunit/includes/api/ApiBlockInfoTraitTest.php
Alexander Vorwerk decbaf4f38 phpunit: use ->getServiceContainer() in integration tests
Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
2022-01-27 22:04:16 +01:00

45 lines
1.2 KiB
PHP

<?php
use MediaWiki\Block\DatabaseBlock;
use MediaWiki\Block\SystemBlock;
use Wikimedia\TestingAccessWrapper;
/**
* @covers ApiBlockInfoTrait
*/
class ApiBlockInfoTraitTest extends MediaWikiIntegrationTestCase {
/**
* @dataProvider provideGetBlockDetails
*/
public function testGetBlockDetails( $block, $expectedInfo ) {
$language = $this->getServiceContainer()->getLanguageFactory()->getLanguage( 'en' );
$mock = $this->getMockForTrait( ApiBlockInfoTrait::class );
$mock->method( 'getLanguage' )->willReturn( $language );
$info = TestingAccessWrapper::newFromObject( $mock )->getBlockDetails( $block );
$subset = array_merge( [
'blockid' => null,
'blockedby' => '',
'blockedbyid' => 0,
'blockreason' => '',
'blockexpiry' => 'infinite',
], $expectedInfo );
$this->assertArraySubmapSame( $subset, $info, "Matching block details" );
}
public static function provideGetBlockDetails() {
return [
'Sitewide block' => [
new DatabaseBlock(),
[ 'blockpartial' => false ],
],
'Partial block' => [
new DatabaseBlock( [ 'sitewide' => false ] ),
[ 'blockpartial' => true ],
],
'System block' => [
new SystemBlock( [ 'systemBlock' => 'proxy' ] ),
[ 'systemblocktype' => 'proxy' ]
],
];
}
}