X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FWikiMapTest.php;h=12878b37ed26257021a8ce284897adc11d2ec13b;hb=b5875a1fbca83f32cb5a160685ab6474d5a552a7;hp=2092e0cf5d137c46e1ccdc42958f8f1f7eb54a62;hpb=8e655d8dd34c9b5b7857532753b4f1faa7d8571d;p=lhc%2Fweb%2Fwiklou.git
diff --git a/tests/phpunit/includes/WikiMapTest.php b/tests/phpunit/includes/WikiMapTest.php
index 2092e0cf5d..12878b37ed 100644
--- a/tests/phpunit/includes/WikiMapTest.php
+++ b/tests/phpunit/includes/WikiMapTest.php
@@ -2,54 +2,76 @@
/**
* @covers WikiMap
+ *
+ * @group Database
*/
-
class WikiMapTest extends MediaWikiLangTestCase {
public function setUp() {
parent::setUp();
$conf = new SiteConfiguration();
- $conf->settings = array(
- 'wgServer' => array(
+ $conf->settings = [
+ 'wgServer' => [
'enwiki' => 'http://en.example.org',
'ruwiki' => '//ru.example.org',
- ),
- 'wgArticlePath' => array(
+ 'nopathwiki' => '//nopath.example.org',
+ ],
+ 'wgArticlePath' => [
'enwiki' => '/w/$1',
'ruwiki' => '/wiki/$1',
- ),
- );
- $conf->suffixes = array( 'wiki' );
- $this->setMwGlobals( array(
+ ],
+ ];
+ $conf->suffixes = [ 'wiki' ];
+ $this->setMwGlobals( [
'wgConf' => $conf,
- ) );
+ ] );
+
+ TestSites::insertIntoDb();
}
public function provideGetWiki() {
+ // As provided by $wgConf
$enwiki = new WikiReference( 'http://en.example.org', '/w/$1' );
$ruwiki = new WikiReference( '//ru.example.org', '/wiki/$1' );
- return array(
- 'unknown' => array( false, 'xyzzy' ),
- 'enwiki' => array( $enwiki, 'enwiki' ),
- 'ruwiki' => array( $ruwiki, 'ruwiki' ),
- );
+ // Created from site objects
+ $nlwiki = new WikiReference( 'https://nl.wikipedia.org', '/wiki/$1' );
+ // enwiktionary doesn't have an interwiki id, thus this falls back to minor = lang code
+ $enwiktionary = new WikiReference( 'https://en.wiktionary.org', '/wiki/$1' );
+
+ return [
+ 'unknown' => [ null, 'xyzzy' ],
+ 'enwiki (wgConf)' => [ $enwiki, 'enwiki' ],
+ 'ruwiki (wgConf)' => [ $ruwiki, 'ruwiki' ],
+ 'nlwiki (sites)' => [ $nlwiki, 'nlwiki', false ],
+ 'enwiktionary (sites)' => [ $enwiktionary, 'enwiktionary', false ],
+ 'non MediaWiki site' => [ null, 'spam', false ],
+ 'boguswiki' => [ null, 'boguswiki' ],
+ 'nopathwiki' => [ null, 'nopathwiki' ],
+ ];
}
/**
* @dataProvider provideGetWiki
*/
- public function testGetWiki( $expected, $wikiId ) {
+ public function testGetWiki( $expected, $wikiId, $useWgConf = true ) {
+ if ( !$useWgConf ) {
+ $this->setMwGlobals( [
+ 'wgConf' => new SiteConfiguration(),
+ ] );
+ }
+
$this->assertEquals( $expected, WikiMap::getWiki( $wikiId ) );
}
public function provideGetWikiName() {
- return array(
- 'unknown' => array( 'xyzzy', 'xyzzy' ),
- 'enwiki' => array( 'en.example.org', 'enwiki' ),
- 'ruwiki' => array( 'ru.example.org', 'ruwiki' ),
- );
+ return [
+ 'unknown' => [ 'xyzzy', 'xyzzy' ],
+ 'enwiki' => [ 'en.example.org', 'enwiki' ],
+ 'ruwiki' => [ 'ru.example.org', 'ruwiki' ],
+ 'enwiktionary (sites)' => [ 'en.wiktionary.org', 'enwiktionary' ],
+ ];
}
/**
@@ -60,22 +82,29 @@ class WikiMapTest extends MediaWikiLangTestCase {
}
public function provideMakeForeignLink() {
- return array(
- 'unknown' => array( false, 'xyzzy', 'Foo' ),
- 'enwiki' => array(
+ return [
+ 'unknown' => [ false, 'xyzzy', 'Foo' ],
+ 'enwiki' => [
'Foo',
'enwiki',
'Foo'
- ),
- 'ruwiki' => array(
+ ],
+ 'ruwiki' => [
'ваÑ',
'ruwiki',
'ФÑ',
'ваÑ'
- ),
- );
+ ],
+ 'enwiktionary (sites)' => [
+ 'Kittens!',
+ 'enwiktionary',
+ 'Kitten',
+ 'Kittens!'
+ ],
+ ];
}
/**
@@ -89,22 +118,29 @@ class WikiMapTest extends MediaWikiLangTestCase {
}
public function provideForeignUserLink() {
- return array(
- 'unknown' => array( false, 'xyzzy', 'Foo' ),
- 'enwiki' => array(
+ return [
+ 'unknown' => [ false, 'xyzzy', 'Foo' ],
+ 'enwiki' => [
'User:Foo',
'enwiki',
'Foo'
- ),
- 'ruwiki' => array(
+ ],
+ 'ruwiki' => [
'ваÑ',
'ruwiki',
'ФÑ',
'ваÑ'
- ),
- );
+ ],
+ 'enwiktionary (sites)' => [
+ 'Whatever',
+ 'enwiktionary',
+ 'Dummy',
+ 'Whatever'
+ ],
+ ];
}
/**
@@ -115,16 +151,21 @@ class WikiMapTest extends MediaWikiLangTestCase {
}
public function provideGetForeignURL() {
- return array(
- 'unknown' => array( false, 'xyzzy', 'Foo' ),
- 'enwiki' => array( 'http://en.example.org/w/Foo', 'enwiki', 'Foo' ),
- 'ruwiki with fragement' => array(
+ return [
+ 'unknown' => [ false, 'xyzzy', 'Foo' ],
+ 'enwiki' => [ 'http://en.example.org/w/Foo', 'enwiki', 'Foo' ],
+ 'enwiktionary (sites)' => [
+ 'https://en.wiktionary.org/wiki/Testme',
+ 'enwiktionary',
+ 'Testme'
+ ],
+ 'ruwiki with fragment' => [
'//ru.example.org/wiki/%D0%A4%D1%83#%D0%B2%D0%B0%D1%80',
'ruwiki',
'ФÑ',
'ваÑ'
- ),
- );
+ ],
+ ];
}
/**