Merge "Fix Language::parseFormattedNumber for lzh and zh-classical"
[lhc/web/wiklou.git] / tests / phpunit / includes / site / MediaWikiSiteTest.php
1 <?php
2
3 /**
4 * Tests for the MediaWikiSite class.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
20 *
21 * @file
22 * @since 1.21
23 *
24 * @ingroup Site
25 * @ingroup Test
26 *
27 * @group Site
28 *
29 * @licence GNU GPL v2+
30 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
31 */
32 class MediaWikiSiteTest extends SiteTest {
33
34 public function testNormalizePageTitle() {
35 $site = new MediaWikiSite();
36 $site->setGlobalId( 'enwiki' );
37
38 //NOTE: this does not actually call out to the enwiki site to perform the normalization,
39 // but uses a local Title object to do so. This is hardcoded on SiteLink::normalizePageTitle
40 // for the case that MW_PHPUNIT_TEST is set.
41 $this->assertEquals( 'Foo', $site->normalizePageName( ' foo ' ) );
42 }
43
44 public function fileUrlProvider() {
45 return array(
46 // url, filepath, path arg, expected
47 array( 'https://en.wikipedia.org', '/w/$1', 'api.php', 'https://en.wikipedia.org/w/api.php' ),
48 array( 'https://en.wikipedia.org', '/w/', 'api.php', 'https://en.wikipedia.org/w/' ),
49 array(
50 'https://en.wikipedia.org',
51 '/foo/page.php?name=$1',
52 'api.php',
53 'https://en.wikipedia.org/foo/page.php?name=api.php'
54 ),
55 array(
56 'https://en.wikipedia.org',
57 '/w/$1',
58 '',
59 'https://en.wikipedia.org/w/'
60 ),
61 array(
62 'https://en.wikipedia.org',
63 '/w/$1',
64 'foo/bar/api.php',
65 'https://en.wikipedia.org/w/foo/bar/api.php'
66 ),
67 );
68 }
69
70 /**
71 * @dataProvider fileUrlProvider
72 * @covers MediaWikiSite::getFileUrl
73 */
74 public function testGetFileUrl( $url, $filePath, $pathArgument, $expected ) {
75 $site = new MediaWikiSite();
76 $site->setFilePath( $url . $filePath );
77
78 $this->assertEquals( $expected, $site->getFileUrl( $pathArgument ) );
79 }
80
81 public static function provideGetPageUrl() {
82 return array(
83 // path, page, expected substring
84 array( 'http://acme.test/wiki/$1', 'Berlin', '/wiki/Berlin' ),
85 array( 'http://acme.test/wiki/', 'Berlin', '/wiki/' ),
86 array( 'http://acme.test/w/index.php?title=$1', 'Berlin', '/w/index.php?title=Berlin' ),
87 array( 'http://acme.test/wiki/$1', '', '/wiki/' ),
88 array( 'http://acme.test/wiki/$1', 'Berlin/sub page', '/wiki/Berlin/sub_page' ),
89 array( 'http://acme.test/wiki/$1', 'Cork (city) ', '/Cork_(city)' ),
90 array( 'http://acme.test/wiki/$1', 'M&M', '/wiki/M%26M' ),
91 );
92 }
93
94 /**
95 * @dataProvider provideGetPageUrl
96 * @covers MediaWikiSite::getPageUrl
97 */
98 public function testGetPageUrl( $path, $page, $expected ) {
99 $site = new MediaWikiSite();
100 $site->setLinkPath( $path );
101
102 $this->assertContains( $path, $site->getPageUrl() );
103 $this->assertContains( $expected, $site->getPageUrl( $page ) );
104 }
105 }