MediaWiki  1.29.2
InterwikiLookupAdapterTest.php
Go to the documentation of this file.
1 <?php
2 
10 
12 
17 
18  protected function setUp() {
19  parent::setUp();
20 
21  $this->interwikiLookup = new InterwikiLookupAdapter(
22  $this->getSiteLookup( $this->getSites() )
23  );
24  }
25 
26  public function testIsValidInterwiki() {
27  $this->assertTrue(
28  $this->interwikiLookup->isValidInterwiki( 'enwt' ),
29  'enwt known prefix is valid'
30  );
31  $this->assertTrue(
32  $this->interwikiLookup->isValidInterwiki( 'foo' ),
33  'foo site known prefix is valid'
34  );
35  $this->assertFalse(
36  $this->interwikiLookup->isValidInterwiki( 'xyz' ),
37  'unknown prefix is not valid'
38  );
39  }
40 
41  public function testFetch() {
42 
43  $interwiki = $this->interwikiLookup->fetch( '' );
44  $this->assertNull( $interwiki );
45 
46  $interwiki = $this->interwikiLookup->fetch( 'xyz' );
47  $this->assertFalse( $interwiki );
48 
49  $interwiki = $this->interwikiLookup->fetch( 'foo' );
50  $this->assertInstanceOf( Interwiki::class, $interwiki );
51  $this->assertSame( 'foobar', $interwiki->getWikiID() );
52 
53  $interwiki = $this->interwikiLookup->fetch( 'enwt' );
54  $this->assertInstanceOf( Interwiki::class, $interwiki );
55 
56  $this->assertSame( 'https://en.wiktionary.org/wiki/$1', $interwiki->getURL(), 'getURL' );
57  $this->assertSame( 'https://en.wiktionary.org/w/api.php', $interwiki->getAPI(), 'getAPI' );
58  $this->assertSame( 'enwiktionary', $interwiki->getWikiID(), 'getWikiID' );
59  $this->assertTrue( $interwiki->isLocal(), 'isLocal' );
60  }
61 
62  public function testGetAllPrefixes() {
63  $this->assertEquals(
64  [ 'foo', 'enwt' ],
65  $this->interwikiLookup->getAllPrefixes(),
66  'getAllPrefixes()'
67  );
68 
69  $this->assertEquals(
70  [ 'foo' ],
71  $this->interwikiLookup->getAllPrefixes( false ),
72  'get external prefixes'
73  );
74 
75  $this->assertEquals(
76  [ 'enwt' ],
77  $this->interwikiLookup->getAllPrefixes( true ),
78  'get local prefixes'
79  );
80  }
81 
82  private function getSiteLookup( SiteList $sites ) {
83  $siteLookup = $this->getMockBuilder( SiteLookup::class )
84  ->disableOriginalConstructor()
85  ->getMock();
86 
87  $siteLookup->expects( $this->any() )
88  ->method( 'getSites' )
89  ->will( $this->returnValue( $sites ) );
90 
91  return $siteLookup;
92  }
93 
94  private function getSites() {
95  $sites = [];
96 
97  $site = new Site();
98  $site->setGlobalId( 'foobar' );
99  $site->addInterwikiId( 'foo' );
100  $site->setSource( 'external' );
101  $sites[] = $site;
102 
103  $site = new MediaWikiSite();
104  $site->setGlobalId( 'enwiktionary' );
105  $site->setGroup( 'wiktionary' );
106  $site->setLanguageCode( 'en' );
107  $site->addNavigationId( 'enwiktionary' );
108  $site->addInterwikiId( 'enwt' );
109  $site->setSource( 'local' );
110  $site->setPath( MediaWikiSite::PATH_PAGE, "https://en.wiktionary.org/wiki/$1" );
111  $site->setPath( MediaWikiSite::PATH_FILE, "https://en.wiktionary.org/w/$1" );
112  $sites[] = $site;
113 
114  return new SiteList( $sites );
115  }
116 
117 }
InterwikiLookupAdapterTest\testFetch
testFetch()
Definition: InterwikiLookupAdapterTest.php:41
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
InterwikiLookupAdapterTest\testIsValidInterwiki
testIsValidInterwiki()
Definition: InterwikiLookupAdapterTest.php:26
MediaWiki\Interwiki\InterwikiLookupAdapter
Definition: InterwikiLookupAdapter.php:35
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
MediaWikiTestCase
Definition: MediaWikiTestCase.php:13
SiteList
Definition: SiteList.php:29
InterwikiLookupAdapterTest\getSiteLookup
getSiteLookup(SiteList $sites)
Definition: InterwikiLookupAdapterTest.php:82
InterwikiLookupAdapterTest\getSites
getSites()
Definition: InterwikiLookupAdapterTest.php:94
MediaWikiSite\PATH_FILE
const PATH_FILE
Definition: MediaWikiSite.php:39
Site
Definition: Site.php:29
any
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition: COPYING.txt:326
InterwikiLookupAdapterTest
Definition: InterwikiLookupAdapterTest.php:11
InterwikiLookupAdapterTest\$interwikiLookup
InterwikiLookupAdapter $interwikiLookup
Definition: InterwikiLookupAdapterTest.php:16
MediaWikiSite\PATH_PAGE
const PATH_PAGE
Definition: MediaWikiSite.php:40
InterwikiLookupAdapterTest\testGetAllPrefixes
testGetAllPrefixes()
Definition: InterwikiLookupAdapterTest.php:62
MediaWikiSite
Class representing a MediaWiki site.
Definition: MediaWikiSite.php:38
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
InterwikiLookupAdapterTest\setUp
setUp()
Definition: InterwikiLookupAdapterTest.php:18