3 namespace MediaWiki\Tests\Site
;
5 use MediaWiki\MainConfigNames
;
6 use MediaWiki\Site\MediaWikiSite
;
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
32 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
34 class MediaWikiSiteTest
extends SiteTest
{
37 * @covers \MediaWiki\Site\MediaWikiSite::normalizePageName
39 public function testNormalizePageTitle() {
40 $this->overrideConfigValue( MainConfigNames
::CapitalLinks
, true );
42 $site = new MediaWikiSite();
43 $site->setGlobalId( 'enwiki' );
45 // NOTE: this does not actually call out to the enwiki site to perform the normalization,
46 // but uses a local Title object to do so. This is hardcoded on SiteLink::normalizePageTitle
47 // for the case that MW_PHPUNIT_TEST is set.
48 $this->assertEquals( 'Foo', $site->normalizePageName( ' foo ' ) );
51 public static function fileUrlProvider() {
53 // url, filepath, path arg, expected
54 [ 'https://en.wikipedia.org', '/w/$1', 'api.php', 'https://en.wikipedia.org/w/api.php' ],
55 [ 'https://en.wikipedia.org', '/w/', 'api.php', 'https://en.wikipedia.org/w/' ],
57 'https://en.wikipedia.org',
58 '/foo/page.php?name=$1',
60 'https://en.wikipedia.org/foo/page.php?name=api.php'
63 'https://en.wikipedia.org',
66 'https://en.wikipedia.org/w/'
69 'https://en.wikipedia.org',
72 'https://en.wikipedia.org/w/foo/bar/api.php'
78 * @dataProvider fileUrlProvider
79 * @covers \MediaWiki\Site\MediaWikiSite::getFileUrl
81 public function testGetFileUrl( $url, $filePath, $pathArgument, $expected ) {
82 $site = new MediaWikiSite();
83 $site->setFilePath( $url . $filePath );
85 $this->assertEquals( $expected, $site->getFileUrl( $pathArgument ) );
88 public static function provideGetPageUrl() {
90 // path, page, expected substring
91 [ 'http://acme.test/wiki/$1', 'Berlin', '/wiki/Berlin' ],
92 [ 'http://acme.test/wiki/', 'Berlin', '/wiki/' ],
93 [ 'http://acme.test/w/index.php?title=$1', 'Berlin', '/w/index.php?title=Berlin' ],
94 [ 'http://acme.test/wiki/$1', '', '/wiki/' ],
95 [ 'http://acme.test/wiki/$1', 'Berlin/subpage', '/wiki/Berlin/subpage' ],
96 [ 'http://acme.test/wiki/$1', 'Berlin/subpage with spaces', '/wiki/Berlin/subpage_with_spaces' ],
97 [ 'http://acme.test/wiki/$1', 'Cork (city) ', '/Cork_(city)' ],
98 [ 'http://acme.test/wiki/$1', 'M&M', '/wiki/M%26M' ],
103 * @dataProvider provideGetPageUrl
104 * @covers \MediaWiki\Site\MediaWikiSite::getPageUrl
106 public function testGetPageUrl( $path, $page, $expected ) {
107 $site = new MediaWikiSite();
108 $site->setLinkPath( $path );
110 $this->assertStringContainsString( $path, $site->getPageUrl() );
111 $this->assertStringContainsString( $expected, $site->getPageUrl( $page ) );