/**
* @covers WikiMap
+ *
+ * @group Database
*/
-
class WikiMapTest extends MediaWikiLangTestCase {
public function setUp() {
$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 ) );
}
'unknown' => array( 'xyzzy', 'xyzzy' ),
'enwiki' => array( 'en.example.org', 'enwiki' ),
'ruwiki' => array( 'ru.example.org', 'ruwiki' ),
+ 'enwiktionary (sites)' => array( 'en.wiktionary.org', 'enwiktionary' ),
);
}
'Фу',
'вар'
),
+ 'enwiktionary (sites)' => array(
+ '<a class="external" rel="nofollow" ' .
+ 'href="https://en.wiktionary.org/wiki/Kitten">Kittens!</a>',
+ 'enwiktionary',
+ 'Kitten',
+ 'Kittens!'
+ ),
);
}
'Фу',
'вар'
),
+ 'enwiktionary (sites)' => array(
+ '<a class="external" rel="nofollow" ' .
+ 'href="https://en.wiktionary.org/wiki/User:Dummy">Whatever</a>',
+ 'enwiktionary',
+ 'Dummy',
+ 'Whatever'
+ ),
);
}
return array(
'unknown' => array( false, 'xyzzy', 'Foo' ),
'enwiki' => array( 'http://en.example.org/w/Foo', 'enwiki', 'Foo' ),
- 'ruwiki with fragement' => array(
+ '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',
'Фу',