mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-17 19:21:39 +00:00
3da8d0c734
Change-Id: I5dee074f69a48a6aca218855859a518ca1c051e1
110 lines
2.6 KiB
PHP
110 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\MediaWiki\Minerva;
|
|
|
|
use MediaWiki\Minerva\SkinOptions;
|
|
use MediaWikiIntegrationTestCase;
|
|
use OutputPage;
|
|
use RequestContext;
|
|
use SkinMinerva;
|
|
use Title;
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
/**
|
|
* @coversDefaultClass SkinMinerva
|
|
* @group MinervaNeue
|
|
*/
|
|
class SkinMinervaTest extends MediaWikiIntegrationTestCase {
|
|
/**
|
|
* @param array $options
|
|
*/
|
|
private function overrideSkinOptions( $options ) {
|
|
$mockOptions = new SkinOptions();
|
|
$mockOptions->setMultiple( $options );
|
|
$this->setService( 'Minerva.SkinOptions', $mockOptions );
|
|
}
|
|
|
|
/**
|
|
* @covers ::setContext
|
|
* @covers ::hasCategoryLinks
|
|
*/
|
|
public function testHasCategoryLinksWhenOptionIsOff() {
|
|
$outputPage = $this->getMockBuilder( OutputPage::class )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$outputPage->expects( $this->never() )
|
|
->method( 'getCategoryLinks' );
|
|
|
|
$this->overrideSkinOptions( [ SkinOptions::CATEGORIES => false ] );
|
|
$context = new RequestContext();
|
|
$context->setTitle( Title::newFromText( 'Test' ) );
|
|
$context->setOutput( $outputPage );
|
|
|
|
$skin = new SkinMinerva();
|
|
$skin->setContext( $context );
|
|
$skin = TestingAccessWrapper::newFromObject( $skin );
|
|
|
|
$this->assertFalse( $skin->hasCategoryLinks() );
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideHasCategoryLinks
|
|
* @param array $categoryLinks
|
|
* @param bool $expected
|
|
* @covers ::setContext
|
|
* @covers ::hasCategoryLinks
|
|
*/
|
|
public function testHasCategoryLinks( array $categoryLinks, $expected ) {
|
|
$outputPage = $this->getMockBuilder( OutputPage::class )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$outputPage->expects( $this->once() )
|
|
->method( 'getCategoryLinks' )
|
|
->willReturn( $categoryLinks );
|
|
|
|
$this->overrideSkinOptions( [ SkinOptions::CATEGORIES => true ] );
|
|
|
|
$context = new RequestContext();
|
|
$context->setTitle( Title::newFromText( 'Test' ) );
|
|
$context->setOutput( $outputPage );
|
|
|
|
$skin = new SkinMinerva();
|
|
$skin->setContext( $context );
|
|
|
|
$skin = TestingAccessWrapper::newFromObject( $skin );
|
|
|
|
$this->assertEquals( $expected, $skin->hasCategoryLinks() );
|
|
}
|
|
|
|
public function provideHasCategoryLinks() {
|
|
return [
|
|
[ [], false ],
|
|
[
|
|
[
|
|
'normal' => '<ul><li><a href="/wiki/Category:1">1</a></li></ul>'
|
|
],
|
|
true
|
|
],
|
|
[
|
|
[
|
|
'hidden' => '<ul><li><a href="/wiki/Category:Hidden">Hidden</a></li></ul>'
|
|
],
|
|
true
|
|
],
|
|
[
|
|
[
|
|
'normal' => '<ul><li><a href="/wiki/Category:1">1</a></li></ul>',
|
|
'hidden' => '<ul><li><a href="/wiki/Category:Hidden">Hidden</a></li></ul>'
|
|
],
|
|
true
|
|
],
|
|
[
|
|
[
|
|
'unexpected' => '<ul><li><a href="/wiki/Category:1">1</a></li></ul>'
|
|
],
|
|
false
|
|
],
|
|
];
|
|
}
|
|
}
|