summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/WikiMapTest.php
blob: 9233416c74dce846afbac4cfcdaef51f5fde5c6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php

/**
 * @covers WikiMap
 */

class WikiMapTest extends MediaWikiLangTestCase {

	public function setUp() {
		parent::setUp();

		$conf = new SiteConfiguration();
		$conf->settings = array(
			'wgServer' => array(
				'enwiki' => 'http://en.example.org',
				'ruwiki' => '//ru.example.org',
			),
			'wgArticlePath' => array(
				'enwiki' => '/w/$1',
				'ruwiki' => '/wiki/$1',
			),
		);
		$conf->suffixes = array( 'wiki' );
		$this->setMwGlobals( array(
			'wgConf' => $conf,
		) );
	}

	public function provideGetWiki() {
		$enwiki = new WikiReference( 'wiki', 'en', 'http://en.example.org', '/w/$1' );
		$ruwiki = new WikiReference( 'wiki', 'ru', '//ru.example.org', '/wiki/$1' );

		return array(
			'unknown' => array( false, 'xyzzy' ),
			'enwiki' => array( $enwiki, 'enwiki' ),
			'ruwiki' => array( $ruwiki, 'ruwiki' ),
		);
	}

	/**
	 * @dataProvider provideGetWiki
	 */
	public function testGetWiki( $expected, $wikiId ) {
		$this->assertEquals( $expected, WikiMap::getWiki( $wikiId ) );
	}

	public function provideGetWikiName() {
		return array(
			'unknown' => array( 'xyzzy', 'xyzzy' ),
			'enwiki' => array( 'en.example.org', 'enwiki' ),
			'ruwiki' => array( 'ru.example.org', 'ruwiki' ),
		);
	}

	/**
	 * @dataProvider provideGetWikiName
	 */
	public function testGetWikiName( $expected, $wikiId ) {
		$this->assertEquals( $expected, WikiMap::getWikiName( $wikiId ) );
	}

	public function provideMakeForeignLink() {
		return array(
			'unknown' => array( false, 'xyzzy', 'Foo' ),
			'enwiki' => array( '<a class="external" rel="nofollow" href="http://en.example.org/w/Foo">Foo</a>', 'enwiki', 'Foo',  ),
			'ruwiki' => array( '<a class="external" rel="nofollow" href="//ru.example.org/wiki/%D0%A4%D1%83">вар</a>', 'ruwiki', 'Фу', 'вар' ),
		);
	}

	/**
	 * @dataProvider provideMakeForeignLink
	 */
	public function testMakeForeignLink( $expected, $wikiId, $page, $text = null ) {
		$this->assertEquals( $expected, WikiMap::makeForeignLink( $wikiId, $page, $text ) );
	}

	public function provideForeignUserLink() {
		return array(
			'unknown' => array( false, 'xyzzy', 'Foo' ),
			'enwiki' => array( '<a class="external" rel="nofollow" href="http://en.example.org/w/User:Foo">User:Foo</a>', 'enwiki', 'Foo',  ),
			'ruwiki' => array( '<a class="external" rel="nofollow" href="//ru.example.org/wiki/User:%D0%A4%D1%83">вар</a>', 'ruwiki', 'Фу', 'вар' ),
		);
	}

	/**
	 * @dataProvider provideForeignUserLink
	 */
	public function testForeignUserLink( $expected, $wikiId, $user, $text = null ) {
		$this->assertEquals( $expected, WikiMap::foreignUserLink( $wikiId, $user, $text ) );
	}

	public function provideGetForeignURL() {
		return array(
			'unknown' => array( false, 'xyzzy', 'Foo' ),
			'enwiki' => array( 'http://en.example.org/w/Foo', 'enwiki', 'Foo',  ),
			'ruwiki with fragement' => array( '//ru.example.org/wiki/%D0%A4%D1%83#%D0%B2%D0%B0%D1%80', 'ruwiki', 'Фу', 'вар' ),
		);
	}

	/**
	 * @dataProvider provideGetForeignURL
	 */
	public function testGetForeignURL( $expected, $wikiId, $page, $fragment = null ) {
		$this->assertEquals( $expected, WikiMap::getForeignURL( $wikiId, $page, $fragment ) );
	}

}