8 class WikiMapTest
extends MediaWikiLangTestCase
{
10 public function setUp() {
13 $conf = new SiteConfiguration();
16 'enwiki' => 'http://en.example.org',
17 'ruwiki' => '//ru.example.org',
21 'ruwiki' => '/wiki/$1',
24 $conf->suffixes
= [ 'wiki' ];
25 $this->setMwGlobals( [
29 TestSites
::insertIntoDb();
32 public function provideGetWiki() {
33 // As provided by $wgConf
34 $enwiki = new WikiReference( 'http://en.example.org', '/w/$1' );
35 $ruwiki = new WikiReference( '//ru.example.org', '/wiki/$1' );
37 // Created from site objects
38 $nlwiki = new WikiReference( 'https://nl.wikipedia.org', '/wiki/$1' );
39 // enwiktionary doesn't have an interwiki id, thus this falls back to minor = lang code
40 $enwiktionary = new WikiReference( 'https://en.wiktionary.org', '/wiki/$1' );
43 'unknown' => [ null, 'xyzzy' ],
44 'enwiki (wgConf)' => [ $enwiki, 'enwiki' ],
45 'ruwiki (wgConf)' => [ $ruwiki, 'ruwiki' ],
46 'nlwiki (sites)' => [ $nlwiki, 'nlwiki', false ],
47 'enwiktionary (sites)' => [ $enwiktionary, 'enwiktionary', false ],
48 'non MediaWiki site' => [ null, 'spam', false ],
53 * @dataProvider provideGetWiki
55 public function testGetWiki( $expected, $wikiId, $useWgConf = true ) {
57 $this->setMwGlobals( [
58 'wgConf' => new SiteConfiguration(),
62 $this->assertEquals( $expected, WikiMap
::getWiki( $wikiId ) );
65 public function provideGetWikiName() {
67 'unknown' => [ 'xyzzy', 'xyzzy' ],
68 'enwiki' => [ 'en.example.org', 'enwiki' ],
69 'ruwiki' => [ 'ru.example.org', 'ruwiki' ],
70 'enwiktionary (sites)' => [ 'en.wiktionary.org', 'enwiktionary' ],
75 * @dataProvider provideGetWikiName
77 public function testGetWikiName( $expected, $wikiId ) {
78 $this->assertEquals( $expected, WikiMap
::getWikiName( $wikiId ) );
81 public function provideMakeForeignLink() {
83 'unknown' => [ false, 'xyzzy', 'Foo' ],
85 '<a class="external" rel="nofollow" ' .
86 'href="http://en.example.org/w/Foo">Foo</a>',
91 '<a class="external" rel="nofollow" ' .
92 'href="//ru.example.org/wiki/%D0%A4%D1%83">вар</a>',
97 'enwiktionary (sites)' => [
98 '<a class="external" rel="nofollow" ' .
99 'href="https://en.wiktionary.org/wiki/Kitten">Kittens!</a>',
108 * @dataProvider provideMakeForeignLink
110 public function testMakeForeignLink( $expected, $wikiId, $page, $text = null ) {
113 WikiMap
::makeForeignLink( $wikiId, $page, $text )
117 public function provideForeignUserLink() {
119 'unknown' => [ false, 'xyzzy', 'Foo' ],
121 '<a class="external" rel="nofollow" ' .
122 'href="http://en.example.org/w/User:Foo">User:Foo</a>',
127 '<a class="external" rel="nofollow" ' .
128 'href="//ru.example.org/wiki/User:%D0%A4%D1%83">вар</a>',
133 'enwiktionary (sites)' => [
134 '<a class="external" rel="nofollow" ' .
135 'href="https://en.wiktionary.org/wiki/User:Dummy">Whatever</a>',
144 * @dataProvider provideForeignUserLink
146 public function testForeignUserLink( $expected, $wikiId, $user, $text = null ) {
147 $this->assertEquals( $expected, WikiMap
::foreignUserLink( $wikiId, $user, $text ) );
150 public function provideGetForeignURL() {
152 'unknown' => [ false, 'xyzzy', 'Foo' ],
153 'enwiki' => [ 'http://en.example.org/w/Foo', 'enwiki', 'Foo' ],
154 'enwiktionary (sites)' => [
155 'https://en.wiktionary.org/wiki/Testme',
159 'ruwiki with fragment' => [
160 '//ru.example.org/wiki/%D0%A4%D1%83#%D0%B2%D0%B0%D1%80',
169 * @dataProvider provideGetForeignURL
171 public function testGetForeignURL( $expected, $wikiId, $page, $fragment = null ) {
172 $this->assertEquals( $expected, WikiMap
::getForeignURL( $wikiId, $page, $fragment ) );