Merge "Fix spelling of "fragment" in test descriptions"
[lhc/web/wiklou.git] / tests / phpunit / includes / WikiReferenceTest.php
1 <?php
2
3 /**
4 * @covers WikiReference
5 */
6
7 class WikiReferenceTest extends PHPUnit_Framework_TestCase {
8
9 public function provideGetDisplayName() {
10 return array(
11 'http' => array( 'foo.bar', 'http://foo.bar' ),
12 'https' => array( 'foo.bar', 'http://foo.bar' ),
13
14 // apparently, this is the expected behavior
15 'invalid' => array( 'purple kittens', 'purple kittens' ),
16 );
17 }
18
19 /**
20 * @dataProvider provideGetDisplayName
21 */
22 public function testGetDisplayName( $expected, $canonicalServer ) {
23 $reference = new WikiReference( $canonicalServer, '/wiki/$1' );
24 $this->assertEquals( $expected, $reference->getDisplayName() );
25 }
26
27 public function testGetCanonicalServer() {
28 $reference = new WikiReference( 'https://acme.com', '/wiki/$1', '//acme.com' );
29 $this->assertEquals( 'https://acme.com', $reference->getCanonicalServer() );
30 }
31
32 public function provideGetCanonicalUrl() {
33 return array(
34 'no fragment' => array(
35 'https://acme.com/wiki/Foo',
36 'https://acme.com',
37 '//acme.com',
38 '/wiki/$1',
39 'Foo',
40 null
41 ),
42 'empty fragment' => array(
43 'https://acme.com/wiki/Foo',
44 'https://acme.com',
45 '//acme.com',
46 '/wiki/$1',
47 'Foo',
48 ''
49 ),
50 'fragment' => array(
51 'https://acme.com/wiki/Foo#Bar',
52 'https://acme.com',
53 '//acme.com',
54 '/wiki/$1',
55 'Foo',
56 'Bar'
57 ),
58 'double fragment' => array(
59 'https://acme.com/wiki/Foo#Bar%23Xus',
60 'https://acme.com',
61 '//acme.com',
62 '/wiki/$1',
63 'Foo',
64 'Bar#Xus'
65 ),
66 'escaped fragment' => array(
67 'https://acme.com/wiki/Foo%23Bar',
68 'https://acme.com',
69 '//acme.com',
70 '/wiki/$1',
71 'Foo#Bar',
72 null
73 ),
74 'empty path' => array(
75 'https://acme.com/Foo',
76 'https://acme.com',
77 '//acme.com',
78 '/$1',
79 'Foo',
80 null
81 ),
82 );
83 }
84
85 /**
86 * @dataProvider provideGetCanonicalUrl
87 */
88 public function testGetCanonicalUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId ) {
89 $reference = new WikiReference( $canonicalServer, $path, $server );
90 $this->assertEquals( $expected, $reference->getCanonicalUrl( $page, $fragmentId ) );
91 }
92
93 /**
94 * @dataProvider provideGetCanonicalUrl
95 * @note getUrl is an alias for getCanonicalUrl
96 */
97 public function testGetUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId ) {
98 $reference = new WikiReference( $canonicalServer, $path, $server );
99 $this->assertEquals( $expected, $reference->getUrl( $page, $fragmentId ) );
100 }
101
102 public function provideGetFullUrl() {
103 return array(
104 'no fragment' => array(
105 '//acme.com/wiki/Foo',
106 'https://acme.com',
107 '//acme.com',
108 '/wiki/$1',
109 'Foo',
110 null
111 ),
112 'empty fragment' => array(
113 '//acme.com/wiki/Foo',
114 'https://acme.com',
115 '//acme.com',
116 '/wiki/$1',
117 'Foo',
118 ''
119 ),
120 'fragment' => array(
121 '//acme.com/wiki/Foo#Bar',
122 'https://acme.com',
123 '//acme.com',
124 '/wiki/$1',
125 'Foo',
126 'Bar'
127 ),
128 'double fragment' => array(
129 '//acme.com/wiki/Foo#Bar%23Xus',
130 'https://acme.com',
131 '//acme.com',
132 '/wiki/$1',
133 'Foo',
134 'Bar#Xus'
135 ),
136 'escaped fragment' => array(
137 '//acme.com/wiki/Foo%23Bar',
138 'https://acme.com',
139 '//acme.com',
140 '/wiki/$1',
141 'Foo#Bar',
142 null
143 ),
144 'empty path' => array(
145 '//acme.com/Foo',
146 'https://acme.com',
147 '//acme.com',
148 '/$1',
149 'Foo',
150 null
151 ),
152 );
153 }
154
155 /**
156 * @dataProvider provideGetFullUrl
157 */
158 public function testGetFullUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId ) {
159 $reference = new WikiReference( $canonicalServer, $path, $server );
160 $this->assertEquals( $expected, $reference->getFullUrl( $page, $fragmentId ) );
161 }
162
163 }