mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-23 22:03:39 +00:00
229a610ae7
* Add PHP type hints to private functions. * Remove @param and @return if redundant to type declaration. Change-Id: I40df9579af92ad1af820d3706a8cd907e9950ce2
80 lines
2.1 KiB
PHP
80 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Minerva;
|
|
|
|
use MediaWiki\Language\ILanguageConverter;
|
|
use MediaWiki\Language\Language;
|
|
use MediaWiki\Languages\LanguageConverterFactory;
|
|
use MediaWiki\Output\OutputPage;
|
|
use MediaWiki\Title\Title;
|
|
use MediaWikiIntegrationTestCase;
|
|
|
|
/**
|
|
* @package Tests\MediaWiki\Minerva
|
|
* @group MinervaNeue
|
|
* @coversDefaultClass \MediaWiki\Minerva\LanguagesHelper
|
|
*/
|
|
class LanguagesHelperTest extends MediaWikiIntegrationTestCase {
|
|
|
|
/**
|
|
* Build test Output object
|
|
*/
|
|
private function getOutput( array $langLinks ): OutputPage {
|
|
$out = $this->createMock( OutputPage::class );
|
|
$out->expects( $this->once() )
|
|
->method( 'getLanguageLinks' )
|
|
->willReturn( $langLinks );
|
|
|
|
return $out;
|
|
}
|
|
|
|
/**
|
|
* Build test LanguageConverterFactory object
|
|
*/
|
|
private function getLanguageConverterFactory( bool $hasVariants ): LanguageConverterFactory {
|
|
$langConv = $this->createMock( ILanguageConverter::class );
|
|
$langConv->method( 'hasVariants' )->willReturn( $hasVariants );
|
|
$langConvFactory = $this->createMock( LanguageConverterFactory::class );
|
|
$langConvFactory->method( 'getLanguageConverter' )->willReturn( $langConv );
|
|
|
|
return $langConvFactory;
|
|
}
|
|
|
|
/**
|
|
* Build test Title object
|
|
*/
|
|
private function getTitle(): Title {
|
|
$languageMock = $this->createMock( Language::class );
|
|
$title = $this->createMock( Title::class );
|
|
$title->method( 'getPageLanguage' )
|
|
->willReturn( $languageMock );
|
|
|
|
return $title;
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideDoesTitleHasLanguagesOrVariants
|
|
* @covers ::__construct
|
|
* @covers ::doesTitleHasLanguagesOrVariants
|
|
*/
|
|
public function testDoesTitleHasLanguagesOrVariants( bool $hasVariants, array $langLinks, bool $expected ) {
|
|
$helper = new LanguagesHelper(
|
|
$this->getLanguageConverterFactory( $hasVariants )
|
|
);
|
|
|
|
$this->assertSame( $expected, $helper->doesTitleHasLanguagesOrVariants(
|
|
$this->getOutput( $langLinks ),
|
|
$this->getTitle()
|
|
) );
|
|
}
|
|
|
|
public static function provideDoesTitleHasLanguagesOrVariants() {
|
|
return [
|
|
[ false, [ 'pl:StronaTestowa', 'en:TestPage' ], true ],
|
|
[ true, [ 'pl:StronaTestowa', 'en:TestPage' ], true ],
|
|
[ false, [], false ],
|
|
[ true, [], true ],
|
|
];
|
|
}
|
|
}
|