3 * @covers ::wfExpandUrl
5 class WfExpandUrlTest
extends MediaWikiTestCase
{
7 * @dataProvider provideExpandableUrls
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' )
17 $this->assertEquals( $fullUrl, wfExpandUrl( $shortUrl, $defaultProto ), $message );
21 * Provider of URL examples for testing wfExpandUrl()
25 public static function provideExpandableUrls() {
26 $modes = array( 'http', 'https' );
28 'http' => 'http://example.com',
29 'https' => 'https://example.com',
30 'protocol-relative' => '//example.com'
32 $defaultProtos = array(
34 'https' => PROTO_HTTPS
,
35 'protocol-relative' => PROTO_RELATIVE
,
36 'current' => PROTO_CURRENT
,
37 'canonical' => PROTO_CANONICAL
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 ) {
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 )"
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 )"
59 # Would be nice to support this, see fixme on wfExpandUrl()
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 )"
67 // Determine expected protocol
68 if ( $protoDesc == 'protocol-relative' ) {
70 } elseif ( $protoDesc == 'current' ) {
72 } elseif ( $protoDesc == 'canonical' ) {
73 $p = "$canServerMode:";
75 $p = $protoDesc . ':';
77 // Determine expected server name
78 if ( $protoDesc == 'canonical' ) {
80 } elseif ( $serverDesc == 'protocol-relative' ) {
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 )"
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 )"