MediaWiki  1.30.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  $interwiki = $this->interwikiLookup->fetch( '' );
43  $this->assertNull( $interwiki );
44 
45  $interwiki = $this->interwikiLookup->fetch( 'xyz' );
46  $this->assertFalse( $interwiki );
47 
48  $interwiki = $this->interwikiLookup->fetch( 'foo' );
49  $this->assertInstanceOf( Interwiki::class, $interwiki );
50  $this->assertSame( 'foobar', $interwiki->getWikiID() );
51 
52  $interwiki = $this->interwikiLookup->fetch( 'enwt' );
53  $this->assertInstanceOf( Interwiki::class, $interwiki );
54 
55  $this->assertSame( 'https://en.wiktionary.org/wiki/$1', $interwiki->getURL(), 'getURL' );
56  $this->assertSame( 'https://en.wiktionary.org/w/api.php', $interwiki->getAPI(), 'getAPI' );
57  $this->assertSame( 'enwiktionary', $interwiki->getWikiID(), 'getWikiID' );
58  $this->assertTrue( $interwiki->isLocal(), 'isLocal' );
59  }
60 
61  public function testGetAllPrefixes() {
62  $foo = [
63  'iw_prefix' => 'foo',
64  'iw_url' => '',
65  'iw_api' => '',
66  'iw_wikiid' => 'foobar',
67  'iw_local' => false,
68  'iw_trans' => false,
69  ];
70  $enwt = [
71  'iw_prefix' => 'enwt',
72  'iw_url' => 'https://en.wiktionary.org/wiki/$1',
73  'iw_api' => 'https://en.wiktionary.org/w/api.php',
74  'iw_wikiid' => 'enwiktionary',
75  'iw_local' => true,
76  'iw_trans' => false,
77  ];
78 
79  $this->assertEquals(
80  [ $foo, $enwt ],
81  $this->interwikiLookup->getAllPrefixes(),
82  'getAllPrefixes()'
83  );
84 
85  $this->assertEquals(
86  [ $foo ],
87  $this->interwikiLookup->getAllPrefixes( false ),
88  'get external prefixes'
89  );
90 
91  $this->assertEquals(
92  [ $enwt ],
93  $this->interwikiLookup->getAllPrefixes( true ),
94  'get local prefixes'
95  );
96  }
97 
98  private function getSiteLookup( SiteList $sites ) {
99  $siteLookup = $this->getMockBuilder( SiteLookup::class )
100  ->disableOriginalConstructor()
101  ->getMock();
102 
103  $siteLookup->expects( $this->any() )
104  ->method( 'getSites' )
105  ->will( $this->returnValue( $sites ) );
106 
107  return $siteLookup;
108  }
109 
110  private function getSites() {
111  $sites = [];
112 
113  $site = new Site();
114  $site->setGlobalId( 'foobar' );
115  $site->addInterwikiId( 'foo' );
116  $site->setSource( 'external' );
117  $sites[] = $site;
118 
119  $site = new MediaWikiSite();
120  $site->setGlobalId( 'enwiktionary' );
121  $site->setGroup( 'wiktionary' );
122  $site->setLanguageCode( 'en' );
123  $site->addNavigationId( 'enwiktionary' );
124  $site->addInterwikiId( 'enwt' );
125  $site->setSource( 'local' );
126  $site->setPath( MediaWikiSite::PATH_PAGE, "https://en.wiktionary.org/wiki/$1" );
127  $site->setPath( MediaWikiSite::PATH_FILE, "https://en.wiktionary.org/w/$1" );
128  $sites[] = $site;
129 
130  return new SiteList( $sites );
131  }
132 
133 }
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:15
SiteList
Definition: SiteList.php:29
InterwikiLookupAdapterTest\getSiteLookup
getSiteLookup(SiteList $sites)
Definition: InterwikiLookupAdapterTest.php:98
InterwikiLookupAdapterTest\getSites
getSites()
Definition: InterwikiLookupAdapterTest.php:110
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:61
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