MediaWiki REL1_32
InterwikiLookupAdapterTest.php
Go to the documentation of this file.
1<?php
2
4
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}
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition COPYING.txt:326
MediaWiki\Interwiki\InterwikiLookupAdapter.
Class representing a MediaWiki site.
Definition Site.php:29