MediaWiki REL1_33
LinkRendererFactoryTest.php
Go to the documentation of this file.
1<?php
2
6
11
16
20 private $linkCache;
21
22 public function setUp() {
23 parent::setUp();
24 $this->titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
25 $this->linkCache = MediaWikiServices::getInstance()->getLinkCache();
26 }
27
28 public static function provideCreateFromLegacyOptions() {
29 return [
30 [
31 [ 'forcearticlepath' ],
32 'getForceArticlePath',
33 true
34 ],
35 [
36 [ 'http' ],
37 'getExpandURLs',
39 ],
40 [
41 [ 'https' ],
42 'getExpandURLs',
44 ],
45 [
46 [ 'stubThreshold' => 150 ],
47 'getStubThreshold',
48 150
49 ],
50 ];
51 }
52
56 public function testCreateFromLegacyOptions( $options, $func, $val ) {
57 $factory = new LinkRendererFactory( $this->titleFormatter, $this->linkCache );
58 $linkRenderer = $factory->createFromLegacyOptions(
60 );
61 $this->assertInstanceOf( LinkRenderer::class, $linkRenderer );
62 $this->assertEquals( $val, $linkRenderer->$func(), $func );
63 }
64
65 public function testCreate() {
66 $factory = new LinkRendererFactory( $this->titleFormatter, $this->linkCache );
67 $this->assertInstanceOf( LinkRenderer::class, $factory->create() );
68 }
69
70 public function testCreateForUser() {
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() );
81 }
82}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Cache for article titles (prefixed DB keys) and ids linked from one source.
Definition LinkCache.php:34
MediaWiki\Linker\LinkRendererFactory.
testCreateFromLegacyOptions( $options, $func, $val)
provideCreateFromLegacyOptions
Base class that store and restore the Language objects.
Factory to create LinkRender objects.
Class that generates HTML links for pages.
MediaWikiServices is the service locator for the application scope of MediaWiki.
const PROTO_HTTPS
Definition Defines.php:229
const PROTO_HTTP
Definition Defines.php:228
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition hooks.txt:1999
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition hooks.txt:2004
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form before processing starts Return false to skip default processing and return $ret $linkRenderer
Definition hooks.txt:2054
return true to allow those checks to and false if checking is done & $user
Definition hooks.txt:1510
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
A title formatter service for MediaWiki.