Import: Handle uploads with sha1 starting with 0 properly
[mediawiki.git] / tests / phpunit / includes / WikiMapTest.php
blobe86559e7d89fe8d438c15a1637dddd7b827a7f16
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 = array(
15 'wgServer' => array(
16 'enwiki' => 'http://en.example.org',
17 'ruwiki' => '//ru.example.org',
19 'wgArticlePath' => array(
20 'enwiki' => '/w/$1',
21 'ruwiki' => '/wiki/$1',
24 $conf->suffixes = array( 'wiki' );
25 $this->setMwGlobals( array(
26 'wgConf' => $conf,
27 ) );
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' );
42 return array(
43 'unknown' => array( null, 'xyzzy' ),
44 'enwiki (wgConf)' => array( $enwiki, 'enwiki' ),
45 'ruwiki (wgConf)' => array( $ruwiki, 'ruwiki' ),
46 'nlwiki (sites)' => array( $nlwiki, 'nlwiki', false ),
47 'enwiktionary (sites)' => array( $enwiktionary, 'enwiktionary', false ),
48 'non MediaWiki site' => array( null, 'spam', false ),
52 /**
53 * @dataProvider provideGetWiki
55 public function testGetWiki( $expected, $wikiId, $useWgConf = true ) {
56 if ( !$useWgConf ) {
57 $this->setMwGlobals( array(
58 'wgConf' => new SiteConfiguration(),
59 ) );
62 $this->assertEquals( $expected, WikiMap::getWiki( $wikiId ) );
65 public function provideGetWikiName() {
66 return array(
67 'unknown' => array( 'xyzzy', 'xyzzy' ),
68 'enwiki' => array( 'en.example.org', 'enwiki' ),
69 'ruwiki' => array( 'ru.example.org', 'ruwiki' ),
70 'enwiktionary (sites)' => array( 'en.wiktionary.org', 'enwiktionary' ),
74 /**
75 * @dataProvider provideGetWikiName
77 public function testGetWikiName( $expected, $wikiId ) {
78 $this->assertEquals( $expected, WikiMap::getWikiName( $wikiId ) );
81 public function provideMakeForeignLink() {
82 return array(
83 'unknown' => array( false, 'xyzzy', 'Foo' ),
84 'enwiki' => array(
85 '<a class="external" rel="nofollow" ' .
86 'href="http://en.example.org/w/Foo">Foo</a>',
87 'enwiki',
88 'Foo'
90 'ruwiki' => array(
91 '<a class="external" rel="nofollow" ' .
92 'href="//ru.example.org/wiki/%D0%A4%D1%83">вар</a>',
93 'ruwiki',
94 'Фу',
95 'вар'
97 'enwiktionary (sites)' => array(
98 '<a class="external" rel="nofollow" ' .
99 'href="https://en.wiktionary.org/wiki/Kitten">Kittens!</a>',
100 'enwiktionary',
101 'Kitten',
102 'Kittens!'
108 * @dataProvider provideMakeForeignLink
110 public function testMakeForeignLink( $expected, $wikiId, $page, $text = null ) {
111 $this->assertEquals(
112 $expected,
113 WikiMap::makeForeignLink( $wikiId, $page, $text )
117 public function provideForeignUserLink() {
118 return array(
119 'unknown' => array( false, 'xyzzy', 'Foo' ),
120 'enwiki' => array(
121 '<a class="external" rel="nofollow" ' .
122 'href="http://en.example.org/w/User:Foo">User:Foo</a>',
123 'enwiki',
124 'Foo'
126 'ruwiki' => array(
127 '<a class="external" rel="nofollow" ' .
128 'href="//ru.example.org/wiki/User:%D0%A4%D1%83">вар</a>',
129 'ruwiki',
130 'Фу',
131 'вар'
133 'enwiktionary (sites)' => array(
134 '<a class="external" rel="nofollow" ' .
135 'href="https://en.wiktionary.org/wiki/User:Dummy">Whatever</a>',
136 'enwiktionary',
137 'Dummy',
138 'Whatever'
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() {
151 return array(
152 'unknown' => array( false, 'xyzzy', 'Foo' ),
153 'enwiki' => array( 'http://en.example.org/w/Foo', 'enwiki', 'Foo' ),
154 'enwiktionary (sites)' => array(
155 'https://en.wiktionary.org/wiki/Testme',
156 'enwiktionary',
157 'Testme'
159 'ruwiki with fragment' => array(
160 '//ru.example.org/wiki/%D0%A4%D1%83#%D0%B2%D0%B0%D1%80',
161 'ruwiki',
162 'Фу',
163 'вар'
169 * @dataProvider provideGetForeignURL
171 public function testGetForeignURL( $expected, $wikiId, $page, $fragment = null ) {
172 $this->assertEquals( $expected, WikiMap::getForeignURL( $wikiId, $page, $fragment ) );