4 * @covers WikiReference
7 class WikiReferenceTest
extends PHPUnit_Framework_TestCase
{
9 use MediaWikiCoversValidator
;
11 public function provideGetDisplayName() {
13 'http' => [ 'foo.bar', 'http://foo.bar' ],
14 'https' => [ 'foo.bar', 'http://foo.bar' ],
16 // apparently, this is the expected behavior
17 'invalid' => [ 'purple kittens', 'purple kittens' ],
22 * @dataProvider provideGetDisplayName
24 public function testGetDisplayName( $expected, $canonicalServer ) {
25 $reference = new WikiReference( $canonicalServer, '/wiki/$1' );
26 $this->assertEquals( $expected, $reference->getDisplayName() );
29 public function testGetCanonicalServer() {
30 $reference = new WikiReference( 'https://acme.com', '/wiki/$1', '//acme.com' );
31 $this->assertEquals( 'https://acme.com', $reference->getCanonicalServer() );
34 public function provideGetCanonicalUrl() {
37 'https://acme.com/wiki/Foo',
45 'https://acme.com/wiki/Foo',
53 'https://acme.com/wiki/Foo#Bar',
60 'double fragment' => [
61 'https://acme.com/wiki/Foo#Bar%23Xus',
68 'escaped fragment' => [
69 'https://acme.com/wiki/Foo%23Bar',
77 'https://acme.com/Foo',
88 * @dataProvider provideGetCanonicalUrl
90 public function testGetCanonicalUrl(
91 $expected, $canonicalServer, $server, $path, $page, $fragmentId
93 $reference = new WikiReference( $canonicalServer, $path, $server );
94 $this->assertEquals( $expected, $reference->getCanonicalUrl( $page, $fragmentId ) );
98 * @dataProvider provideGetCanonicalUrl
99 * @note getUrl is an alias for getCanonicalUrl
101 public function testGetUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId ) {
102 $reference = new WikiReference( $canonicalServer, $path, $server );
103 $this->assertEquals( $expected, $reference->getUrl( $page, $fragmentId ) );
106 public function provideGetFullUrl() {
109 '//acme.com/wiki/Foo',
116 'empty fragment' => [
117 '//acme.com/wiki/Foo',
125 '//acme.com/wiki/Foo#Bar',
132 'double fragment' => [
133 '//acme.com/wiki/Foo#Bar%23Xus',
140 'escaped fragment' => [
141 '//acme.com/wiki/Foo%23Bar',
160 * @dataProvider provideGetFullUrl
162 public function testGetFullUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId ) {
163 $reference = new WikiReference( $canonicalServer, $path, $server );
164 $this->assertEquals( $expected, $reference->getFullUrl( $page, $fragmentId ) );