Merge "Adding a quotation marks message to core."
[lhc/web/wiklou.git] / tests / phpunit / includes / GlobalFunctions / wfExpandUrlTest.php
1 <?php
2 /**
3 * @covers ::wfExpandUrl
4 */
5 class WfExpandUrlTest extends MediaWikiTestCase {
6 /**
7 * @dataProvider provideExpandableUrls
8 */
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' )
15 ) );
16
17 $this->assertEquals( $fullUrl, wfExpandUrl( $shortUrl, $defaultProto ), $message );
18 }
19
20 /**
21 * Provider of URL examples for testing wfExpandUrl()
22 *
23 * @return array
24 */
25 public static function provideExpandableUrls() {
26 $modes = array( 'http', 'https' );
27 $servers = array(
28 'http' => 'http://example.com',
29 'https' => 'https://example.com',
30 'protocol-relative' => '//example.com'
31 );
32 $defaultProtos = array(
33 'http' => PROTO_HTTP,
34 'https' => PROTO_HTTPS,
35 'protocol-relative' => PROTO_RELATIVE,
36 'current' => PROTO_CURRENT,
37 'canonical' => PROTO_CANONICAL
38 );
39
40 $retval = array();
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 ) {
47 $retval[] = array(
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 )"
52 );
53 $retval[] = array(
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 )"
58 );
59 # Would be nice to support this, see fixme on wfExpandUrl()
60 $retval[] = array(
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 )"
65 );
66
67 // Determine expected protocol
68 if ( $protoDesc == 'protocol-relative' ) {
69 $p = '';
70 } elseif ( $protoDesc == 'current' ) {
71 $p = "$mode:";
72 } elseif ( $protoDesc == 'canonical' ) {
73 $p = "$canServerMode:";
74 } else {
75 $p = $protoDesc . ':';
76 }
77 // Determine expected server name
78 if ( $protoDesc == 'canonical' ) {
79 $srv = $canServer;
80 } elseif ( $serverDesc == 'protocol-relative' ) {
81 $srv = $p . $server;
82 } else {
83 $srv = $server;
84 }
85
86 $retval[] = array(
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 )"
91 );
92 $retval[] = array(
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 )"
97 );
98 }
99 }
100 }
101 }
102
103 return $retval;
104 }
105 }