Add tests for WikiMap and 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( 'wiki', 'en', 'http://en.example.org', '/w/$1' );
31 $ruwiki = new WikiReference( 'wiki', 'ru', '//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( '<a class="external" rel="nofollow" href="http://en.example.org/w/Foo">Foo</a>', 'enwiki', 'Foo', ),
66 'ruwiki' => array( '<a class="external" rel="nofollow" href="//ru.example.org/wiki/%D0%A4%D1%83">вар</a>', 'ruwiki', 'Фу', 'вар' ),
67 );
68 }
69
70 /**
71 * @dataProvider provideMakeForeignLink
72 */
73 public function testMakeForeignLink( $expected, $wikiId, $page, $text = null ) {
74 $this->assertEquals( $expected, WikiMap::makeForeignLink( $wikiId, $page, $text ) );
75 }
76
77 public function provideForeignUserLink() {
78 return array(
79 'unknown' => array( false, 'xyzzy', 'Foo' ),
80 'enwiki' => array( '<a class="external" rel="nofollow" href="http://en.example.org/w/User:Foo">User:Foo</a>', 'enwiki', 'Foo', ),
81 'ruwiki' => array( '<a class="external" rel="nofollow" href="//ru.example.org/wiki/User:%D0%A4%D1%83">вар</a>', 'ruwiki', 'Фу', 'вар' ),
82 );
83 }
84
85 /**
86 * @dataProvider provideForeignUserLink
87 */
88 public function testForeignUserLink( $expected, $wikiId, $user, $text = null ) {
89 $this->assertEquals( $expected, WikiMap::foreignUserLink( $wikiId, $user, $text ) );
90 }
91
92 public function provideGetForeignURL() {
93 return array(
94 'unknown' => array( false, 'xyzzy', 'Foo' ),
95 'enwiki' => array( 'http://en.example.org/w/Foo', 'enwiki', 'Foo', ),
96 );
97 }
98
99 /**
100 * @dataProvider provideGetForeignURL
101 */
102 public function testGetForeignURL( $expected, $wikiId, $page, $fragment = null ) {
103 $this->assertEquals( $expected, WikiMap::getForeignURL( $wikiId, $page, $fragment ) );
104 }
105
106 }
107