mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-29 00:20:51 +00:00
3e3cafe6b0
Bug: T192167 Change-Id: I34fc9bc5520e04a123642305ae0ca5d4f80d706c
74 lines
2 KiB
PHP
74 lines
2 KiB
PHP
<?php
|
|
|
|
namespace Tests\MediaWiki\Minerva;
|
|
|
|
use MediaWiki\Minerva\LanguagesHelper;
|
|
use PHPUnit\Framework\MockObject\Invocation;
|
|
|
|
/**
|
|
* Class SkinMinervaTest
|
|
* @package Tests\MediaWiki\Minerva
|
|
* @group MinervaNeue
|
|
* @coversDefaultClass \MediaWiki\Minerva\LanguagesHelper
|
|
*/
|
|
class LanguagesHelperTest extends \MediaWikiUnitTestCase {
|
|
|
|
/**
|
|
* Build test Output object
|
|
* @param array $langLinks
|
|
* @return \OutputPage
|
|
*/
|
|
private function getOutput( array $langLinks ) {
|
|
$out = $this->createMock( \OutputPage::class );
|
|
$out->expects( $this->once() )
|
|
->method( 'getLanguageLinks' )
|
|
->willReturn( $langLinks );
|
|
|
|
return $out;
|
|
}
|
|
|
|
/**
|
|
* Build test Title object
|
|
* @param $hasVariants
|
|
* @param Invocation|null $matcher
|
|
* @return \Title
|
|
*/
|
|
private function getTitle( $hasVariants, Invocation $matcher = null ) {
|
|
$languageMock = $this->createMock( \Language::class );
|
|
$languageMock->expects( $matcher ?? $this->any() )
|
|
->method( 'hasVariants' )
|
|
->willReturn( $hasVariants );
|
|
|
|
$title = $this->createMock( \Title::class );
|
|
$title->expects( $matcher ?? $this->any() )
|
|
->method( 'getPageLanguage' )
|
|
->willReturn( $languageMock );
|
|
|
|
return $title;
|
|
}
|
|
|
|
/**
|
|
* @covers ::__construct
|
|
* @covers ::doesTitleHasLanguagesOrVariants
|
|
*/
|
|
public function testReturnsWhenOutputPageHasLangLinks() {
|
|
$helper = new LanguagesHelper( $this->getOutput( [ 'pl:StronaTestowa', 'en:TestPage' ] ) );
|
|
|
|
$this->assertTrue( $helper->doesTitleHasLanguagesOrVariants( $this->getTitle( false ) ) );
|
|
$this->assertTrue( $helper->doesTitleHasLanguagesOrVariants( $this->getTitle( true ) ) );
|
|
}
|
|
|
|
/**
|
|
* @covers ::__construct
|
|
* @covers ::doesTitleHasLanguagesOrVariants
|
|
*/
|
|
public function testReturnsWhenOutputDoesNotHaveLangLinks() {
|
|
$helper = new LanguagesHelper( $this->getOutput( [] ) );
|
|
|
|
$this->assertFalse( $helper->doesTitleHasLanguagesOrVariants(
|
|
$this->getTitle( false ), $this->once() ) );
|
|
$this->assertTrue( $helper->doesTitleHasLanguagesOrVariants(
|
|
$this->getTitle( true ), $this->once() ) );
|
|
}
|
|
}
|