Merge "SpecialMovepage: Convert form to use OOUI controls"
[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( 'wiki', 'xx', $canonicalServer, '/wiki/$1' );
24 $this->assertEquals( $expected, $reference->getDisplayName() );
25 }
26
27 public function testGetCanonicalServer() {
28 $reference = new WikiReference( 'wiki', 'xx', '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 fragement' => array( 'https://acme.com/wiki/Foo', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', null ),
35 'empty fragement' => array( 'https://acme.com/wiki/Foo', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', '' ),
36 'fragment' => array( 'https://acme.com/wiki/Foo#Bar', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', 'Bar' ),
37 'double fragment' => array( 'https://acme.com/wiki/Foo#Bar%23Xus', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', 'Bar#Xus' ),
38 'escaped fragement' => array( 'https://acme.com/wiki/Foo%23Bar', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo#Bar', null ),
39 'empty path' => array( 'https://acme.com/Foo', 'https://acme.com', '//acme.com', '/$1', 'Foo', null ),
40 );
41 }
42
43 /**
44 * @dataProvider provideGetCanonicalUrl
45 */
46 public function testGetCanonicalUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId ) {
47 $reference = new WikiReference( 'wiki', 'xx', $canonicalServer, $path, $server );
48 $this->assertEquals( $expected, $reference->getCanonicalUrl( $page, $fragmentId ) );
49 }
50
51 /**
52 * @dataProvider provideGetCanonicalUrl
53 * @note getUrl is an alias for getCanonicalUrl
54 */
55 public function testGetUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId ) {
56 $reference = new WikiReference( 'wiki', 'xx', $canonicalServer, $path, $server );
57 $this->assertEquals( $expected, $reference->getUrl( $page, $fragmentId ) );
58 }
59
60 public function provideGetFullUrl() {
61 return array(
62 'no fragement' => array( '//acme.com/wiki/Foo', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', null ),
63 'empty fragement' => array( '//acme.com/wiki/Foo', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', '' ),
64 'fragment' => array( '//acme.com/wiki/Foo#Bar', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', 'Bar' ),
65 'double fragment' => array( '//acme.com/wiki/Foo#Bar%23Xus', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', 'Bar#Xus' ),
66 'escaped fragement' => array( '//acme.com/wiki/Foo%23Bar', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo#Bar', null ),
67 'empty path' => array( '//acme.com/Foo', 'https://acme.com', '//acme.com', '/$1', 'Foo', null ),
68 );
69 }
70
71 /**
72 * @dataProvider provideGetFullUrl
73 */
74 public function testGetFullUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId ) {
75 $reference = new WikiReference( 'wiki', 'xx', $canonicalServer, $path, $server );
76 $this->assertEquals( $expected, $reference->getFullUrl( $page, $fragmentId ) );
77 }
78
79 }
80