4 * Tests for the MediaWikiSite class.
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.
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.
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
29 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
31 class MediaWikiSiteTest
extends SiteTest
{
33 public function testNormalizePageTitle() {
34 $this->setMwGlobals( [
35 'wgCapitalLinks' => true,
38 $site = new MediaWikiSite();
39 $site->setGlobalId( 'enwiki' );
41 // NOTE: this does not actually call out to the enwiki site to perform the normalization,
42 // but uses a local Title object to do so. This is hardcoded on SiteLink::normalizePageTitle
43 // for the case that MW_PHPUNIT_TEST is set.
44 $this->assertEquals( 'Foo', $site->normalizePageName( ' foo ' ) );
47 public function fileUrlProvider() {
49 // url, filepath, path arg, expected
50 [ 'https://en.wikipedia.org', '/w/$1', 'api.php', 'https://en.wikipedia.org/w/api.php' ],
51 [ 'https://en.wikipedia.org', '/w/', 'api.php', 'https://en.wikipedia.org/w/' ],
53 'https://en.wikipedia.org',
54 '/foo/page.php?name=$1',
56 'https://en.wikipedia.org/foo/page.php?name=api.php'
59 'https://en.wikipedia.org',
62 'https://en.wikipedia.org/w/'
65 'https://en.wikipedia.org',
68 'https://en.wikipedia.org/w/foo/bar/api.php'
74 * @dataProvider fileUrlProvider
75 * @covers MediaWikiSite::getFileUrl
77 public function testGetFileUrl( $url, $filePath, $pathArgument, $expected ) {
78 $site = new MediaWikiSite();
79 $site->setFilePath( $url . $filePath );
81 $this->assertEquals( $expected, $site->getFileUrl( $pathArgument ) );
84 public static function provideGetPageUrl() {
86 // path, page, expected substring
87 [ 'http://acme.test/wiki/$1', 'Berlin', '/wiki/Berlin' ],
88 [ 'http://acme.test/wiki/', 'Berlin', '/wiki/' ],
89 [ 'http://acme.test/w/index.php?title=$1', 'Berlin', '/w/index.php?title=Berlin' ],
90 [ 'http://acme.test/wiki/$1', '', '/wiki/' ],
91 [ 'http://acme.test/wiki/$1', 'Berlin/sub page', '/wiki/Berlin/sub_page' ],
92 [ 'http://acme.test/wiki/$1', 'Cork (city) ', '/Cork_(city)' ],
93 [ 'http://acme.test/wiki/$1', 'M&M', '/wiki/M%26M' ],
98 * @dataProvider provideGetPageUrl
99 * @covers MediaWikiSite::getPageUrl
101 public function testGetPageUrl( $path, $page, $expected ) {
102 $site = new MediaWikiSite();
103 $site->setLinkPath( $path );
105 $this->assertContains( $path, $site->getPageUrl() );
106 $this->assertContains( $expected, $site->getPageUrl( $page ) );