186ffdbcc32ffed732fbb131f9e2bc93597de05b
8 class WikiMapTest
extends MediaWikiLangTestCase
{
10 public function setUp() {
13 $conf = new SiteConfiguration();
16 'enwiki' => 'http://en.example.org',
17 'ruwiki' => '//ru.example.org',
18 'nopathwiki' => '//nopath.example.org',
19 'thiswiki' => '//this.wiki.org'
23 'ruwiki' => '/wiki/$1',
26 $conf->suffixes
= [ 'wiki' ];
27 $this->setMwGlobals( [
29 'wgLocalDatabases' => [ 'enwiki', 'ruwiki', 'nopathwiki' ],
30 'wgCanonicalServer' => '//this.wiki.org',
31 'wgDBname' => 'thiswiki',
35 TestSites
::insertIntoDb();
38 public function provideGetWiki() {
39 // As provided by $wgConf
40 $enwiki = new WikiReference( 'http://en.example.org', '/w/$1' );
41 $ruwiki = new WikiReference( '//ru.example.org', '/wiki/$1' );
43 // Created from site objects
44 $nlwiki = new WikiReference( 'https://nl.wikipedia.org', '/wiki/$1' );
45 // enwiktionary doesn't have an interwiki id, thus this falls back to minor = lang code
46 $enwiktionary = new WikiReference( 'https://en.wiktionary.org', '/wiki/$1' );
49 'unknown' => [ null, 'xyzzy' ],
50 'enwiki (wgConf)' => [ $enwiki, 'enwiki' ],
51 'ruwiki (wgConf)' => [ $ruwiki, 'ruwiki' ],
52 'nlwiki (sites)' => [ $nlwiki, 'nlwiki', false ],
53 'enwiktionary (sites)' => [ $enwiktionary, 'enwiktionary', false ],
54 'non MediaWiki site' => [ null, 'spam', false ],
55 'boguswiki' => [ null, 'boguswiki' ],
56 'nopathwiki' => [ null, 'nopathwiki' ],
61 * @dataProvider provideGetWiki
63 public function testGetWiki( $expected, $wikiId, $useWgConf = true ) {
65 $this->setMwGlobals( [
66 'wgConf' => new SiteConfiguration(),
70 $this->assertEquals( $expected, WikiMap
::getWiki( $wikiId ) );
73 public function provideGetWikiName() {
75 'unknown' => [ 'xyzzy', 'xyzzy' ],
76 'enwiki' => [ 'en.example.org', 'enwiki' ],
77 'ruwiki' => [ 'ru.example.org', 'ruwiki' ],
78 'enwiktionary (sites)' => [ 'en.wiktionary.org', 'enwiktionary' ],
83 * @dataProvider provideGetWikiName
85 public function testGetWikiName( $expected, $wikiId ) {
86 $this->assertEquals( $expected, WikiMap
::getWikiName( $wikiId ) );
89 public function provideMakeForeignLink() {
91 'unknown' => [ false, 'xyzzy', 'Foo' ],
93 '<a class="external" rel="nofollow" ' .
94 'href="http://en.example.org/w/Foo">Foo</a>',
99 '<a class="external" rel="nofollow" ' .
100 'href="//ru.example.org/wiki/%D0%A4%D1%83">вар</a>',
105 'enwiktionary (sites)' => [
106 '<a class="external" rel="nofollow" ' .
107 'href="https://en.wiktionary.org/wiki/Kitten">Kittens!</a>',
116 * @dataProvider provideMakeForeignLink
118 public function testMakeForeignLink( $expected, $wikiId, $page, $text = null ) {
121 WikiMap
::makeForeignLink( $wikiId, $page, $text )
125 public function provideForeignUserLink() {
127 'unknown' => [ false, 'xyzzy', 'Foo' ],
129 '<a class="external" rel="nofollow" ' .
130 'href="http://en.example.org/w/User:Foo">User:Foo</a>',
135 '<a class="external" rel="nofollow" ' .
136 'href="//ru.example.org/wiki/User:%D0%A4%D1%83">вар</a>',
141 'enwiktionary (sites)' => [
142 '<a class="external" rel="nofollow" ' .
143 'href="https://en.wiktionary.org/wiki/User:Dummy">Whatever</a>',
152 * @dataProvider provideForeignUserLink
154 public function testForeignUserLink( $expected, $wikiId, $user, $text = null ) {
155 $this->assertEquals( $expected, WikiMap
::foreignUserLink( $wikiId, $user, $text ) );
158 public function provideGetForeignURL() {
160 'unknown' => [ false, 'xyzzy', 'Foo' ],
161 'enwiki' => [ 'http://en.example.org/w/Foo', 'enwiki', 'Foo' ],
162 'enwiktionary (sites)' => [
163 'https://en.wiktionary.org/wiki/Testme',
167 'ruwiki with fragment' => [
168 '//ru.example.org/wiki/%D0%A4%D1%83#%D0%B2%D0%B0%D1%80',
177 * @dataProvider provideGetForeignURL
179 public function testGetForeignURL( $expected, $wikiId, $page, $fragment = null ) {
180 $this->assertEquals( $expected, WikiMap
::getForeignURL( $wikiId, $page, $fragment ) );
184 * @covers WikiMap::getCanonicalServerInfoForAllWikis()
186 public function testGetCanonicalServerInfoForAllWikis() {
189 'url' => '//this.wiki.org',
190 'parts' => [ 'scheme' => '', 'host' => 'this.wiki.org', 'delimiter' => '//' ]
193 'url' => 'http://en.example.org',
195 'scheme' => 'http', 'host' => 'en.example.org', 'delimiter' => '://' ]
198 'url' => '//ru.example.org',
199 'parts' => [ 'scheme' => '', 'host' => 'ru.example.org', 'delimiter' => '//' ]
203 $this->assertArrayEquals(
205 WikiMap
::getCanonicalServerInfoForAllWikis(),
211 public function provideGetWikiFromUrl() {
213 [ 'http://this.wiki.org', 'thiswiki' ],
214 [ 'https://this.wiki.org', 'thiswiki' ],
215 [ 'http://this.wiki.org/$1', 'thiswiki' ],
216 [ 'https://this.wiki.org/$2', 'thiswiki' ],
217 [ 'http://en.example.org', 'enwiki' ],
218 [ 'https://en.example.org', 'enwiki' ],
219 [ 'http://en.example.org/$1', 'enwiki' ],
220 [ 'https://en.example.org/$2', 'enwiki' ],
221 [ 'http://ru.example.org', 'ruwiki' ],
222 [ 'https://ru.example.org', 'ruwiki' ],
223 [ 'http://ru.example.org/$1', 'ruwiki' ],
224 [ 'https://ru.example.org/$2', 'ruwiki' ],
225 [ 'http://not.defined.org', false ]
230 * @dataProvider provideGetWikiFromUrl
231 * @covers WikiMap::getWikiFromUrl()
233 public function testGetWikiFromUrl( $url, $wiki ) {
234 $this->assertEquals( $wiki, WikiMap
::getWikiFromUrl( $url ) );