3 * Tests for wfExpandUrl()
5 class WfExpandUrlTest
extends MediaWikiTestCase
{
6 /** @dataProvider provideExpandableUrls */
7 public function testWfExpandUrl( $fullUrl, $shortUrl, $defaultProto, $server, $canServer, $httpsMode, $message ) {
8 // Fake $wgServer and $wgCanonicalServer
9 $this->setMwGlobals( array(
10 'wgServer' => $server,
11 'wgCanonicalServer' => $canServer,
14 // Fake $_SERVER['HTTPS'] if needed
16 $_SERVER['HTTPS'] = 'on';
18 unset( $_SERVER['HTTPS'] );
21 $this->assertEquals( $fullUrl, wfExpandUrl( $shortUrl, $defaultProto ), $message );
25 * Provider of URL examples for testing wfExpandUrl()
29 public static function provideExpandableUrls() {
30 $modes = array( 'http', 'https' );
32 'http' => 'http://example.com',
33 'https' => 'https://example.com',
34 'protocol-relative' => '//example.com'
36 $defaultProtos = array(
38 'https' => PROTO_HTTPS
,
39 'protocol-relative' => PROTO_RELATIVE
,
40 'current' => PROTO_CURRENT
,
41 'canonical' => PROTO_CANONICAL
45 foreach ( $modes as $mode ) {
46 $httpsMode = $mode == 'https';
47 foreach ( $servers as $serverDesc => $server ) {
48 foreach ( $modes as $canServerMode ) {
49 $canServer = "$canServerMode://example2.com";
50 foreach ( $defaultProtos as $protoDesc => $defaultProto ) {
52 'http://example.com', 'http://example.com',
53 $defaultProto, $server, $canServer, $httpsMode,
54 "Testing fully qualified http URLs (no need to expand) ' .
55 '(defaultProto: $protoDesc , wgServer: $server, wgCanonicalServer: $canServer, current request protocol: $mode )"
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, wgCanonicalServer: $canServer, current request protocol: $mode )"
63 # Would be nice to support this, see fixme on wfExpandUrl()
65 "wiki/FooBar", 'wiki/FooBar',
66 $defaultProto, $server, $canServer, $httpsMode,
67 "Test non-expandable relative URLs ' .
68 '(defaultProto: $protoDesc , wgServer: $server, wgCanonicalServer: $canServer, current request protocol: $mode )"
71 // Determine expected protocol
72 if ( $protoDesc == 'protocol-relative' ) {
74 } elseif ( $protoDesc == 'current' ) {
76 } elseif ( $protoDesc == 'canonical' ) {
77 $p = "$canServerMode:";
79 $p = $protoDesc . ':';
81 // Determine expected server name
82 if ( $protoDesc == 'canonical' ) {
84 } elseif ( $serverDesc == 'protocol-relative' ) {
91 "$p//wikipedia.org", '//wikipedia.org',
92 $defaultProto, $server, $canServer, $httpsMode,
93 "Test protocol-relative URL ' .
94 '(defaultProto: $protoDesc, wgServer: $server, wgCanonicalServer: $canServer, current request protocol: $mode )"
97 "$srv/wiki/FooBar", '/wiki/FooBar',
98 $defaultProto, $server, $canServer, $httpsMode,
99 "Testing expanding URL beginning with / ' .
100 '(defaultProto: $protoDesc , wgServer: $server, wgCanonicalServer: $canServer, current request protocol: $mode )"