Merge "Added release notes for 'ContentHandler::runLegacyHooks' removal"
[mediawiki.git] / tests / phpunit / includes / WikiMapTest.php
blob12878b37ed26257021a8ce284897adc11d2ec13b
1 <?php
3 /**
4 * @covers WikiMap
6 * @group Database
7 */
8 class WikiMapTest extends MediaWikiLangTestCase {
10 public function setUp() {
11 parent::setUp();
13 $conf = new SiteConfiguration();
14 $conf->settings = [
15 'wgServer' => [
16 'enwiki' => 'http://en.example.org',
17 'ruwiki' => '//ru.example.org',
18 'nopathwiki' => '//nopath.example.org',
20 'wgArticlePath' => [
21 'enwiki' => '/w/$1',
22 'ruwiki' => '/wiki/$1',
25 $conf->suffixes = [ 'wiki' ];
26 $this->setMwGlobals( [
27 'wgConf' => $conf,
28 ] );
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' );
43 return [
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' ],
55 /**
56 * @dataProvider provideGetWiki
58 public function testGetWiki( $expected, $wikiId, $useWgConf = true ) {
59 if ( !$useWgConf ) {
60 $this->setMwGlobals( [
61 'wgConf' => new SiteConfiguration(),
62 ] );
65 $this->assertEquals( $expected, WikiMap::getWiki( $wikiId ) );
68 public function provideGetWikiName() {
69 return [
70 'unknown' => [ 'xyzzy', 'xyzzy' ],
71 'enwiki' => [ 'en.example.org', 'enwiki' ],
72 'ruwiki' => [ 'ru.example.org', 'ruwiki' ],
73 'enwiktionary (sites)' => [ 'en.wiktionary.org', 'enwiktionary' ],
77 /**
78 * @dataProvider provideGetWikiName
80 public function testGetWikiName( $expected, $wikiId ) {
81 $this->assertEquals( $expected, WikiMap::getWikiName( $wikiId ) );
84 public function provideMakeForeignLink() {
85 return [
86 'unknown' => [ false, 'xyzzy', 'Foo' ],
87 'enwiki' => [
88 '<a class="external" rel="nofollow" ' .
89 'href="http://en.example.org/w/Foo">Foo</a>',
90 'enwiki',
91 'Foo'
93 'ruwiki' => [
94 '<a class="external" rel="nofollow" ' .
95 'href="//ru.example.org/wiki/%D0%A4%D1%83">вар</a>',
96 'ruwiki',
97 'Фу',
98 'вар'
100 'enwiktionary (sites)' => [
101 '<a class="external" rel="nofollow" ' .
102 'href="https://en.wiktionary.org/wiki/Kitten">Kittens!</a>',
103 'enwiktionary',
104 'Kitten',
105 'Kittens!'
111 * @dataProvider provideMakeForeignLink
113 public function testMakeForeignLink( $expected, $wikiId, $page, $text = null ) {
114 $this->assertEquals(
115 $expected,
116 WikiMap::makeForeignLink( $wikiId, $page, $text )
120 public function provideForeignUserLink() {
121 return [
122 'unknown' => [ false, 'xyzzy', 'Foo' ],
123 'enwiki' => [
124 '<a class="external" rel="nofollow" ' .
125 'href="http://en.example.org/w/User:Foo">User:Foo</a>',
126 'enwiki',
127 'Foo'
129 'ruwiki' => [
130 '<a class="external" rel="nofollow" ' .
131 'href="//ru.example.org/wiki/User:%D0%A4%D1%83">вар</a>',
132 'ruwiki',
133 'Фу',
134 'вар'
136 'enwiktionary (sites)' => [
137 '<a class="external" rel="nofollow" ' .
138 'href="https://en.wiktionary.org/wiki/User:Dummy">Whatever</a>',
139 'enwiktionary',
140 'Dummy',
141 'Whatever'
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() {
154 return [
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',
159 'enwiktionary',
160 'Testme'
162 'ruwiki with fragment' => [
163 '//ru.example.org/wiki/%D0%A4%D1%83#%D0%B2%D0%B0%D1%80',
164 'ruwiki',
165 'Фу',
166 'вар'
172 * @dataProvider provideGetForeignURL
174 public function testGetForeignURL( $expected, $wikiId, $page, $fragment = null ) {
175 $this->assertEquals( $expected, WikiMap::getForeignURL( $wikiId, $page, $fragment ) );