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',
22 'ruwiki' => '/wiki/$1',
25 $conf->suffixes
= [ 'wiki' ];
26 $this->setMwGlobals( [
30 TestSites
::insertIntoDb();
33 public function provideGetWiki() {
34 // As provided by $wgConf
35 $enwiki = new WikiReference( 'http://en.example.org', '/w/$1' );
36 $ruwiki = new WikiReference( '//ru.example.org', '/wiki/$1' );
38 // Created from site objects
39 $nlwiki = new WikiReference( 'https://nl.wikipedia.org', '/wiki/$1' );
40 // enwiktionary doesn't have an interwiki id, thus this falls back to minor = lang code
41 $enwiktionary = new WikiReference( 'https://en.wiktionary.org', '/wiki/$1' );
44 'unknown' => [ null, 'xyzzy' ],
45 'enwiki (wgConf)' => [ $enwiki, 'enwiki' ],
46 'ruwiki (wgConf)' => [ $ruwiki, 'ruwiki' ],
47 'nlwiki (sites)' => [ $nlwiki, 'nlwiki', false ],
48 'enwiktionary (sites)' => [ $enwiktionary, 'enwiktionary', false ],
49 'non MediaWiki site' => [ null, 'spam', false ],
50 'boguswiki' => [ null, 'boguswiki' ],
51 'nopathwiki' => [ null, 'nopathwiki' ],
56 * @dataProvider provideGetWiki
58 public function testGetWiki( $expected, $wikiId, $useWgConf = true ) {
60 $this->setMwGlobals( [
61 'wgConf' => new SiteConfiguration(),
65 $this->assertEquals( $expected, WikiMap
::getWiki( $wikiId ) );
68 public function provideGetWikiName() {
70 'unknown' => [ 'xyzzy', 'xyzzy' ],
71 'enwiki' => [ 'en.example.org', 'enwiki' ],
72 'ruwiki' => [ 'ru.example.org', 'ruwiki' ],
73 'enwiktionary (sites)' => [ 'en.wiktionary.org', 'enwiktionary' ],
78 * @dataProvider provideGetWikiName
80 public function testGetWikiName( $expected, $wikiId ) {
81 $this->assertEquals( $expected, WikiMap
::getWikiName( $wikiId ) );
84 public function provideMakeForeignLink() {
86 'unknown' => [ false, 'xyzzy', 'Foo' ],
88 '<a class="external" rel="nofollow" ' .
89 'href="http://en.example.org/w/Foo">Foo</a>',
94 '<a class="external" rel="nofollow" ' .
95 'href="//ru.example.org/wiki/%D0%A4%D1%83">вар</a>',
100 'enwiktionary (sites)' => [
101 '<a class="external" rel="nofollow" ' .
102 'href="https://en.wiktionary.org/wiki/Kitten">Kittens!</a>',
111 * @dataProvider provideMakeForeignLink
113 public function testMakeForeignLink( $expected, $wikiId, $page, $text = null ) {
116 WikiMap
::makeForeignLink( $wikiId, $page, $text )
120 public function provideForeignUserLink() {
122 'unknown' => [ false, 'xyzzy', 'Foo' ],
124 '<a class="external" rel="nofollow" ' .
125 'href="http://en.example.org/w/User:Foo">User:Foo</a>',
130 '<a class="external" rel="nofollow" ' .
131 'href="//ru.example.org/wiki/User:%D0%A4%D1%83">вар</a>',
136 'enwiktionary (sites)' => [
137 '<a class="external" rel="nofollow" ' .
138 'href="https://en.wiktionary.org/wiki/User:Dummy">Whatever</a>',
147 * @dataProvider provideForeignUserLink
149 public function testForeignUserLink( $expected, $wikiId, $user, $text = null ) {
150 $this->assertEquals( $expected, WikiMap
::foreignUserLink( $wikiId, $user, $text ) );
153 public function provideGetForeignURL() {
155 'unknown' => [ false, 'xyzzy', 'Foo' ],
156 'enwiki' => [ 'http://en.example.org/w/Foo', 'enwiki', 'Foo' ],
157 'enwiktionary (sites)' => [
158 'https://en.wiktionary.org/wiki/Testme',
162 'ruwiki with fragment' => [
163 '//ru.example.org/wiki/%D0%A4%D1%83#%D0%B2%D0%B0%D1%80',
172 * @dataProvider provideGetForeignURL
174 public function testGetForeignURL( $expected, $wikiId, $page, $fragment = null ) {
175 $this->assertEquals( $expected, WikiMap
::getForeignURL( $wikiId, $page, $fragment ) );