Fix some language depending phpunit tests by using MediaWikiLangTestCase
[lhc/web/wiklou.git] / tests / phpunit / includes / WikiMapTest.php
index 9233416..e86559e 100644 (file)
@@ -2,8 +2,9 @@
 
 /**
  * @covers WikiMap
+ *
+ * @group Database
  */
-
 class WikiMapTest extends MediaWikiLangTestCase {
 
        public function setUp() {
@@ -24,23 +25,40 @@ class WikiMapTest extends MediaWikiLangTestCase {
                $this->setMwGlobals( array(
                        'wgConf' => $conf,
                ) );
+
+               TestSites::insertIntoDb();
        }
 
        public function provideGetWiki() {
-               $enwiki = new WikiReference( 'wiki', 'en', 'http://en.example.org', '/w/$1' );
-               $ruwiki = new WikiReference( 'wiki', 'ru', '//ru.example.org', '/wiki/$1' );
+               // As provided by $wgConf
+               $enwiki = new WikiReference( 'http://en.example.org', '/w/$1' );
+               $ruwiki = new WikiReference( '//ru.example.org', '/wiki/$1' );
+
+               // 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 array(
-                       'unknown' => array( false, 'xyzzy' ),
-                       'enwiki' => array( $enwiki, 'enwiki' ),
-                       'ruwiki' => array( $ruwiki, 'ruwiki' ),
+                       'unknown' => array( null, 'xyzzy' ),
+                       'enwiki (wgConf)' => array( $enwiki, 'enwiki' ),
+                       'ruwiki (wgConf)' => array( $ruwiki, 'ruwiki' ),
+                       'nlwiki (sites)' => array( $nlwiki, 'nlwiki', false ),
+                       'enwiktionary (sites)' => array( $enwiktionary, 'enwiktionary', false ),
+                       'non MediaWiki site' => array( null, 'spam', false ),
                );
        }
 
        /**
         * @dataProvider provideGetWiki
         */
-       public function testGetWiki( $expected, $wikiId ) {
+       public function testGetWiki( $expected, $wikiId, $useWgConf = true ) {
+               if ( !$useWgConf ) {
+                       $this->setMwGlobals( array(
+                               'wgConf' => new SiteConfiguration(),
+                       ) );
+               }
+
                $this->assertEquals( $expected, WikiMap::getWiki( $wikiId ) );
        }
 
@@ -49,6 +67,7 @@ class WikiMapTest extends MediaWikiLangTestCase {
                        'unknown' => array( 'xyzzy', 'xyzzy' ),
                        'enwiki' => array( 'en.example.org', 'enwiki' ),
                        'ruwiki' => array( 'ru.example.org', 'ruwiki' ),
+                       'enwiktionary (sites)' => array( 'en.wiktionary.org', 'enwiktionary' ),
                );
        }
 
@@ -62,8 +81,26 @@ class WikiMapTest extends MediaWikiLangTestCase {
        public function provideMakeForeignLink() {
                return array(
                        'unknown' => array( false, 'xyzzy', 'Foo' ),
-                       'enwiki' => array( '<a class="external" rel="nofollow" href="http://en.example.org/w/Foo">Foo</a>', 'enwiki', 'Foo',  ),
-                       'ruwiki' => array( '<a class="external" rel="nofollow" href="//ru.example.org/wiki/%D0%A4%D1%83">вар</a>', 'ruwiki', 'Фу', 'вар' ),
+                       'enwiki' => array(
+                               '<a class="external" rel="nofollow" ' .
+                                       'href="http://en.example.org/w/Foo">Foo</a>',
+                               'enwiki',
+                               'Foo'
+                       ),
+                       'ruwiki' => array(
+                               '<a class="external" rel="nofollow" ' .
+                                       'href="//ru.example.org/wiki/%D0%A4%D1%83">вар</a>',
+                               'ruwiki',
+                               'Фу',
+                               'вар'
+                       ),
+                       'enwiktionary (sites)' => array(
+                               '<a class="external" rel="nofollow" ' .
+                                       'href="https://en.wiktionary.org/wiki/Kitten">Kittens!</a>',
+                               'enwiktionary',
+                               'Kitten',
+                               'Kittens!'
+                       ),
                );
        }
 
@@ -71,14 +108,35 @@ class WikiMapTest extends MediaWikiLangTestCase {
         * @dataProvider provideMakeForeignLink
         */
        public function testMakeForeignLink( $expected, $wikiId, $page, $text = null ) {
-               $this->assertEquals( $expected, WikiMap::makeForeignLink( $wikiId, $page, $text ) );
+               $this->assertEquals(
+                       $expected,
+                       WikiMap::makeForeignLink( $wikiId, $page, $text )
+               );
        }
 
        public function provideForeignUserLink() {
                return array(
                        'unknown' => array( false, 'xyzzy', 'Foo' ),
-                       'enwiki' => array( '<a class="external" rel="nofollow" href="http://en.example.org/w/User:Foo">User:Foo</a>', 'enwiki', 'Foo',  ),
-                       'ruwiki' => array( '<a class="external" rel="nofollow" href="//ru.example.org/wiki/User:%D0%A4%D1%83">вар</a>', 'ruwiki', 'Фу', 'вар' ),
+                       'enwiki' => array(
+                               '<a class="external" rel="nofollow" ' .
+                                       'href="http://en.example.org/w/User:Foo">User:Foo</a>',
+                               'enwiki',
+                               'Foo'
+                       ),
+                       'ruwiki' => array(
+                               '<a class="external" rel="nofollow" ' .
+                                       'href="//ru.example.org/wiki/User:%D0%A4%D1%83">вар</a>',
+                               'ruwiki',
+                               'Фу',
+                               'вар'
+                       ),
+                       'enwiktionary (sites)' => array(
+                               '<a class="external" rel="nofollow" ' .
+                                       'href="https://en.wiktionary.org/wiki/User:Dummy">Whatever</a>',
+                               'enwiktionary',
+                               'Dummy',
+                               'Whatever'
+                       ),
                );
        }
 
@@ -92,8 +150,18 @@ 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( '//ru.example.org/wiki/%D0%A4%D1%83#%D0%B2%D0%B0%D1%80', 'ruwiki', 'Фу', 'вар' ),
+                       'enwiki' => array( 'http://en.example.org/w/Foo', 'enwiki', 'Foo' ),
+                       'enwiktionary (sites)' => array(
+                               'https://en.wiktionary.org/wiki/Testme',
+                               'enwiktionary',
+                               'Testme'
+                       ),
+                       'ruwiki with fragment' => array(
+                               '//ru.example.org/wiki/%D0%A4%D1%83#%D0%B2%D0%B0%D1%80',
+                               'ruwiki',
+                               'Фу',
+                               'вар'
+                       ),
                );
        }
 
@@ -105,4 +173,3 @@ class WikiMapTest extends MediaWikiLangTestCase {
        }
 
 }
-