4 * @covers WikiReference
6 class WikiReferenceTest
extends PHPUnit\Framework\TestCase
{
8 use MediaWikiCoversValidator
;
10 public function provideGetDisplayName() {
12 'http' => [ 'foo.bar', 'http://foo.bar' ],
13 'https' => [ 'foo.bar', 'http://foo.bar' ],
15 // apparently, this is the expected behavior
16 'invalid' => [ 'purple kittens', 'purple kittens' ],
21 * @dataProvider provideGetDisplayName
23 public function testGetDisplayName( $expected, $canonicalServer ) {
24 $reference = new WikiReference( $canonicalServer, '/wiki/$1' );
25 $this->assertEquals( $expected, $reference->getDisplayName() );
28 public function testGetCanonicalServer() {
29 $reference = new WikiReference( 'https://acme.com', '/wiki/$1', '//acme.com' );
30 $this->assertEquals( 'https://acme.com', $reference->getCanonicalServer() );
33 public function provideGetCanonicalUrl() {
36 'https://acme.com/wiki/Foo',
44 'https://acme.com/wiki/Foo',
52 'https://acme.com/wiki/Foo#Bar',
59 'double fragment' => [
60 'https://acme.com/wiki/Foo#Bar%23Xus',
67 'escaped fragment' => [
68 'https://acme.com/wiki/Foo%23Bar',
76 'https://acme.com/Foo',
87 * @dataProvider provideGetCanonicalUrl
89 public function testGetCanonicalUrl(
90 $expected, $canonicalServer, $server, $path, $page, $fragmentId
92 $reference = new WikiReference( $canonicalServer, $path, $server );
93 $this->assertEquals( $expected, $reference->getCanonicalUrl( $page, $fragmentId ) );
97 * @dataProvider provideGetCanonicalUrl
98 * @note getUrl is an alias for getCanonicalUrl
100 public function testGetUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId ) {
101 $reference = new WikiReference( $canonicalServer, $path, $server );
102 $this->assertEquals( $expected, $reference->getUrl( $page, $fragmentId ) );
105 public function provideGetFullUrl() {
108 '//acme.com/wiki/Foo',
115 'empty fragment' => [
116 '//acme.com/wiki/Foo',
124 '//acme.com/wiki/Foo#Bar',
131 'double fragment' => [
132 '//acme.com/wiki/Foo#Bar%23Xus',
139 'escaped fragment' => [
140 '//acme.com/wiki/Foo%23Bar',
159 * @dataProvider provideGetFullUrl
161 public function testGetFullUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId ) {
162 $reference = new WikiReference( $canonicalServer, $path, $server );
163 $this->assertEquals( $expected, $reference->getFullUrl( $page, $fragmentId ) );