Add support for fragments to WikiMap
[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 provideGetHostname() {
10 return array(
11 'http' => array( 'foo.bar', 'http://foo.bar' ),
12 'https' => array( 'foo.bar', 'https://foo.bar' ),
13 );
14 }
15
16 /**
17 * @dataProvider provideGetHostname
18 */
19 public function testGetHostname( $expected, $canonicalServer ) {
20 $this->markTestSkipped( 'The implementation is patently broken.' );
21
22 $reference = new WikiReference( 'wiki', 'xx', $canonicalServer, '/wiki/$1' );
23 $this->assertEquals( $expected, $reference->getHostname() );
24 }
25
26 public function provideGetDisplayName() {
27 return array(
28 'http' => array( 'foo.bar', 'http://foo.bar' ),
29 'https' => array( 'foo.bar', 'http://foo.bar' ),
30
31 // apparently, this is the expected behavior
32 'invalid' => array( 'purple kittens/wiki/', 'purple kittens' ),
33 );
34 }
35
36 /**
37 * @dataProvider provideGetDisplayName
38 */
39 public function testGetDisplayName( $expected, $canonicalServer ) {
40 $reference = new WikiReference( 'wiki', 'xx', $canonicalServer, '/wiki/$1' );
41 $this->assertEquals( $expected, $reference->getDisplayName() );
42 }
43
44 public function testGetCanonicalServer() {
45 $reference = new WikiReference( 'wiki', 'xx', 'https://acme.com', '/wiki/$1', '//acme.com' );
46 $this->assertEquals( 'https://acme.com', $reference->getCanonicalServer() );
47 }
48
49 public function provideGetCanonicalUrl() {
50 return array(
51 'no fragement' => array( 'https://acme.com/wiki/Foo', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', null ),
52 'empty fragement' => array( 'https://acme.com/wiki/Foo', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', '' ),
53 'fragment' => array( 'https://acme.com/wiki/Foo#Bar', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', 'Bar' ),
54 'double fragment' => array( 'https://acme.com/wiki/Foo#Bar%23Xus', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', 'Bar#Xus' ),
55 'escaped fragement' => array( 'https://acme.com/wiki/Foo%23Bar', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo#Bar', null ),
56 'empty path' => array( 'https://acme.com/Foo', 'https://acme.com', '//acme.com', '/$1', 'Foo', null ),
57 );
58 }
59
60 /**
61 * @dataProvider provideGetCanonicalUrl
62 */
63 public function testGetCanonicalUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId ) {
64 $reference = new WikiReference( 'wiki', 'xx', $canonicalServer, $path, $server );
65 $this->assertEquals( $expected, $reference->getCanonicalUrl( $page, $fragmentId ) );
66 }
67
68 /**
69 * @dataProvider provideGetCanonicalUrl
70 */
71 public function testGetUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId ) {
72 $reference = new WikiReference( 'wiki', 'xx', $canonicalServer, $path, $server );
73 $this->assertEquals( $expected, $reference->getUrl( $page, $fragmentId ) );
74 }
75
76 public function provideGetFullUrl() {
77 return array(
78 'no fragement' => array( '//acme.com/wiki/Foo', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', null ),
79 'empty fragement' => array( '//acme.com/wiki/Foo', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', '' ),
80 'fragment' => array( '//acme.com/wiki/Foo#Bar', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', 'Bar' ),
81 'double fragment' => array( '//acme.com/wiki/Foo#Bar%23Xus', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', 'Bar#Xus' ),
82 'escaped fragement' => array( '//acme.com/wiki/Foo%23Bar', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo#Bar', null ),
83 'empty path' => array( '//acme.com/Foo', 'https://acme.com', '//acme.com', '/$1', 'Foo', null ),
84 );
85 }
86
87 /**
88 * @dataProvider provideGetFullUrl
89 */
90 public function testGetFullUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId ) {
91 $reference = new WikiReference( 'wiki', 'xx', $canonicalServer, $path, $server );
92 $this->assertEquals( $expected, $reference->getFullUrl( $page, $fragmentId ) );
93 }
94
95 }
96