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