| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Site; |
| 4 |
|
| 5 |
use MediaWiki\MainConfigNames; |
| 6 |
use MediaWiki\Site\MediaWikiSite; |
| 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 |
class MediaWikiSiteTest extends SiteTest { |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public function testNormalizePageTitle() { |
| 40 |
$this->overrideConfigValue( MainConfigNames::CapitalLinks, true ); |
| 41 |
|
| 42 |
$site = new MediaWikiSite(); |
| 43 |
$site->setGlobalId( 'enwiki' ); |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
$this->assertEquals( 'Foo', $site->normalizePageName( ' foo ' ) ); |
| 49 |
} |
| 50 |
|
| 51 |
public static function fileUrlProvider() { |
| 52 |
return [ |
| 53 |
|
| 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/' ], |
| 56 |
[ |
| 57 |
'https://en.wikipedia.org', |
| 58 |
'/foo/page.php?name=$1', |
| 59 |
'api.php', |
| 60 |
'https://en.wikipedia.org/foo/page.php?name=api.php' |
| 61 |
], |
| 62 |
[ |
| 63 |
'https://en.wikipedia.org', |
| 64 |
'/w/$1', |
| 65 |
'', |
| 66 |
'https://en.wikipedia.org/w/' |
| 67 |
], |
| 68 |
[ |
| 69 |
'https://en.wikipedia.org', |
| 70 |
'/w/$1', |
| 71 |
'foo/bar/api.php', |
| 72 |
'https://en.wikipedia.org/w/foo/bar/api.php' |
| 73 |
], |
| 74 |
]; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public function testGetFileUrl( $url, $filePath, $pathArgument, $expected ) { |
| 82 |
$site = new MediaWikiSite(); |
| 83 |
$site->setFilePath( $url . $filePath ); |
| 84 |
|
| 85 |
$this->assertEquals( $expected, $site->getFileUrl( $pathArgument ) ); |
| 86 |
} |
| 87 |
|
| 88 |
public static function provideGetPageUrl() { |
| 89 |
return [ |
| 90 |
|
| 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' ], |
| 99 |
]; |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
public function testGetPageUrl( $path, $page, $expected ) { |
| 107 |
$site = new MediaWikiSite(); |
| 108 |
$site->setLinkPath( $path ); |
| 109 |
|
| 110 |
$this->assertStringContainsString( $path, $site->getPageUrl() ); |
| 111 |
$this->assertStringContainsString( $expected, $site->getPageUrl( $page ) ); |
| 112 |
} |
| 113 |
} |