MediaWiki REL1_31
MediaWikiSiteTest.php
Go to the documentation of this file.
1<?php
2
32
33 public function testNormalizePageTitle() {
34 $this->setMwGlobals( [
35 'wgCapitalLinks' => true,
36 ] );
37
38 $site = new MediaWikiSite();
39 $site->setGlobalId( 'enwiki' );
40
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 ' ) );
45 }
46
47 public function fileUrlProvider() {
48 return [
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/' ],
52 [
53 'https://en.wikipedia.org',
54 '/foo/page.php?name=$1',
55 'api.php',
56 'https://en.wikipedia.org/foo/page.php?name=api.php'
57 ],
58 [
59 'https://en.wikipedia.org',
60 '/w/$1',
61 '',
62 'https://en.wikipedia.org/w/'
63 ],
64 [
65 'https://en.wikipedia.org',
66 '/w/$1',
67 'foo/bar/api.php',
68 'https://en.wikipedia.org/w/foo/bar/api.php'
69 ],
70 ];
71 }
72
77 public function testGetFileUrl( $url, $filePath, $pathArgument, $expected ) {
78 $site = new MediaWikiSite();
79 $site->setFilePath( $url . $filePath );
80
81 $this->assertEquals( $expected, $site->getFileUrl( $pathArgument ) );
82 }
83
84 public static function provideGetPageUrl() {
85 return [
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' ],
94 ];
95 }
96
101 public function testGetPageUrl( $path, $page, $expected ) {
102 $site = new MediaWikiSite();
103 $site->setLinkPath( $path );
104
105 $this->assertContains( $path, $site->getPageUrl() );
106 $this->assertContains( $expected, $site->getPageUrl( $page ) );
107 }
108}
testGetPageUrl( $path, $page, $expected)
provideGetPageUrl MediaWikiSite::getPageUrl
testGetFileUrl( $url, $filePath, $pathArgument, $expected)
fileUrlProvider MediaWikiSite::getFileUrl
Class representing a MediaWiki site.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.