Merge "Cache page content language in Title object"
[lhc/web/wiklou.git] / tests / phpunit / includes / GlobalFunctions / wfAssembleUrlTest.php
1 <?php
2 /**
3 * @covers ::wfAssembleUrl
4 */
5 class WfAssembleUrlTest extends MediaWikiTestCase {
6 /**
7 * @dataProvider provideURLParts
8 */
9 public function testWfAssembleUrl( $parts, $output ) {
10 $partsDump = print_r( $parts, true );
11 $this->assertEquals(
12 $output,
13 wfAssembleUrl( $parts ),
14 "Testing $partsDump assembles to $output"
15 );
16 }
17
18 /**
19 * Provider of URL parts for testing wfAssembleUrl()
20 *
21 * @return array
22 */
23 public static function provideURLParts() {
24 $schemes = array(
25 '' => array(),
26 '//' => array(
27 'delimiter' => '//',
28 ),
29 'http://' => array(
30 'scheme' => 'http',
31 'delimiter' => '://',
32 ),
33 );
34
35 $hosts = array(
36 '' => array(),
37 'example.com' => array(
38 'host' => 'example.com',
39 ),
40 'example.com:123' => array(
41 'host' => 'example.com',
42 'port' => 123,
43 ),
44 'id@example.com' => array(
45 'user' => 'id',
46 'host' => 'example.com',
47 ),
48 'id@example.com:123' => array(
49 'user' => 'id',
50 'host' => 'example.com',
51 'port' => 123,
52 ),
53 'id:key@example.com' => array(
54 'user' => 'id',
55 'pass' => 'key',
56 'host' => 'example.com',
57 ),
58 'id:key@example.com:123' => array(
59 'user' => 'id',
60 'pass' => 'key',
61 'host' => 'example.com',
62 'port' => 123,
63 ),
64 );
65
66 $cases = array();
67 foreach ( $schemes as $scheme => $schemeParts ) {
68 foreach ( $hosts as $host => $hostParts ) {
69 foreach ( array( '', '/path' ) as $path ) {
70 foreach ( array( '', 'query' ) as $query ) {
71 foreach ( array( '', 'fragment' ) as $fragment ) {
72 $parts = array_merge(
73 $schemeParts,
74 $hostParts
75 );
76 $url = $scheme .
77 $host .
78 $path;
79
80 if ( $path ) {
81 $parts['path'] = $path;
82 }
83 if ( $query ) {
84 $parts['query'] = $query;
85 $url .= '?' . $query;
86 }
87 if ( $fragment ) {
88 $parts['fragment'] = $fragment;
89 $url .= '#' . $fragment;
90 }
91
92 $cases[] = array(
93 $parts,
94 $url,
95 );
96 }
97 }
98 }
99 }
100 }
101
102 $complexURL = 'http://id:key@example.org:321' .
103 '/over/there?name=ferret&foo=bar#nose';
104 $cases[] = array(
105 wfParseUrl( $complexURL ),
106 $complexURL,
107 );
108
109 return $cases;
110 }
111 }