2017-07-12 15:12:40 +00:00
|
|
|
<?php
|
|
|
|
|
2017-07-14 23:56:16 +00:00
|
|
|
namespace Tests\MediaWiki\Minerva;
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2019-04-10 21:43:50 +00:00
|
|
|
use MediaWiki\Minerva\SkinOptions;
|
2022-03-04 16:40:54 +00:00
|
|
|
use MediaWiki\Minerva\Skins\SkinMinerva;
|
2021-10-11 22:53:10 +00:00
|
|
|
use MediaWikiIntegrationTestCase;
|
2017-07-12 15:12:40 +00:00
|
|
|
use OutputPage;
|
|
|
|
use RequestContext;
|
|
|
|
use Title;
|
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
|
|
/**
|
2022-03-04 16:40:54 +00:00
|
|
|
* @coversDefaultClass \MediaWiki\Minerva\Skins\SkinMinerva
|
2017-07-14 23:56:16 +00:00
|
|
|
* @group MinervaNeue
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
2021-10-11 22:53:10 +00:00
|
|
|
class SkinMinervaTest extends MediaWikiIntegrationTestCase {
|
2021-01-15 20:57:04 +00:00
|
|
|
/**
|
|
|
|
* @param array $options
|
|
|
|
*/
|
2019-04-10 21:43:50 +00:00
|
|
|
private function overrideSkinOptions( $options ) {
|
|
|
|
$mockOptions = new SkinOptions();
|
|
|
|
$mockOptions->setMultiple( $options );
|
|
|
|
$this->setService( 'Minerva.SkinOptions', $mockOptions );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::setContext
|
|
|
|
* @covers ::hasCategoryLinks
|
|
|
|
*/
|
|
|
|
public function testHasCategoryLinksWhenOptionIsOff() {
|
|
|
|
$outputPage = $this->getMockBuilder( OutputPage::class )
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$outputPage->expects( $this->never() )
|
|
|
|
->method( 'getCategoryLinks' );
|
|
|
|
|
2019-08-01 16:18:18 +00:00
|
|
|
$this->overrideSkinOptions( [ SkinOptions::CATEGORIES => false ] );
|
2017-07-12 15:12:40 +00:00
|
|
|
$context = new RequestContext();
|
2022-03-10 21:39:37 +00:00
|
|
|
$context->setTitle( Title::makeTitle( NS_MAIN, 'Test' ) );
|
2017-07-12 15:12:40 +00:00
|
|
|
$context->setOutput( $outputPage );
|
|
|
|
|
|
|
|
$skin = new SkinMinerva();
|
|
|
|
$skin->setContext( $context );
|
|
|
|
$skin = TestingAccessWrapper::newFromObject( $skin );
|
|
|
|
|
2021-11-13 17:58:14 +00:00
|
|
|
$this->assertFalse( $skin->hasCategoryLinks() );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideHasCategoryLinks
|
|
|
|
* @param array $categoryLinks
|
|
|
|
* @param bool $expected
|
|
|
|
* @covers ::setContext
|
2017-12-29 20:26:59 +00:00
|
|
|
* @covers ::hasCategoryLinks
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
public function testHasCategoryLinks( array $categoryLinks, $expected ) {
|
|
|
|
$outputPage = $this->getMockBuilder( OutputPage::class )
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$outputPage->expects( $this->once() )
|
|
|
|
->method( 'getCategoryLinks' )
|
2021-12-17 10:29:48 +00:00
|
|
|
->willReturn( $categoryLinks );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2019-08-01 16:18:18 +00:00
|
|
|
$this->overrideSkinOptions( [ SkinOptions::CATEGORIES => true ] );
|
2019-04-10 21:43:50 +00:00
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
$context = new RequestContext();
|
2022-03-10 21:39:37 +00:00
|
|
|
$context->setTitle( Title::makeTitle( NS_MAIN, 'Test' ) );
|
2017-07-12 15:12:40 +00:00
|
|
|
$context->setOutput( $outputPage );
|
|
|
|
|
|
|
|
$skin = new SkinMinerva();
|
|
|
|
$skin->setContext( $context );
|
|
|
|
|
|
|
|
$skin = TestingAccessWrapper::newFromObject( $skin );
|
|
|
|
|
2022-03-04 19:11:16 +00:00
|
|
|
$this->assertEquals( $expected, $skin->hasCategoryLinks() );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|