rdbms: Rename "memCache" to "memStash" in LBFactory
[mediawiki.git] / tests / phpunit / includes / linker / LinkRendererFactoryTest.php
blob27e5a657ede644c14bbcc135b8f42a86636f4188
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->getMockBuilder( User::class )
73 ->setMethods( [ 'getStubThreshold' ] )->getMock();
74 $user->expects( $this->once() )
75 ->method( 'getStubThreshold' )
76 ->willReturn( 15 );
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() );