2019-07-09 16:10:31 +00:00
|
|
|
<?php
|
|
|
|
|
2022-05-03 18:11:54 +00:00
|
|
|
namespace MediaWiki\Minerva;
|
2019-07-09 16:10:31 +00:00
|
|
|
|
2024-10-20 07:28:03 +00:00
|
|
|
use MediaWiki\Language\ILanguageConverter;
|
|
|
|
use MediaWiki\Language\Language;
|
2021-02-27 14:36:08 +00:00
|
|
|
use MediaWiki\Languages\LanguageConverterFactory;
|
2024-01-06 15:31:38 +00:00
|
|
|
use MediaWiki\Output\OutputPage;
|
2023-08-19 04:23:00 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2022-05-03 18:11:54 +00:00
|
|
|
use MediaWikiIntegrationTestCase;
|
2019-07-09 16:10:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @package Tests\MediaWiki\Minerva
|
|
|
|
* @group MinervaNeue
|
|
|
|
* @coversDefaultClass \MediaWiki\Minerva\LanguagesHelper
|
|
|
|
*/
|
2022-05-03 18:11:54 +00:00
|
|
|
class LanguagesHelperTest extends MediaWikiIntegrationTestCase {
|
2019-07-09 16:10:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Build test Output object
|
|
|
|
*/
|
2024-10-21 18:39:39 +00:00
|
|
|
private function getOutput( array $langLinks ): OutputPage {
|
2022-05-03 18:11:54 +00:00
|
|
|
$out = $this->createMock( OutputPage::class );
|
2019-07-09 16:10:31 +00:00
|
|
|
$out->expects( $this->once() )
|
|
|
|
->method( 'getLanguageLinks' )
|
|
|
|
->willReturn( $langLinks );
|
|
|
|
|
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-03-02 19:34:53 +00:00
|
|
|
* Build test LanguageConverterFactory object
|
2019-07-09 16:10:31 +00:00
|
|
|
*/
|
2024-10-21 18:39:39 +00:00
|
|
|
private function getLanguageConverterFactory( bool $hasVariants ): LanguageConverterFactory {
|
2021-02-27 14:36:08 +00:00
|
|
|
$langConv = $this->createMock( ILanguageConverter::class );
|
2024-03-02 20:07:16 +00:00
|
|
|
$langConv->method( 'hasVariants' )->willReturn( $hasVariants );
|
2021-02-27 14:36:08 +00:00
|
|
|
$langConvFactory = $this->createMock( LanguageConverterFactory::class );
|
2024-03-03 07:55:20 +00:00
|
|
|
$langConvFactory->method( 'getLanguageConverter' )->willReturn( $langConv );
|
2019-07-09 16:10:31 +00:00
|
|
|
|
2024-03-02 19:34:53 +00:00
|
|
|
return $langConvFactory;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build test Title object
|
|
|
|
*/
|
2024-10-21 18:39:39 +00:00
|
|
|
private function getTitle(): Title {
|
2024-03-03 07:55:20 +00:00
|
|
|
$languageMock = $this->createMock( Language::class );
|
2022-05-03 18:11:54 +00:00
|
|
|
$title = $this->createMock( Title::class );
|
2024-03-02 20:07:16 +00:00
|
|
|
$title->method( 'getPageLanguage' )
|
2019-07-09 16:10:31 +00:00
|
|
|
->willReturn( $languageMock );
|
|
|
|
|
|
|
|
return $title;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-03-02 19:34:53 +00:00
|
|
|
* @dataProvider provideDoesTitleHasLanguagesOrVariants
|
2019-07-09 16:10:31 +00:00
|
|
|
* @covers ::__construct
|
|
|
|
* @covers ::doesTitleHasLanguagesOrVariants
|
|
|
|
*/
|
2024-03-02 19:34:53 +00:00
|
|
|
public function testDoesTitleHasLanguagesOrVariants( bool $hasVariants, array $langLinks, bool $expected ) {
|
2024-03-02 19:34:53 +00:00
|
|
|
$helper = new LanguagesHelper(
|
2024-03-23 21:43:33 +00:00
|
|
|
$this->getLanguageConverterFactory( $hasVariants )
|
2024-03-02 19:34:53 +00:00
|
|
|
);
|
|
|
|
|
2024-03-23 21:43:33 +00:00
|
|
|
$this->assertSame( $expected, $helper->doesTitleHasLanguagesOrVariants(
|
|
|
|
$this->getOutput( $langLinks ),
|
|
|
|
$this->getTitle()
|
|
|
|
) );
|
2019-07-09 16:10:31 +00:00
|
|
|
}
|
|
|
|
|
2024-03-02 19:34:53 +00:00
|
|
|
public static function provideDoesTitleHasLanguagesOrVariants() {
|
|
|
|
return [
|
|
|
|
[ false, [ 'pl:StronaTestowa', 'en:TestPage' ], true ],
|
|
|
|
[ true, [ 'pl:StronaTestowa', 'en:TestPage' ], true ],
|
|
|
|
[ false, [], false ],
|
|
|
|
[ true, [], true ],
|
|
|
|
];
|
2019-07-09 16:10:31 +00:00
|
|
|
}
|
|
|
|
}
|