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