Fixed dependencies for jquery.collapsibleTabs
[lhc/web/wiklou.git] / tests / phpunit / includes / GlobalFunctions / wfExpandUrlTest.php
1 <?php
2 /**
3 * Unit tests for wfExpandUrl()
4 */
5
6 class wfExpandUrl extends MediaWikiTestCase {
7 /** @dataProvider provideExpandableUrls */
8 public function testWfExpandUrl( $fullUrl, $shortUrl, $defaultProto, $server, $canServer, $httpsMode, $message ) {
9 // Fake $wgServer and $wgCanonicalServer
10 global $wgServer, $wgCanonicalServer;
11 $oldServer = $wgServer;
12 $oldCanServer = $wgCanonicalServer;
13 $wgServer = $server;
14 $wgCanonicalServer = $canServer;
15
16 // Fake $_SERVER['HTTPS'] if needed
17 if ( $httpsMode ) {
18 $_SERVER['HTTPS'] = 'on';
19 } else {
20 unset( $_SERVER['HTTPS'] );
21 }
22
23 $this->assertEquals( $fullUrl, wfExpandUrl( $shortUrl, $defaultProto ), $message );
24
25 // Restore $wgServer and $wgCanonicalServer
26 $wgServer = $oldServer;
27 $wgCanonicalServer = $oldCanServer;
28 }
29
30 /**
31 * Provider of URL examples for testing wfExpandUrl()
32 *
33 * @return array
34 */
35 public function provideExpandableUrls() {
36 $modes = array( 'http', 'https' );
37 $servers = array(
38 'http' => 'http://example.com',
39 'https' => 'https://example.com',
40 'protocol-relative' => '//example.com'
41 );
42 $defaultProtos = array(
43 'http' => PROTO_HTTP,
44 'https' => PROTO_HTTPS,
45 'protocol-relative' => PROTO_RELATIVE,
46 'current' => PROTO_CURRENT,
47 'canonical' => PROTO_CANONICAL
48 );
49
50 $retval = array();
51 foreach ( $modes as $mode ) {
52 $httpsMode = $mode == 'https';
53 foreach ( $servers as $serverDesc => $server ) {
54 foreach ( $modes as $canServerMode ) {
55 $canServer = "$canServerMode://example2.com";
56 foreach ( $defaultProtos as $protoDesc => $defaultProto ) {
57 $retval[] = array(
58 'http://example.com', 'http://example.com',
59 $defaultProto, $server, $canServer, $httpsMode,
60 "Testing fully qualified http URLs (no need to expand) ' .
61 '(defaultProto: $protoDesc , wgServer: $server, wgCanonicalServer: $canServer, current request protocol: $mode )"
62 );
63 $retval[] = array(
64 'https://example.com', 'https://example.com',
65 $defaultProto, $server, $canServer, $httpsMode,
66 "Testing fully qualified https URLs (no need to expand) ' .
67 '(defaultProto: $protoDesc , wgServer: $server, wgCanonicalServer: $canServer, current request protocol: $mode )"
68 );
69 # Would be nice to support this, see fixme on wfExpandUrl()
70 $retval[] = array(
71 "wiki/FooBar", 'wiki/FooBar',
72 $defaultProto, $server, $canServer, $httpsMode,
73 "Test non-expandable relative URLs ' .
74 '(defaultProto: $protoDesc , wgServer: $server, wgCanonicalServer: $canServer, current request protocol: $mode )"
75 );
76
77 // Determine expected protocol
78 if ( $protoDesc == 'protocol-relative' ) {
79 $p = '';
80 } elseif ( $protoDesc == 'current' ) {
81 $p = "$mode:";
82 } elseif ( $protoDesc == 'canonical' ) {
83 $p = "$canServerMode:";
84 } else {
85 $p = $protoDesc . ':';
86 }
87 // Determine expected server name
88 if ( $protoDesc == 'canonical' ) {
89 $srv = $canServer;
90 } elseif ( $serverDesc == 'protocol-relative' ) {
91 $srv = $p . $server;
92 } else {
93 $srv = $server;
94 }
95
96 $retval[] = array(
97 "$p//wikipedia.org", '//wikipedia.org',
98 $defaultProto, $server, $canServer, $httpsMode,
99 "Test protocol-relative URL ' .
100 '(defaultProto: $protoDesc, wgServer: $server, wgCanonicalServer: $canServer, current request protocol: $mode )"
101 );
102 $retval[] = array(
103 "$srv/wiki/FooBar", '/wiki/FooBar',
104 $defaultProto, $server, $canServer, $httpsMode,
105 "Testing expanding URL beginning with / ' .
106 '(defaultProto: $protoDesc , wgServer: $server, wgCanonicalServer: $canServer, current request protocol: $mode )"
107 );
108 }
109 }
110 }
111 }
112 return $retval;
113 }
114 }