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