Remove unused minor and major in WikiReference
[lhc/web/wiklou.git] / tests / phpunit / includes / WikiMapTest.php
1 <?php
2
3 /**
4 * @covers WikiMap
5 */
6
7 class WikiMapTest extends MediaWikiLangTestCase {
8
9 public function setUp() {
10 parent::setUp();
11
12 $conf = new SiteConfiguration();
13 $conf->settings = array(
14 'wgServer' => array(
15 'enwiki' => 'http://en.example.org',
16 'ruwiki' => '//ru.example.org',
17 ),
18 'wgArticlePath' => array(
19 'enwiki' => '/w/$1',
20 'ruwiki' => '/wiki/$1',
21 ),
22 );
23 $conf->suffixes = array( 'wiki' );
24 $this->setMwGlobals( array(
25 'wgConf' => $conf,
26 ) );
27 }
28
29 public function provideGetWiki() {
30 $enwiki = new WikiReference( 'http://en.example.org', '/w/$1' );
31 $ruwiki = new WikiReference( '//ru.example.org', '/wiki/$1' );
32
33 return array(
34 'unknown' => array( false, 'xyzzy' ),
35 'enwiki' => array( $enwiki, 'enwiki' ),
36 'ruwiki' => array( $ruwiki, 'ruwiki' ),
37 );
38 }
39
40 /**
41 * @dataProvider provideGetWiki
42 */
43 public function testGetWiki( $expected, $wikiId ) {
44 $this->assertEquals( $expected, WikiMap::getWiki( $wikiId ) );
45 }
46
47 public function provideGetWikiName() {
48 return array(
49 'unknown' => array( 'xyzzy', 'xyzzy' ),
50 'enwiki' => array( 'en.example.org', 'enwiki' ),
51 'ruwiki' => array( 'ru.example.org', 'ruwiki' ),
52 );
53 }
54
55 /**
56 * @dataProvider provideGetWikiName
57 */
58 public function testGetWikiName( $expected, $wikiId ) {
59 $this->assertEquals( $expected, WikiMap::getWikiName( $wikiId ) );
60 }
61
62 public function provideMakeForeignLink() {
63 return array(
64 'unknown' => array( false, 'xyzzy', 'Foo' ),
65 'enwiki' => array(
66 '<a class="external" rel="nofollow" ' .
67 'href="http://en.example.org/w/Foo">Foo</a>',
68 'enwiki',
69 'Foo'
70 ),
71 'ruwiki' => array(
72 '<a class="external" rel="nofollow" ' .
73 'href="//ru.example.org/wiki/%D0%A4%D1%83">вар</a>',
74 'ruwiki',
75 'Фу',
76 'вар'
77 ),
78 );
79 }
80
81 /**
82 * @dataProvider provideMakeForeignLink
83 */
84 public function testMakeForeignLink( $expected, $wikiId, $page, $text = null ) {
85 $this->assertEquals(
86 $expected,
87 WikiMap::makeForeignLink( $wikiId, $page, $text )
88 );
89 }
90
91 public function provideForeignUserLink() {
92 return array(
93 'unknown' => array( false, 'xyzzy', 'Foo' ),
94 'enwiki' => array(
95 '<a class="external" rel="nofollow" ' .
96 'href="http://en.example.org/w/User:Foo">User:Foo</a>',
97 'enwiki',
98 'Foo'
99 ),
100 'ruwiki' => array(
101 '<a class="external" rel="nofollow" ' .
102 'href="//ru.example.org/wiki/User:%D0%A4%D1%83">вар</a>',
103 'ruwiki',
104 'Фу',
105 'вар'
106 ),
107 );
108 }
109
110 /**
111 * @dataProvider provideForeignUserLink
112 */
113 public function testForeignUserLink( $expected, $wikiId, $user, $text = null ) {
114 $this->assertEquals( $expected, WikiMap::foreignUserLink( $wikiId, $user, $text ) );
115 }
116
117 public function provideGetForeignURL() {
118 return array(
119 'unknown' => array( false, 'xyzzy', 'Foo' ),
120 'enwiki' => array( 'http://en.example.org/w/Foo', 'enwiki', 'Foo' ),
121 'ruwiki with fragement' => array(
122 '//ru.example.org/wiki/%D0%A4%D1%83#%D0%B2%D0%B0%D1%80',
123 'ruwiki',
124 'Фу',
125 'вар'
126 ),
127 );
128 }
129
130 /**
131 * @dataProvider provideGetForeignURL
132 */
133 public function testGetForeignURL( $expected, $wikiId, $page, $fragment = null ) {
134 $this->assertEquals( $expected, WikiMap::getForeignURL( $wikiId, $page, $fragment ) );
135 }
136
137 }