MediaWiki REL1_33
MediaWikiSiteTest.php
Go to the documentation of this file.
1<?php
2
30
34 public function testNormalizePageTitle() {
35 $this->setMwGlobals( [
36 'wgCapitalLinks' => true,
37 ] );
38
39 $site = new MediaWikiSite();
40 $site->setGlobalId( 'enwiki' );
41
42 // NOTE: this does not actually call out to the enwiki site to perform the normalization,
43 // but uses a local Title object to do so. This is hardcoded on SiteLink::normalizePageTitle
44 // for the case that MW_PHPUNIT_TEST is set.
45 $this->assertEquals( 'Foo', $site->normalizePageName( ' foo ' ) );
46 }
47
48 public function fileUrlProvider() {
49 return [
50 // url, filepath, path arg, expected
51 [ 'https://en.wikipedia.org', '/w/$1', 'api.php', 'https://en.wikipedia.org/w/api.php' ],
52 [ 'https://en.wikipedia.org', '/w/', 'api.php', 'https://en.wikipedia.org/w/' ],
53 [
54 'https://en.wikipedia.org',
55 '/foo/page.php?name=$1',
56 'api.php',
57 'https://en.wikipedia.org/foo/page.php?name=api.php'
58 ],
59 [
60 'https://en.wikipedia.org',
61 '/w/$1',
62 '',
63 'https://en.wikipedia.org/w/'
64 ],
65 [
66 'https://en.wikipedia.org',
67 '/w/$1',
68 'foo/bar/api.php',
69 'https://en.wikipedia.org/w/foo/bar/api.php'
70 ],
71 ];
72 }
73
78 public function testGetFileUrl( $url, $filePath, $pathArgument, $expected ) {
79 $site = new MediaWikiSite();
80 $site->setFilePath( $url . $filePath );
81
82 $this->assertEquals( $expected, $site->getFileUrl( $pathArgument ) );
83 }
84
85 public static function provideGetPageUrl() {
86 return [
87 // path, page, expected substring
88 [ 'http://acme.test/wiki/$1', 'Berlin', '/wiki/Berlin' ],
89 [ 'http://acme.test/wiki/', 'Berlin', '/wiki/' ],
90 [ 'http://acme.test/w/index.php?title=$1', 'Berlin', '/w/index.php?title=Berlin' ],
91 [ 'http://acme.test/wiki/$1', '', '/wiki/' ],
92 [ 'http://acme.test/wiki/$1', 'Berlin/sub page', '/wiki/Berlin/sub_page' ],
93 [ 'http://acme.test/wiki/$1', 'Cork (city) ', '/Cork_(city)' ],
94 [ 'http://acme.test/wiki/$1', 'M&M', '/wiki/M%26M' ],
95 ];
96 }
97
102 public function testGetPageUrl( $path, $page, $expected ) {
103 $site = new MediaWikiSite();
104 $site->setLinkPath( $path );
105
106 $this->assertContains( $path, $site->getPageUrl() );
107 $this->assertContains( $expected, $site->getPageUrl( $page ) );
108 }
109}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
testNormalizePageTitle()
MediaWikiSite::normalizePageName.
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.