3 use MediaWiki\Linker\LinkRenderer
;
4 use MediaWiki\Linker\LinkRendererFactory
;
5 use MediaWiki\MediaWikiServices
;
8 * @covers MediaWiki\Linker\LinkRendererFactory
10 class LinkRendererFactoryTest
extends MediaWikiLangTestCase
{
15 private $titleFormatter;
22 public function setUp() {
24 $this->titleFormatter
= MediaWikiServices
::getInstance()->getTitleFormatter();
25 $this->linkCache
= MediaWikiServices
::getInstance()->getLinkCache();
28 public static function provideCreateFromLegacyOptions() {
31 [ 'forcearticlepath' ],
32 'getForceArticlePath',
46 [ 'stubThreshold' => 150 ],
54 * @dataProvider provideCreateFromLegacyOptions
56 public function testCreateFromLegacyOptions( $options, $func, $val ) {
57 $factory = new LinkRendererFactory( $this->titleFormatter
, $this->linkCache
);
58 $linkRenderer = $factory->createFromLegacyOptions(
61 $this->assertInstanceOf( LinkRenderer
::class, $linkRenderer );
62 $this->assertEquals( $val, $linkRenderer->$func(), $func );
65 public function testCreate() {
66 $factory = new LinkRendererFactory( $this->titleFormatter
, $this->linkCache
);
67 $this->assertInstanceOf( LinkRenderer
::class, $factory->create() );
70 public function testCreateForUser() {
71 /** @var PHPUnit_Framework_MockObject_MockObject|User $user */
72 $user = $this->getMock( User
::class, [ 'getStubThreshold' ] );
73 $user->expects( $this->once() )
74 ->method( 'getStubThreshold' )
76 $factory = new LinkRendererFactory( $this->titleFormatter
, $this->linkCache
);
77 $linkRenderer = $factory->createForUser( $user );
78 $this->assertInstanceOf( LinkRenderer
::class, $linkRenderer );
79 $this->assertEquals( 15, $linkRenderer->getStubThreshold() );