Merge "Remove parameter 'options' from hook 'SkinEditSectionLinks'"
[lhc/web/wiklou.git] / tests / phpunit / includes / linker / LinkRendererFactoryTest.php
1 <?php
2
3 use MediaWiki\Linker\LinkRenderer;
4 use MediaWiki\Linker\LinkRendererFactory;
5 use MediaWiki\MediaWikiServices;
6
7 /**
8 * @covers MediaWiki\Linker\LinkRendererFactory
9 */
10 class LinkRendererFactoryTest extends MediaWikiLangTestCase {
11
12 /**
13 * @var TitleFormatter
14 */
15 private $titleFormatter;
16
17 /**
18 * @var LinkCache
19 */
20 private $linkCache;
21
22 /**
23 * @var NamespaceInfo
24 */
25 private $nsInfo;
26
27 public function setUp() {
28 parent::setUp();
29
30 $services = MediaWikiServices::getInstance();
31 $this->titleFormatter = $services->getTitleFormatter();
32 $this->linkCache = $services->getLinkCache();
33 $this->nsInfo = $services->getNamespaceInfo();
34 }
35
36 public static function provideCreateFromLegacyOptions() {
37 return [
38 [
39 [ 'forcearticlepath' ],
40 'getForceArticlePath',
41 true
42 ],
43 [
44 [ 'http' ],
45 'getExpandURLs',
46 PROTO_HTTP
47 ],
48 [
49 [ 'https' ],
50 'getExpandURLs',
51 PROTO_HTTPS
52 ],
53 [
54 [ 'stubThreshold' => 150 ],
55 'getStubThreshold',
56 150
57 ],
58 ];
59 }
60
61 /**
62 * @dataProvider provideCreateFromLegacyOptions
63 */
64 public function testCreateFromLegacyOptions( $options, $func, $val ) {
65 $factory =
66 new LinkRendererFactory( $this->titleFormatter, $this->linkCache, $this->nsInfo );
67 $linkRenderer = $factory->createFromLegacyOptions(
68 $options
69 );
70 $this->assertInstanceOf( LinkRenderer::class, $linkRenderer );
71 $this->assertEquals( $val, $linkRenderer->$func(), $func );
72 }
73
74 public function testCreate() {
75 $factory =
76 new LinkRendererFactory( $this->titleFormatter, $this->linkCache, $this->nsInfo );
77 $this->assertInstanceOf( LinkRenderer::class, $factory->create() );
78 }
79
80 public function testCreateForUser() {
81 /** @var PHPUnit_Framework_MockObject_MockObject|User $user */
82 $user = $this->getMockBuilder( User::class )
83 ->setMethods( [ 'getStubThreshold' ] )->getMock();
84 $user->expects( $this->once() )
85 ->method( 'getStubThreshold' )
86 ->willReturn( 15 );
87 $factory =
88 new LinkRendererFactory( $this->titleFormatter, $this->linkCache, $this->nsInfo );
89 $linkRenderer = $factory->createForUser( $user );
90 $this->assertInstanceOf( LinkRenderer::class, $linkRenderer );
91 $this->assertEquals( 15, $linkRenderer->getStubThreshold() );
92 }
93 }