Index: trunk/phase3/tests/phpunit/includes/GlobalFunctions/wfExpandUrl.php |
— | — | @@ -1,66 +0,0 @@ |
2 | | -<?php |
3 | | -/* |
4 | | - * Unit tests for wfExpandUrl() |
5 | | - */ |
6 | | - |
7 | | -class wfExpandUrl extends MediaWikiTestCase { |
8 | | - /** @dataProvider provideExpandableUrls */ |
9 | | - public function testWfExpandUrl( $fullUrl, $shortUrl, $defaultProto, $server, $httpsMode, $message ) { |
10 | | - // Fake $wgServer |
11 | | - global $wgServer; |
12 | | - $oldServer = $wgServer; |
13 | | - $wgServer = $server; |
14 | | - |
15 | | - // Fake $_SERVER['HTTPS'] if needed |
16 | | - if ( $httpsMode ) { |
17 | | - $_SERVER['HTTPS'] = 'on'; |
18 | | - } else { |
19 | | - unset( $_SERVER['HTTPS'] ); |
20 | | - } |
21 | | - |
22 | | - $this->assertEquals( $fullUrl, wfExpandUrl( $shortUrl, $defaultProto ), $message ); |
23 | | - |
24 | | - // Restore $wgServer |
25 | | - $wgServer = $oldServer; |
26 | | - } |
27 | | - |
28 | | - /** |
29 | | - * Provider of URL examples for testing wfExpandUrl() |
30 | | - * |
31 | | - * @return array |
32 | | - */ |
33 | | - public function provideExpandableUrls() { |
34 | | - $modes = array( 'http', 'https' ); |
35 | | - $servers = array( 'http' => 'http://example.com', 'https' => 'https://example.com', 'protocol-relative' => '//example.com' ); |
36 | | - $defaultProtos = array( 'http' => PROTO_HTTP, 'https' => PROTO_HTTPS, 'protocol-relative' => PROTO_RELATIVE, 'current' => PROTO_CURRENT ); |
37 | | - |
38 | | - $retval = array(); |
39 | | - foreach ( $modes as $mode ) { |
40 | | - $httpsMode = $mode == 'https'; |
41 | | - foreach ( $servers as $serverDesc => $server ) { |
42 | | - foreach ( $defaultProtos as $protoDesc => $defaultProto ) { |
43 | | - $retval[] = array( 'http://example.com', 'http://example.com', $defaultProto, $server, $httpsMode, "Testing fully qualified http URLs (no need to expand) (defaultProto: $protoDesc , wgServer: $server, current request protocol: $mode )" ); |
44 | | - $retval[] = array( 'https://example.com', 'https://example.com', $defaultProto, $server, $httpsMode, "Testing fully qualified https URLs (no need to expand) (defaultProto: $protoDesc , wgServer: $server, current request protocol: $mode )" ); |
45 | | - # Would be nice to support this, see fixme on wfExpandUrl() |
46 | | - $retval[] = array( "wiki/FooBar", 'wiki/FooBar', $defaultProto, $server, $httpsMode, "Test non-expandable relative URLs (defaultProto: $protoDesc , wgServer: $server, current request protocol: $mode )" ); |
47 | | - |
48 | | - // Determine expected protocol |
49 | | - $p = $protoDesc . ':'; // default case |
50 | | - if ( $protoDesc == 'protocol-relative' ) { |
51 | | - $p = ''; |
52 | | - } else if ( $protoDesc == 'current' ) { |
53 | | - $p = "$mode:"; |
54 | | - } else { |
55 | | - $p = $protoDesc . ':'; |
56 | | - } |
57 | | - // Determine expected server name |
58 | | - $srv = $serverDesc == 'protocol-relative' ? $p . $server : $server; |
59 | | - |
60 | | - $retval[] = array( "$p//wikipedia.org", '//wikipedia.org', $defaultProto, $server, $httpsMode, "Test protocol-relative URL (defaultProto: $protoDesc, wgServer: $server, current request protocol: $mode )" ); |
61 | | - $retval[] = array( "$srv/wiki/FooBar", '/wiki/FooBar', $defaultProto, $server, $httpsMode, "Testing expanding URL beginning with / (defaultProto: $protoDesc , wgServer: $server, current request protocol: $mode )" ); |
62 | | - } |
63 | | - } |
64 | | - } |
65 | | - return $retval; |
66 | | - } |
67 | | -} |
Index: trunk/phase3/tests/phpunit/includes/GlobalFunctions/wfExpandUrlTest.php |
— | — | @@ -0,0 +1,66 @@ |
| 2 | +<?php |
| 3 | +/* |
| 4 | + * Unit tests for wfExpandUrl() |
| 5 | + */ |
| 6 | + |
| 7 | +class wfExpandUrl extends MediaWikiTestCase { |
| 8 | + /** @dataProvider provideExpandableUrls */ |
| 9 | + public function testWfExpandUrl( $fullUrl, $shortUrl, $defaultProto, $server, $httpsMode, $message ) { |
| 10 | + // Fake $wgServer |
| 11 | + global $wgServer; |
| 12 | + $oldServer = $wgServer; |
| 13 | + $wgServer = $server; |
| 14 | + |
| 15 | + // Fake $_SERVER['HTTPS'] if needed |
| 16 | + if ( $httpsMode ) { |
| 17 | + $_SERVER['HTTPS'] = 'on'; |
| 18 | + } else { |
| 19 | + unset( $_SERVER['HTTPS'] ); |
| 20 | + } |
| 21 | + |
| 22 | + $this->assertEquals( $fullUrl, wfExpandUrl( $shortUrl, $defaultProto ), $message ); |
| 23 | + |
| 24 | + // Restore $wgServer |
| 25 | + $wgServer = $oldServer; |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Provider of URL examples for testing wfExpandUrl() |
| 30 | + * |
| 31 | + * @return array |
| 32 | + */ |
| 33 | + public function provideExpandableUrls() { |
| 34 | + $modes = array( 'http', 'https' ); |
| 35 | + $servers = array( 'http' => 'http://example.com', 'https' => 'https://example.com', 'protocol-relative' => '//example.com' ); |
| 36 | + $defaultProtos = array( 'http' => PROTO_HTTP, 'https' => PROTO_HTTPS, 'protocol-relative' => PROTO_RELATIVE, 'current' => PROTO_CURRENT ); |
| 37 | + |
| 38 | + $retval = array(); |
| 39 | + foreach ( $modes as $mode ) { |
| 40 | + $httpsMode = $mode == 'https'; |
| 41 | + foreach ( $servers as $serverDesc => $server ) { |
| 42 | + foreach ( $defaultProtos as $protoDesc => $defaultProto ) { |
| 43 | + $retval[] = array( 'http://example.com', 'http://example.com', $defaultProto, $server, $httpsMode, "Testing fully qualified http URLs (no need to expand) (defaultProto: $protoDesc , wgServer: $server, current request protocol: $mode )" ); |
| 44 | + $retval[] = array( 'https://example.com', 'https://example.com', $defaultProto, $server, $httpsMode, "Testing fully qualified https URLs (no need to expand) (defaultProto: $protoDesc , wgServer: $server, current request protocol: $mode )" ); |
| 45 | + # Would be nice to support this, see fixme on wfExpandUrl() |
| 46 | + $retval[] = array( "wiki/FooBar", 'wiki/FooBar', $defaultProto, $server, $httpsMode, "Test non-expandable relative URLs (defaultProto: $protoDesc , wgServer: $server, current request protocol: $mode )" ); |
| 47 | + |
| 48 | + // Determine expected protocol |
| 49 | + $p = $protoDesc . ':'; // default case |
| 50 | + if ( $protoDesc == 'protocol-relative' ) { |
| 51 | + $p = ''; |
| 52 | + } else if ( $protoDesc == 'current' ) { |
| 53 | + $p = "$mode:"; |
| 54 | + } else { |
| 55 | + $p = $protoDesc . ':'; |
| 56 | + } |
| 57 | + // Determine expected server name |
| 58 | + $srv = $serverDesc == 'protocol-relative' ? $p . $server : $server; |
| 59 | + |
| 60 | + $retval[] = array( "$p//wikipedia.org", '//wikipedia.org', $defaultProto, $server, $httpsMode, "Test protocol-relative URL (defaultProto: $protoDesc, wgServer: $server, current request protocol: $mode )" ); |
| 61 | + $retval[] = array( "$srv/wiki/FooBar", '/wiki/FooBar', $defaultProto, $server, $httpsMode, "Testing expanding URL beginning with / (defaultProto: $protoDesc , wgServer: $server, current request protocol: $mode )" ); |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + return $retval; |
| 66 | + } |
| 67 | +} |
Property changes on: trunk/phase3/tests/phpunit/includes/GlobalFunctions/wfExpandUrlTest.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 68 | + native |