MediaWiki REL1_31
wfExpandUrlTest.php
Go to the documentation of this file.
1<?php
10 public function testWfExpandUrl( $fullUrl, $shortUrl, $defaultProto,
11 $server, $canServer, $httpsMode, $message
12 ) {
13 // Fake $wgServer, $wgCanonicalServer and $wgRequest->getProtocol()
14 $this->setMwGlobals( [
15 'wgServer' => $server,
16 'wgCanonicalServer' => $canServer,
17 'wgRequest' => new FauxRequest( [], false, null, $httpsMode ? 'https' : 'http' )
18 ] );
19
20 $this->assertEquals( $fullUrl, wfExpandUrl( $shortUrl, $defaultProto ), $message );
21 }
22
28 public static function provideExpandableUrls() {
29 $modes = [ 'http', 'https' ];
30 $servers = [
31 'http' => 'http://example.com',
32 'https' => 'https://example.com',
33 'protocol-relative' => '//example.com'
34 ];
35 $defaultProtos = [
36 'http' => PROTO_HTTP,
37 'https' => PROTO_HTTPS,
38 'protocol-relative' => PROTO_RELATIVE,
39 'current' => PROTO_CURRENT,
40 'canonical' => PROTO_CANONICAL
41 ];
42
43 $retval = [];
44 foreach ( $modes as $mode ) {
45 $httpsMode = $mode == 'https';
46 foreach ( $servers as $serverDesc => $server ) {
47 foreach ( $modes as $canServerMode ) {
48 $canServer = "$canServerMode://example2.com";
49 foreach ( $defaultProtos as $protoDesc => $defaultProto ) {
50 $retval[] = [
51 'http://example.com', 'http://example.com',
52 $defaultProto, $server, $canServer, $httpsMode,
53 "Testing fully qualified http URLs (no need to expand) "
54 . "(defaultProto: $protoDesc , wgServer: $server, "
55 . "wgCanonicalServer: $canServer, current request protocol: $mode )"
56 ];
57 $retval[] = [
58 'https://example.com', 'https://example.com',
59 $defaultProto, $server, $canServer, $httpsMode,
60 "Testing fully qualified https URLs (no need to expand) "
61 . "(defaultProto: $protoDesc , wgServer: $server, "
62 . "wgCanonicalServer: $canServer, current request protocol: $mode )"
63 ];
64 # Would be nice to support this, see fixme on wfExpandUrl()
65 $retval[] = [
66 "wiki/FooBar", 'wiki/FooBar',
67 $defaultProto, $server, $canServer, $httpsMode,
68 "Test non-expandable relative URLs (defaultProto: $protoDesc, "
69 . "wgServer: $server, wgCanonicalServer: $canServer, "
70 . "current request protocol: $mode )"
71 ];
72
73 // Determine expected protocol
74 if ( $protoDesc == 'protocol-relative' ) {
75 $p = '';
76 } elseif ( $protoDesc == 'current' ) {
77 $p = "$mode:";
78 } elseif ( $protoDesc == 'canonical' ) {
79 $p = "$canServerMode:";
80 } else {
81 $p = $protoDesc . ':';
82 }
83 // Determine expected server name
84 if ( $protoDesc == 'canonical' ) {
85 $srv = $canServer;
86 } elseif ( $serverDesc == 'protocol-relative' ) {
87 $srv = $p . $server;
88 } else {
89 $srv = $server;
90 }
91
92 $retval[] = [
93 "$p//wikipedia.org", '//wikipedia.org',
94 $defaultProto, $server, $canServer, $httpsMode,
95 "Test protocol-relative URL (defaultProto: $protoDesc, "
96 . "wgServer: $server, wgCanonicalServer: $canServer, "
97 . "current request protocol: $mode )"
98 ];
99 $retval[] = [
100 "$srv/wiki/FooBar",
101 '/wiki/FooBar',
102 $defaultProto,
103 $server,
104 $canServer,
105 $httpsMode,
106 "Testing expanding URL beginning with / (defaultProto: $protoDesc, "
107 . "wgServer: $server, wgCanonicalServer: $canServer, "
108 . "current request protocol: $mode )"
109 ];
110 }
111 }
112 }
113 }
114
115 return $retval;
116 }
117}
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
WebRequest clone which takes values from a provided array.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
GlobalFunctions wfExpandUrl.
testWfExpandUrl( $fullUrl, $shortUrl, $defaultProto, $server, $canServer, $httpsMode, $message)
provideExpandableUrls
static provideExpandableUrls()
Provider of URL examples for testing wfExpandUrl()
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 local account incomplete not yet checked for validity & $retval
Definition hooks.txt:266
const PROTO_CANONICAL
Definition Defines.php:233
const PROTO_HTTPS
Definition Defines.php:230
const PROTO_CURRENT
Definition Defines.php:232
const PROTO_HTTP
Definition Defines.php:229
const PROTO_RELATIVE
Definition Defines.php:231