MediaWiki  1.30.0
WikiReferenceTest.php
Go to the documentation of this file.
1 <?php
2 
7 class WikiReferenceTest extends PHPUnit_Framework_TestCase {
8 
9  public function provideGetDisplayName() {
10  return [
11  'http' => [ 'foo.bar', 'http://foo.bar' ],
12  'https' => [ 'foo.bar', 'http://foo.bar' ],
13 
14  // apparently, this is the expected behavior
15  'invalid' => [ 'purple kittens', 'purple kittens' ],
16  ];
17  }
18 
22  public function testGetDisplayName( $expected, $canonicalServer ) {
23  $reference = new WikiReference( $canonicalServer, '/wiki/$1' );
24  $this->assertEquals( $expected, $reference->getDisplayName() );
25  }
26 
27  public function testGetCanonicalServer() {
28  $reference = new WikiReference( 'https://acme.com', '/wiki/$1', '//acme.com' );
29  $this->assertEquals( 'https://acme.com', $reference->getCanonicalServer() );
30  }
31 
32  public function provideGetCanonicalUrl() {
33  return [
34  'no fragment' => [
35  'https://acme.com/wiki/Foo',
36  'https://acme.com',
37  '//acme.com',
38  '/wiki/$1',
39  'Foo',
40  null
41  ],
42  'empty fragment' => [
43  'https://acme.com/wiki/Foo',
44  'https://acme.com',
45  '//acme.com',
46  '/wiki/$1',
47  'Foo',
48  ''
49  ],
50  'fragment' => [
51  'https://acme.com/wiki/Foo#Bar',
52  'https://acme.com',
53  '//acme.com',
54  '/wiki/$1',
55  'Foo',
56  'Bar'
57  ],
58  'double fragment' => [
59  'https://acme.com/wiki/Foo#Bar%23Xus',
60  'https://acme.com',
61  '//acme.com',
62  '/wiki/$1',
63  'Foo',
64  'Bar#Xus'
65  ],
66  'escaped fragment' => [
67  'https://acme.com/wiki/Foo%23Bar',
68  'https://acme.com',
69  '//acme.com',
70  '/wiki/$1',
71  'Foo#Bar',
72  null
73  ],
74  'empty path' => [
75  'https://acme.com/Foo',
76  'https://acme.com',
77  '//acme.com',
78  '/$1',
79  'Foo',
80  null
81  ],
82  ];
83  }
84 
88  public function testGetCanonicalUrl(
89  $expected, $canonicalServer, $server, $path, $page, $fragmentId
90  ) {
91  $reference = new WikiReference( $canonicalServer, $path, $server );
92  $this->assertEquals( $expected, $reference->getCanonicalUrl( $page, $fragmentId ) );
93  }
94 
99  public function testGetUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId ) {
100  $reference = new WikiReference( $canonicalServer, $path, $server );
101  $this->assertEquals( $expected, $reference->getUrl( $page, $fragmentId ) );
102  }
103 
104  public function provideGetFullUrl() {
105  return [
106  'no fragment' => [
107  '//acme.com/wiki/Foo',
108  'https://acme.com',
109  '//acme.com',
110  '/wiki/$1',
111  'Foo',
112  null
113  ],
114  'empty fragment' => [
115  '//acme.com/wiki/Foo',
116  'https://acme.com',
117  '//acme.com',
118  '/wiki/$1',
119  'Foo',
120  ''
121  ],
122  'fragment' => [
123  '//acme.com/wiki/Foo#Bar',
124  'https://acme.com',
125  '//acme.com',
126  '/wiki/$1',
127  'Foo',
128  'Bar'
129  ],
130  'double fragment' => [
131  '//acme.com/wiki/Foo#Bar%23Xus',
132  'https://acme.com',
133  '//acme.com',
134  '/wiki/$1',
135  'Foo',
136  'Bar#Xus'
137  ],
138  'escaped fragment' => [
139  '//acme.com/wiki/Foo%23Bar',
140  'https://acme.com',
141  '//acme.com',
142  '/wiki/$1',
143  'Foo#Bar',
144  null
145  ],
146  'empty path' => [
147  '//acme.com/Foo',
148  'https://acme.com',
149  '//acme.com',
150  '/$1',
151  'Foo',
152  null
153  ],
154  ];
155  }
156 
160  public function testGetFullUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId ) {
161  $reference = new WikiReference( $canonicalServer, $path, $server );
162  $this->assertEquals( $expected, $reference->getFullUrl( $page, $fragmentId ) );
163  }
164 
165 }
WikiReferenceTest\provideGetCanonicalUrl
provideGetCanonicalUrl()
Definition: WikiReferenceTest.php:32
WikiReferenceTest\testGetFullUrl
testGetFullUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId)
provideGetFullUrl
Definition: WikiReferenceTest.php:160
WikiReferenceTest
WikiReference.
Definition: WikiReferenceTest.php:7
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:35
WikiReferenceTest\provideGetFullUrl
provideGetFullUrl()
Definition: WikiReferenceTest.php:104
WikiReferenceTest\testGetDisplayName
testGetDisplayName( $expected, $canonicalServer)
provideGetDisplayName
Definition: WikiReferenceTest.php:22
WikiReferenceTest\testGetCanonicalUrl
testGetCanonicalUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId)
provideGetCanonicalUrl
Definition: WikiReferenceTest.php:88
WikiReference
Reference to a locally-hosted wiki.
Definition: WikiReference.php:26
$path
$path
Definition: NoLocalSettings.php:26
WikiReferenceTest\testGetUrl
testGetUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId)
provideGetCanonicalUrl
Definition: WikiReferenceTest.php:99
WikiReferenceTest\provideGetDisplayName
provideGetDisplayName()
Definition: WikiReferenceTest.php:9
WikiReferenceTest\testGetCanonicalServer
testGetCanonicalServer()
Definition: WikiReferenceTest.php:27