4 * @covers WikiReference
7 class WikiReferenceTest
extends PHPUnit_Framework_TestCase
{
9 public function provideGetDisplayName() {
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' ),
20 * @dataProvider provideGetDisplayName
22 public function testGetDisplayName( $expected, $canonicalServer ) {
23 $reference = new WikiReference( 'wiki', 'xx', $canonicalServer, '/wiki/$1' );
24 $this->assertEquals( $expected, $reference->getDisplayName() );
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() );
32 public function provideGetCanonicalUrl() {
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 ),
44 * @dataProvider provideGetCanonicalUrl
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 ) );
52 * @dataProvider provideGetCanonicalUrl
53 * @note getUrl is an alias for getCanonicalUrl
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 ) );
60 public function provideGetFullUrl() {
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 ),
72 * @dataProvider provideGetFullUrl
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 ) );