Merge "Update docs/hooks.txt for ShowSearchHitTitle"
[mediawiki.git] / tests / phpunit / includes / linker / LinkRendererFactoryTest.php
blobbf12f80f0a01cbd83cbb614b1b6650ac1775abfc
1 <?php
3 use MediaWiki\Linker\LinkRenderer;
4 use MediaWiki\Linker\LinkRendererFactory;
5 use MediaWiki\MediaWikiServices;
7 /**
8 * @covers MediaWiki\Linker\LinkRendererFactory
9 */
10 class LinkRendererFactoryTest extends MediaWikiLangTestCase {
12 /**
13 * @var TitleFormatter
15 private $titleFormatter;
17 /**
18 * @var LinkCache
20 private $linkCache;
22 public function setUp() {
23 parent::setUp();
24 $this->titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
25 $this->linkCache = MediaWikiServices::getInstance()->getLinkCache();
28 public static function provideCreateFromLegacyOptions() {
29 return [
31 [ 'forcearticlepath' ],
32 'getForceArticlePath',
33 true
36 [ 'http' ],
37 'getExpandURLs',
38 PROTO_HTTP
41 [ 'https' ],
42 'getExpandURLs',
43 PROTO_HTTPS
46 [ 'stubThreshold' => 150 ],
47 'getStubThreshold',
48 150
53 /**
54 * @dataProvider provideCreateFromLegacyOptions
56 public function testCreateFromLegacyOptions( $options, $func, $val ) {
57 $factory = new LinkRendererFactory( $this->titleFormatter, $this->linkCache );
58 $linkRenderer = $factory->createFromLegacyOptions(
59 $options
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' )
75 ->willReturn( 15 );
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() );