Merge "Bug 44855, Bug 37743: Improved vector button styles for jquery.ui"
[lhc/web/wiklou.git] / tests / phpunit / includes / GlobalFunctions / wfExpandUrlTest.php
1 <?php
2 /**
3 * Tests for wfExpandUrl()
4 */
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,
12 ) );
13
14 // Fake $_SERVER['HTTPS'] if needed
15 if ( $httpsMode ) {
16 $_SERVER['HTTPS'] = 'on';
17 } else {
18 unset( $_SERVER['HTTPS'] );
19 }
20
21 $this->assertEquals( $fullUrl, wfExpandUrl( $shortUrl, $defaultProto ), $message );
22 }
23
24 /**
25 * Provider of URL examples for testing wfExpandUrl()
26 *
27 * @return array
28 */
29 public static function provideExpandableUrls() {
30 $modes = array( 'http', 'https' );
31 $servers = array(
32 'http' => 'http://example.com',
33 'https' => 'https://example.com',
34 'protocol-relative' => '//example.com'
35 );
36 $defaultProtos = array(
37 'http' => PROTO_HTTP,
38 'https' => PROTO_HTTPS,
39 'protocol-relative' => PROTO_RELATIVE,
40 'current' => PROTO_CURRENT,
41 'canonical' => PROTO_CANONICAL
42 );
43
44 $retval = array();
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 ) {
51 $retval[] = array(
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 )"
56 );
57 $retval[] = array(
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 )"
62 );
63 # Would be nice to support this, see fixme on wfExpandUrl()
64 $retval[] = array(
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 )"
69 );
70
71 // Determine expected protocol
72 if ( $protoDesc == 'protocol-relative' ) {
73 $p = '';
74 } elseif ( $protoDesc == 'current' ) {
75 $p = "$mode:";
76 } elseif ( $protoDesc == 'canonical' ) {
77 $p = "$canServerMode:";
78 } else {
79 $p = $protoDesc . ':';
80 }
81 // Determine expected server name
82 if ( $protoDesc == 'canonical' ) {
83 $srv = $canServer;
84 } elseif ( $serverDesc == 'protocol-relative' ) {
85 $srv = $p . $server;
86 } else {
87 $srv = $server;
88 }
89
90 $retval[] = array(
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 )"
95 );
96 $retval[] = array(
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 )"
101 );
102 }
103 }
104 }
105 }
106
107 return $retval;
108 }
109 }