(bug 41330) Default to the current year in the history page filter form
[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 * @group Database
29 *
30 * @licence GNU GPL v2+
31 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
32 */
33 class MediaWikiSiteTest extends SiteObjectTest {
34
35 public function setUp() {
36 parent::setUp();
37
38 static $hasSites = false;
39
40 if ( !$hasSites ) {
41 TestSites::insertIntoDb();
42 $hasSites = true;
43 }
44 }
45
46 public function testFactoryConstruction() {
47 $this->assertInstanceOf( 'MediaWikiSite', MediaWikiSite::newFromGlobalId( 'enwiki' ) );
48 $this->assertInstanceOf( 'Site', MediaWikiSite::newFromGlobalId( 'enwiki' ) );
49 $this->assertInstanceOf( 'MediaWikiSite', SitesTable::singleton()->newRow( array( 'type' => Site::TYPE_MEDIAWIKI ) ) );
50 }
51
52 public function testNormalizePageTitle() {
53 $site = MediaWikiSite::newFromGlobalId( 'enwiki' );
54
55 //NOTE: this does not actually call out to the enwiki site to perform the normalization,
56 // but uses a local Title object to do so. This is hardcoded on SiteLink::normalizePageTitle
57 // for the case that MW_PHPUNIT_TEST is set.
58 $this->assertEquals( 'Foo', $site->normalizePageName( ' foo ' ) );
59 }
60
61 public function fileUrlProvider() {
62 return array(
63 // url, filepath, path arg, expected
64 array( 'https://en.wikipedia.org', '/w/$1', 'api.php', 'https://en.wikipedia.org/w/api.php' ),
65 array( 'https://en.wikipedia.org', '/w/', 'api.php', 'https://en.wikipedia.org/w/' ),
66 array( 'https://en.wikipedia.org', '/foo/page.php?name=$1', 'api.php', 'https://en.wikipedia.org/foo/page.php?name=api.php' ),
67 array( 'https://en.wikipedia.org', '/w/$1', '', 'https://en.wikipedia.org/w/' ),
68 array( 'https://en.wikipedia.org', '/w/$1', 'foo/bar/api.php', 'https://en.wikipedia.org/w/foo/bar/api.php' ),
69 );
70 }
71
72 /**
73 * @dataProvider fileUrlProvider
74 */
75 public function testGetFileUrl( $url, $filePath, $pathArgument, $expected ) {
76 $site = MediaWikiSite::newFromGlobalId( 'enwiki' );
77
78 $site->setFilePath( $url . $filePath );
79
80 $this->assertEquals( $expected, $site->getFileUrl( $pathArgument ) );
81 }
82
83 public function provideGetPageUrl() {
84 return array(
85 // path, page, expected substring
86 array( 'http://acme.test/wiki/$1', 'Berlin', '/wiki/Berlin' ),
87 array( 'http://acme.test/wiki/', 'Berlin', '/wiki/' ),
88 array( 'http://acme.test/w/index.php?title=$1', 'Berlin', '/w/index.php?title=Berlin' ),
89 array( 'http://acme.test/wiki/$1', '', '/wiki/' ),
90 array( 'http://acme.test/wiki/$1', 'Berlin/sub page', '/wiki/Berlin/sub_page' ),
91 array( 'http://acme.test/wiki/$1', 'Cork (city) ', '/Cork_(city)' ),
92 array( 'http://acme.test/wiki/$1', 'M&M', '/wiki/M%26M' ),
93 );
94 }
95
96 /**
97 * @dataProvider provideGetPageUrl
98 */
99 public function testGetPageUrl( $path, $page, $expected ) {
100 /* @var MediaWikiSite $site */
101 $site = MediaWikiSite::newFromGlobalId( 'enwiki' );
102
103 $site->setLinkPath( $path );
104 $this->assertContains( $path, $site->getPageUrl() );
105 $this->assertContains( $expected, $site->getPageUrl( $page ) );
106 }
107
108 }