MediaWiki  1.28.0
WikiMapTest.php
Go to the documentation of this file.
1 <?php
2 
9 
10  public function setUp() {
11  parent::setUp();
12 
13  $conf = new SiteConfiguration();
14  $conf->settings = [
15  'wgServer' => [
16  'enwiki' => 'http://en.example.org',
17  'ruwiki' => '//ru.example.org',
18  'nopathwiki' => '//nopath.example.org',
19  ],
20  'wgArticlePath' => [
21  'enwiki' => '/w/$1',
22  'ruwiki' => '/wiki/$1',
23  ],
24  ];
25  $conf->suffixes = [ 'wiki' ];
26  $this->setMwGlobals( [
27  'wgConf' => $conf,
28  ] );
29 
31  }
32 
33  public function provideGetWiki() {
34  // As provided by $wgConf
35  $enwiki = new WikiReference( 'http://en.example.org', '/w/$1' );
36  $ruwiki = new WikiReference( '//ru.example.org', '/wiki/$1' );
37 
38  // Created from site objects
39  $nlwiki = new WikiReference( 'https://nl.wikipedia.org', '/wiki/$1' );
40  // enwiktionary doesn't have an interwiki id, thus this falls back to minor = lang code
41  $enwiktionary = new WikiReference( 'https://en.wiktionary.org', '/wiki/$1' );
42 
43  return [
44  'unknown' => [ null, 'xyzzy' ],
45  'enwiki (wgConf)' => [ $enwiki, 'enwiki' ],
46  'ruwiki (wgConf)' => [ $ruwiki, 'ruwiki' ],
47  'nlwiki (sites)' => [ $nlwiki, 'nlwiki', false ],
48  'enwiktionary (sites)' => [ $enwiktionary, 'enwiktionary', false ],
49  'non MediaWiki site' => [ null, 'spam', false ],
50  'boguswiki' => [ null, 'boguswiki' ],
51  'nopathwiki' => [ null, 'nopathwiki' ],
52  ];
53  }
54 
58  public function testGetWiki( $expected, $wikiId, $useWgConf = true ) {
59  if ( !$useWgConf ) {
60  $this->setMwGlobals( [
61  'wgConf' => new SiteConfiguration(),
62  ] );
63  }
64 
65  $this->assertEquals( $expected, WikiMap::getWiki( $wikiId ) );
66  }
67 
68  public function provideGetWikiName() {
69  return [
70  'unknown' => [ 'xyzzy', 'xyzzy' ],
71  'enwiki' => [ 'en.example.org', 'enwiki' ],
72  'ruwiki' => [ 'ru.example.org', 'ruwiki' ],
73  'enwiktionary (sites)' => [ 'en.wiktionary.org', 'enwiktionary' ],
74  ];
75  }
76 
80  public function testGetWikiName( $expected, $wikiId ) {
81  $this->assertEquals( $expected, WikiMap::getWikiName( $wikiId ) );
82  }
83 
84  public function provideMakeForeignLink() {
85  return [
86  'unknown' => [ false, 'xyzzy', 'Foo' ],
87  'enwiki' => [
88  '<a class="external" rel="nofollow" ' .
89  'href="http://en.example.org/w/Foo">Foo</a>',
90  'enwiki',
91  'Foo'
92  ],
93  'ruwiki' => [
94  '<a class="external" rel="nofollow" ' .
95  'href="//ru.example.org/wiki/%D0%A4%D1%83">вар</a>',
96  'ruwiki',
97  'Фу',
98  'вар'
99  ],
100  'enwiktionary (sites)' => [
101  '<a class="external" rel="nofollow" ' .
102  'href="https://en.wiktionary.org/wiki/Kitten">Kittens!</a>',
103  'enwiktionary',
104  'Kitten',
105  'Kittens!'
106  ],
107  ];
108  }
109 
113  public function testMakeForeignLink( $expected, $wikiId, $page, $text = null ) {
114  $this->assertEquals(
115  $expected,
116  WikiMap::makeForeignLink( $wikiId, $page, $text )
117  );
118  }
119 
120  public function provideForeignUserLink() {
121  return [
122  'unknown' => [ false, 'xyzzy', 'Foo' ],
123  'enwiki' => [
124  '<a class="external" rel="nofollow" ' .
125  'href="http://en.example.org/w/User:Foo">User:Foo</a>',
126  'enwiki',
127  'Foo'
128  ],
129  'ruwiki' => [
130  '<a class="external" rel="nofollow" ' .
131  'href="//ru.example.org/wiki/User:%D0%A4%D1%83">вар</a>',
132  'ruwiki',
133  'Фу',
134  'вар'
135  ],
136  'enwiktionary (sites)' => [
137  '<a class="external" rel="nofollow" ' .
138  'href="https://en.wiktionary.org/wiki/User:Dummy">Whatever</a>',
139  'enwiktionary',
140  'Dummy',
141  'Whatever'
142  ],
143  ];
144  }
145 
149  public function testForeignUserLink( $expected, $wikiId, $user, $text = null ) {
150  $this->assertEquals( $expected, WikiMap::foreignUserLink( $wikiId, $user, $text ) );
151  }
152 
153  public function provideGetForeignURL() {
154  return [
155  'unknown' => [ false, 'xyzzy', 'Foo' ],
156  'enwiki' => [ 'http://en.example.org/w/Foo', 'enwiki', 'Foo' ],
157  'enwiktionary (sites)' => [
158  'https://en.wiktionary.org/wiki/Testme',
159  'enwiktionary',
160  'Testme'
161  ],
162  'ruwiki with fragment' => [
163  '//ru.example.org/wiki/%D0%A4%D1%83#%D0%B2%D0%B0%D1%80',
164  'ruwiki',
165  'Фу',
166  'вар'
167  ],
168  ];
169  }
170 
174  public function testGetForeignURL( $expected, $wikiId, $page, $fragment = null ) {
175  $this->assertEquals( $expected, WikiMap::getForeignURL( $wikiId, $page, $fragment ) );
176  }
177 
178 }
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
static foreignUserLink($wikiID, $user, $text=null)
Convenience to get a link to a user page on a foreign wiki.
Definition: WikiMap.php:134
provideGetForeignURL()
static getWikiName($wikiID)
Convenience to get the wiki's display name.
Definition: WikiMap.php:117
static getForeignURL($wikiID, $page, $fragmentId=null)
Convenience to get a url to a page on a foreign wiki.
Definition: WikiMap.php:168
Reference to a locally-hosted wiki.
Definition: WikiMap.php:182
testMakeForeignLink($expected, $wikiId, $page, $text=null)
provideMakeForeignLink
Base class that store and restore the Language objects.
provideGetWikiName()
Definition: WikiMapTest.php:68
provideForeignUserLink()
static makeForeignLink($wikiID, $page, $text=null)
Convenience to get a link to a page on a foreign wiki.
Definition: WikiMap.php:146
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition: hooks.txt:242
testGetWiki($expected, $wikiId, $useWgConf=true)
provideGetWiki
Definition: WikiMapTest.php:58
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
testGetForeignURL($expected, $wikiId, $page, $fragment=null)
provideGetForeignURL
testForeignUserLink($expected, $wikiId, $user, $text=null)
provideForeignUserLink
WikiMap.
Definition: WikiMapTest.php:8
provideMakeForeignLink()
Definition: WikiMapTest.php:84
testGetWikiName($expected, $wikiId)
provideGetWikiName
Definition: WikiMapTest.php:80
static getWiki($wikiID)
Get a WikiReference object for $wikiID.
Definition: WikiMap.php:34
This is a class for holding configuration settings, particularly for multi-wiki sites.
setMwGlobals($pairs, $value=null)
static insertIntoDb()
Inserts sites into the database for the unit tests that need them.
Definition: TestSites.php:109
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
Definition: hooks.txt:2491