MediaWiki  REL1_31
WikiReferenceTest.php
Go to the documentation of this file.
1 <?php
2 
6 class WikiReferenceTest extends PHPUnit\Framework\TestCase {
7 
8  use MediaWikiCoversValidator;
9 
10  public function provideGetDisplayName() {
11  return [
12  'http' => [ 'foo.bar', 'http://foo.bar' ],
13  'https' => [ 'foo.bar', 'http://foo.bar' ],
14 
15  // apparently, this is the expected behavior
16  'invalid' => [ 'purple kittens', 'purple kittens' ],
17  ];
18  }
19 
23  public function testGetDisplayName( $expected, $canonicalServer ) {
24  $reference = new WikiReference( $canonicalServer, '/wiki/$1' );
25  $this->assertEquals( $expected, $reference->getDisplayName() );
26  }
27 
28  public function testGetCanonicalServer() {
29  $reference = new WikiReference( 'https://acme.com', '/wiki/$1', '//acme.com' );
30  $this->assertEquals( 'https://acme.com', $reference->getCanonicalServer() );
31  }
32 
33  public function provideGetCanonicalUrl() {
34  return [
35  'no fragment' => [
36  'https://acme.com/wiki/Foo',
37  'https://acme.com',
38  '//acme.com',
39  '/wiki/$1',
40  'Foo',
41  null
42  ],
43  'empty fragment' => [
44  'https://acme.com/wiki/Foo',
45  'https://acme.com',
46  '//acme.com',
47  '/wiki/$1',
48  'Foo',
49  ''
50  ],
51  'fragment' => [
52  'https://acme.com/wiki/Foo#Bar',
53  'https://acme.com',
54  '//acme.com',
55  '/wiki/$1',
56  'Foo',
57  'Bar'
58  ],
59  'double fragment' => [
60  'https://acme.com/wiki/Foo#Bar%23Xus',
61  'https://acme.com',
62  '//acme.com',
63  '/wiki/$1',
64  'Foo',
65  'Bar#Xus'
66  ],
67  'escaped fragment' => [
68  'https://acme.com/wiki/Foo%23Bar',
69  'https://acme.com',
70  '//acme.com',
71  '/wiki/$1',
72  'Foo#Bar',
73  null
74  ],
75  'empty path' => [
76  'https://acme.com/Foo',
77  'https://acme.com',
78  '//acme.com',
79  '/$1',
80  'Foo',
81  null
82  ],
83  ];
84  }
85 
89  public function testGetCanonicalUrl(
90  $expected, $canonicalServer, $server, $path, $page, $fragmentId
91  ) {
92  $reference = new WikiReference( $canonicalServer, $path, $server );
93  $this->assertEquals( $expected, $reference->getCanonicalUrl( $page, $fragmentId ) );
94  }
95 
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 ) );
103  }
104 
105  public function provideGetFullUrl() {
106  return [
107  'no fragment' => [
108  '//acme.com/wiki/Foo',
109  'https://acme.com',
110  '//acme.com',
111  '/wiki/$1',
112  'Foo',
113  null
114  ],
115  'empty fragment' => [
116  '//acme.com/wiki/Foo',
117  'https://acme.com',
118  '//acme.com',
119  '/wiki/$1',
120  'Foo',
121  ''
122  ],
123  'fragment' => [
124  '//acme.com/wiki/Foo#Bar',
125  'https://acme.com',
126  '//acme.com',
127  '/wiki/$1',
128  'Foo',
129  'Bar'
130  ],
131  'double fragment' => [
132  '//acme.com/wiki/Foo#Bar%23Xus',
133  'https://acme.com',
134  '//acme.com',
135  '/wiki/$1',
136  'Foo',
137  'Bar#Xus'
138  ],
139  'escaped fragment' => [
140  '//acme.com/wiki/Foo%23Bar',
141  'https://acme.com',
142  '//acme.com',
143  '/wiki/$1',
144  'Foo#Bar',
145  null
146  ],
147  'empty path' => [
148  '//acme.com/Foo',
149  'https://acme.com',
150  '//acme.com',
151  '/$1',
152  'Foo',
153  null
154  ],
155  ];
156  }
157 
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 ) );
164  }
165 
166 }
WikiReferenceTest\provideGetCanonicalUrl
provideGetCanonicalUrl()
Definition: WikiReferenceTest.php:33
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
WikiReferenceTest\testGetFullUrl
testGetFullUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId)
provideGetFullUrl
Definition: WikiReferenceTest.php:161
WikiReferenceTest
WikiReference.
Definition: WikiReferenceTest.php:6
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
WikiReferenceTest\provideGetFullUrl
provideGetFullUrl()
Definition: WikiReferenceTest.php:105
WikiReferenceTest\testGetDisplayName
testGetDisplayName( $expected, $canonicalServer)
provideGetDisplayName
Definition: WikiReferenceTest.php:23
WikiReferenceTest\testGetCanonicalUrl
testGetCanonicalUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId)
provideGetCanonicalUrl
Definition: WikiReferenceTest.php:89
WikiReference
Reference to a locally-hosted wiki.
Definition: WikiReference.php:26
$path
$path
Definition: NoLocalSettings.php:25
WikiReferenceTest\testGetUrl
testGetUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId)
provideGetCanonicalUrl
Definition: WikiReferenceTest.php:100
WikiReferenceTest\provideGetDisplayName
provideGetDisplayName()
Definition: WikiReferenceTest.php:10
WikiReferenceTest\testGetCanonicalServer
testGetCanonicalServer()
Definition: WikiReferenceTest.php:28