MediaWiki  1.27.2
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 }
const PROTO_CURRENT
Definition: Defines.php:264
wfExpandUrl($url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
GlobalFunctions wfExpandUrl.
const PROTO_HTTPS
Definition: Defines.php:262
testWfExpandUrl($fullUrl, $shortUrl, $defaultProto, $server, $canServer, $httpsMode, $message)
provideExpandableUrls
const PROTO_RELATIVE
Definition: Defines.php:263
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
const PROTO_HTTP
Definition: Defines.php:261
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
const PROTO_CANONICAL
Definition: Defines.php:265
static provideExpandableUrls()
Provider of URL examples for testing wfExpandUrl()
setMwGlobals($pairs, $value=null)
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:242