MediaWiki  1.29.1
LinkRendererFactoryTest.php
Go to the documentation of this file.
1 <?php
2 
6 
11 
15  private $titleFormatter;
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(
59  $options
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 }
LinkCache
Cache for article titles (prefixed DB keys) and ids linked from one source.
Definition: LinkCache.php:34
LinkRendererFactoryTest\testCreateFromLegacyOptions
testCreateFromLegacyOptions( $options, $func, $val)
provideCreateFromLegacyOptions
Definition: LinkRendererFactoryTest.php:56
MediaWiki\Linker\LinkRenderer
Class that generates HTML links for pages.
Definition: LinkRenderer.php:42
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:246
MediaWiki\Linker\LinkRendererFactory
Factory to create LinkRender objects.
Definition: LinkRendererFactory.php:32
$linkRenderer
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:1956
LinkRendererFactoryTest\testCreateForUser
testCreateForUser()
Definition: LinkRendererFactoryTest.php:70
LinkRendererFactoryTest\provideCreateFromLegacyOptions
static provideCreateFromLegacyOptions()
Definition: LinkRendererFactoryTest.php:28
php
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:35
LinkRendererFactoryTest
MediaWiki\Linker\LinkRendererFactory.
Definition: LinkRendererFactoryTest.php:10
LinkRendererFactoryTest\testCreate
testCreate()
Definition: LinkRendererFactoryTest.php:65
LinkRendererFactoryTest\$linkCache
LinkCache $linkCache
Definition: LinkRendererFactoryTest.php:20
LinkRendererFactoryTest\$titleFormatter
TitleFormatter $titleFormatter
Definition: LinkRendererFactoryTest.php:15
PROTO_HTTPS
const PROTO_HTTPS
Definition: Defines.php:218
LinkRendererFactoryTest\setUp
setUp()
Definition: LinkRendererFactoryTest.php:22
PROTO_HTTP
const PROTO_HTTP
Definition: Defines.php:217
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:6
TitleFormatter
A title formatter service for MediaWiki.
Definition: TitleFormatter.php:35
true
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:1956
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
MediaWikiServices
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 MediaWikiServices
Definition: injection.txt:23
$options
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition: hooks.txt:1049