wiki.techinc.nl/tests/phpunit/includes/api/ApiBlockInfoTraitTest.php
Ed Sanders c0ecb08bdb ApiBlockInfoTrait: Add formatted and relative times
Providing just standard timestamps means that formatting
has to happen in the client, however that means loading a
large deprecated library (moment.js). We already have
localised formatting functions in PHP so just provide
the output of those in the API.

Also fix test mocks to correctly provide a language object
rather than a string.

Bug: T224635
Change-Id: I73dcfcdbbc6e90bc692bf5a456075fe1eaed2df9
2021-12-06 16:02:18 +00:00

46 lines
1.3 KiB
PHP

<?php
use MediaWiki\Block\DatabaseBlock;
use MediaWiki\Block\SystemBlock;
use MediaWiki\MediaWikiServices;
use Wikimedia\TestingAccessWrapper;
/**
* @covers ApiBlockInfoTrait
*/
class ApiBlockInfoTraitTest extends MediaWikiIntegrationTestCase {
/**
* @dataProvider provideGetBlockDetails
*/
public function testGetBlockDetails( $block, $expectedInfo ) {
$language = MediaWikiServices::getInstance()->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' ]
],
];
}
}