wiki.techinc.nl/tests/phpunit/unit/includes/linker/LinkRendererFactoryTest.php
Lucas Werkmeister 37d90f3664 Add comment flag to LinkRenderer
This marks whether links are being rendered for comments or elsewhere.
This information can be used in hooks; specifically, Wikibase wants to
add labels to entity links only in comments and on special pages.

Bug: T292203
Change-Id: I9164f760e8b46e05218fb36f430bc36ef1fdf30f
2021-11-02 13:03:20 +01:00

106 lines
2.5 KiB
PHP

<?php
use MediaWiki\HookContainer\HookContainer;
use MediaWiki\Linker\LinkRenderer;
use MediaWiki\Linker\LinkRendererFactory;
use MediaWiki\SpecialPage\SpecialPageFactory;
/**
* @covers MediaWiki\Linker\LinkRendererFactory
*/
class LinkRendererFactoryTest extends MediaWikiUnitTestCase {
/**
* @var TitleFormatter
*/
private $titleFormatter;
/**
* @var LinkCache
*/
private $linkCache;
/**
* @var SpecialPageFactory
*/
private $specialPageFactory;
/**
* @var HookContainer
*/
private $hookContainer;
protected function setUp(): void {
parent::setUp();
$this->titleFormatter = $this->createMock( TitleFormatter::class );
$this->linkCache = $this->createMock( LinkCache::class );
$this->specialPageFactory = $this->createMock( SpecialPageFactory::class );
$this->hookContainer = $this->createMock( HookContainer::class );
}
public static function provideCreateFromLegacyOptions() {
return [
[
[ 'forcearticlepath' ],
'getForceArticlePath',
true
],
[
[ 'http' ],
'getExpandURLs',
PROTO_HTTP
],
[
[ 'https' ],
'getExpandURLs',
PROTO_HTTPS
]
];
}
/**
* @dataProvider provideCreateFromLegacyOptions
*/
public function testCreateFromLegacyOptions( $options, $func, $val ) {
$factory = new LinkRendererFactory(
$this->titleFormatter,
$this->linkCache,
$this->specialPageFactory,
$this->hookContainer
);
$linkRenderer = $factory->createFromLegacyOptions(
$options
);
$this->assertInstanceOf( LinkRenderer::class, $linkRenderer );
$this->assertEquals( $val, $linkRenderer->$func(), $func );
$this->assertFalse(
$linkRenderer->isForComment(),
'isForComment should default to false in legacy implementation'
);
}
public function testCreate() {
$factory = new LinkRendererFactory(
$this->titleFormatter,
$this->linkCache,
$this->specialPageFactory,
$this->hookContainer
);
$linkRenderer = $factory->create();
$this->assertInstanceOf( LinkRenderer::class, $linkRenderer );
$this->assertFalse( $linkRenderer->isForComment(), 'isForComment should default to false' );
}
public function testCreateForComment() {
$factory = new LinkRendererFactory(
$this->titleFormatter,
$this->linkCache,
$this->specialPageFactory,
$this->hookContainer
);
$linkRenderer = $factory->create( [ 'renderForComment' => true ] );
$this->assertInstanceOf( LinkRenderer::class, $linkRenderer );
$this->assertTrue( $linkRenderer->isForComment() );
}
}