MediaWiki  1.23.8
wfExpandUrlTest.php
Go to the documentation of this file.
1 <?php
9  public function testWfExpandUrl( $fullUrl, $shortUrl, $defaultProto, $server, $canServer, $httpsMode, $message ) {
10  // Fake $wgServer, $wgCanonicalServer and $wgRequest->getProtocol()
11  $this->setMwGlobals( array(
12  'wgServer' => $server,
13  'wgCanonicalServer' => $canServer,
14  'wgRequest' => new FauxRequest( array(), false, null, $httpsMode ? 'https' : 'http' )
15  ) );
16 
17  $this->assertEquals( $fullUrl, wfExpandUrl( $shortUrl, $defaultProto ), $message );
18  }
19 
25  public static function provideExpandableUrls() {
26  $modes = array( 'http', 'https' );
27  $servers = array(
28  'http' => 'http://example.com',
29  'https' => 'https://example.com',
30  'protocol-relative' => '//example.com'
31  );
32  $defaultProtos = array(
33  'http' => PROTO_HTTP,
34  'https' => PROTO_HTTPS,
35  'protocol-relative' => PROTO_RELATIVE,
36  'current' => PROTO_CURRENT,
37  'canonical' => PROTO_CANONICAL
38  );
39 
40  $retval = array();
41  foreach ( $modes as $mode ) {
42  $httpsMode = $mode == 'https';
43  foreach ( $servers as $serverDesc => $server ) {
44  foreach ( $modes as $canServerMode ) {
45  $canServer = "$canServerMode://example2.com";
46  foreach ( $defaultProtos as $protoDesc => $defaultProto ) {
47  $retval[] = array(
48  'http://example.com', 'http://example.com',
49  $defaultProto, $server, $canServer, $httpsMode,
50  "Testing fully qualified http URLs (no need to expand) ' .
51  '(defaultProto: $protoDesc , wgServer: $server, wgCanonicalServer: $canServer, current request protocol: $mode )"
52  );
53  $retval[] = array(
54  'https://example.com', 'https://example.com',
55  $defaultProto, $server, $canServer, $httpsMode,
56  "Testing fully qualified https URLs (no need to expand) ' .
57  '(defaultProto: $protoDesc , wgServer: $server, wgCanonicalServer: $canServer, current request protocol: $mode )"
58  );
59  # Would be nice to support this, see fixme on wfExpandUrl()
60  $retval[] = array(
61  "wiki/FooBar", 'wiki/FooBar',
62  $defaultProto, $server, $canServer, $httpsMode,
63  "Test non-expandable relative URLs ' .
64  '(defaultProto: $protoDesc , wgServer: $server, wgCanonicalServer: $canServer, current request protocol: $mode )"
65  );
66 
67  // Determine expected protocol
68  if ( $protoDesc == 'protocol-relative' ) {
69  $p = '';
70  } elseif ( $protoDesc == 'current' ) {
71  $p = "$mode:";
72  } elseif ( $protoDesc == 'canonical' ) {
73  $p = "$canServerMode:";
74  } else {
75  $p = $protoDesc . ':';
76  }
77  // Determine expected server name
78  if ( $protoDesc == 'canonical' ) {
79  $srv = $canServer;
80  } elseif ( $serverDesc == 'protocol-relative' ) {
81  $srv = $p . $server;
82  } else {
83  $srv = $server;
84  }
85 
86  $retval[] = array(
87  "$p//wikipedia.org", '//wikipedia.org',
88  $defaultProto, $server, $canServer, $httpsMode,
89  "Test protocol-relative URL ' .
90  '(defaultProto: $protoDesc, wgServer: $server, wgCanonicalServer: $canServer, current request protocol: $mode )"
91  );
92  $retval[] = array(
93  "$srv/wiki/FooBar", '/wiki/FooBar',
94  $defaultProto, $server, $canServer, $httpsMode,
95  "Testing expanding URL beginning with / ' .
96  '(defaultProto: $protoDesc , wgServer: $server, wgCanonicalServer: $canServer, current request protocol: $mode )"
97  );
98  }
99  }
100  }
101  }
102 
103  return $retval;
104  }
105 }
WfExpandUrlTest\provideExpandableUrls
static provideExpandableUrls()
Provider of URL examples for testing wfExpandUrl()
Definition: wfExpandUrlTest.php:25
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: WebRequest.php:1275
PROTO_CANONICAL
const PROTO_CANONICAL
Definition: Defines.php:271
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
WfExpandUrlTest
@covers wfExpandUrl
Definition: wfExpandUrlTest.php:5
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:302
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
PROTO_CURRENT
const PROTO_CURRENT
Definition: Defines.php:270
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
PROTO_HTTPS
const PROTO_HTTPS
Definition: Defines.php:268
PROTO_HTTP
const PROTO_HTTP
Definition: Defines.php:267
PROTO_RELATIVE
const PROTO_RELATIVE
Definition: Defines.php:269
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
$retval
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account incomplete not yet checked for validity & $retval
Definition: hooks.txt:237
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:497
WfExpandUrlTest\testWfExpandUrl
testWfExpandUrl( $fullUrl, $shortUrl, $defaultProto, $server, $canServer, $httpsMode, $message)
@dataProvider provideExpandableUrls
Definition: wfExpandUrlTest.php:9