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->getMockBuilder( User
::class )
73 ->setMethods( [ 'getStubThreshold' ] )->getMock();
74 $user->expects( $this->once() )
75 ->method( 'getStubThreshold' )
77 $factory = new LinkRendererFactory( $this->titleFormatter
, $this->linkCache
);
78 $linkRenderer = $factory->createForUser( $user );
79 $this->assertInstanceOf( LinkRenderer
::class, $linkRenderer );
80 $this->assertEquals( 15, $linkRenderer->getStubThreshold() );