Import: Handle uploads with sha1 starting with 0 properly
[mediawiki.git] / tests / phpunit / includes / WikiReferenceTest.php
blobbcef403aba5d5ac542ed4a8a3353136c3d64ee94
1 <?php
3 /**
4 * @covers WikiReference
5 */
7 class WikiReferenceTest extends PHPUnit_Framework_TestCase {
9 public function provideGetDisplayName() {
10 return array(
11 'http' => array( 'foo.bar', 'http://foo.bar' ),
12 'https' => array( 'foo.bar', 'http://foo.bar' ),
14 // apparently, this is the expected behavior
15 'invalid' => array( 'purple kittens', 'purple kittens' ),
19 /**
20 * @dataProvider provideGetDisplayName
22 public function testGetDisplayName( $expected, $canonicalServer ) {
23 $reference = new WikiReference( $canonicalServer, '/wiki/$1' );
24 $this->assertEquals( $expected, $reference->getDisplayName() );
27 public function testGetCanonicalServer() {
28 $reference = new WikiReference( 'https://acme.com', '/wiki/$1', '//acme.com' );
29 $this->assertEquals( 'https://acme.com', $reference->getCanonicalServer() );
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
42 'empty fragment' => array(
43 'https://acme.com/wiki/Foo',
44 'https://acme.com',
45 '//acme.com',
46 '/wiki/$1',
47 'Foo',
50 'fragment' => array(
51 'https://acme.com/wiki/Foo#Bar',
52 'https://acme.com',
53 '//acme.com',
54 '/wiki/$1',
55 'Foo',
56 'Bar'
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'
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
74 'empty path' => array(
75 'https://acme.com/Foo',
76 'https://acme.com',
77 '//acme.com',
78 '/$1',
79 'Foo',
80 null
85 /**
86 * @dataProvider provideGetCanonicalUrl
88 public function testGetCanonicalUrl(
89 $expected, $canonicalServer, $server, $path, $page, $fragmentId
90 ) {
91 $reference = new WikiReference( $canonicalServer, $path, $server );
92 $this->assertEquals( $expected, $reference->getCanonicalUrl( $page, $fragmentId ) );
95 /**
96 * @dataProvider provideGetCanonicalUrl
97 * @note getUrl is an alias for getCanonicalUrl
99 public function testGetUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId ) {
100 $reference = new WikiReference( $canonicalServer, $path, $server );
101 $this->assertEquals( $expected, $reference->getUrl( $page, $fragmentId ) );
104 public function provideGetFullUrl() {
105 return array(
106 'no fragment' => array(
107 '//acme.com/wiki/Foo',
108 'https://acme.com',
109 '//acme.com',
110 '/wiki/$1',
111 'Foo',
112 null
114 'empty fragment' => array(
115 '//acme.com/wiki/Foo',
116 'https://acme.com',
117 '//acme.com',
118 '/wiki/$1',
119 'Foo',
122 'fragment' => array(
123 '//acme.com/wiki/Foo#Bar',
124 'https://acme.com',
125 '//acme.com',
126 '/wiki/$1',
127 'Foo',
128 'Bar'
130 'double fragment' => array(
131 '//acme.com/wiki/Foo#Bar%23Xus',
132 'https://acme.com',
133 '//acme.com',
134 '/wiki/$1',
135 'Foo',
136 'Bar#Xus'
138 'escaped fragment' => array(
139 '//acme.com/wiki/Foo%23Bar',
140 'https://acme.com',
141 '//acme.com',
142 '/wiki/$1',
143 'Foo#Bar',
144 null
146 'empty path' => array(
147 '//acme.com/Foo',
148 'https://acme.com',
149 '//acme.com',
150 '/$1',
151 'Foo',
152 null
158 * @dataProvider provideGetFullUrl
160 public function testGetFullUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId ) {
161 $reference = new WikiReference( $canonicalServer, $path, $server );
162 $this->assertEquals( $expected, $reference->getFullUrl( $page, $fragmentId ) );