Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / interwiki / InterwikiTest.php
blob6ab1de4bcab74478604be0bff73b0086493577e1
1 <?php
3 use MediaWiki\MainConfigNames;
4 use Wikimedia\Rdbms\Platform\ISQLPlatform;
6 /**
7 * @covers \Interwiki
8 * @group Database
9 */
10 class InterwikiTest extends MediaWikiIntegrationTestCase {
12 public function testConstructor() {
13 $interwiki = new Interwiki(
14 'xyz',
15 'http://xyz.acme.test/wiki/$1',
16 'http://xyz.acme.test/w/api.php',
17 'xyzwiki',
22 $this->overrideConfigValue( MainConfigNames::LanguageCode, 'qqx' );
24 $this->assertSame( '(interwiki-name-xyz)', $interwiki->getName() );
25 $this->assertSame( '(interwiki-desc-xyz)', $interwiki->getDescription() );
26 $this->assertSame( 'http://xyz.acme.test/w/api.php', $interwiki->getAPI() );
27 $this->assertSame( 'http://xyz.acme.test/wiki/$1', $interwiki->getURL() );
28 $this->assertSame( 'xyzwiki', $interwiki->getWikiID() );
29 $this->assertTrue( $interwiki->isLocal() );
30 $this->assertFalse( $interwiki->isTranscludable() );
33 public function testGetUrl() {
34 $interwiki = new Interwiki(
35 'xyz',
36 'http://xyz.acme.test/wiki/$1'
39 $this->assertSame( 'http://xyz.acme.test/wiki/$1', $interwiki->getURL() );
40 $this->assertSame( 'http://xyz.acme.test/wiki/Foo%26Bar', $interwiki->getURL( 'Foo&Bar' ) );
43 //// tests for static data access methods below ///////////////////////////////////////////////
45 private function populateDB( $iwrows ) {
46 $dbw = $this->getDb();
47 $dbw->newDeleteQueryBuilder()
48 ->deleteFrom( 'interwiki' )
49 ->where( ISQLPlatform::ALL_ROWS )
50 ->caller( __METHOD__ )->execute();
51 $dbw->newInsertQueryBuilder()
52 ->insertInto( 'interwiki' )
53 ->rows( $iwrows )
54 ->caller( __METHOD__ )
55 ->execute();
58 public function testDatabaseStorage() {
59 // NOTE: database setup is expensive, so we only do
60 // it once and run all the tests in one go.
61 $dewiki = [
62 'iw_prefix' => 'de',
63 'iw_url' => 'http://de.wikipedia.org/wiki/',
64 'iw_api' => 'http://de.wikipedia.org/w/api.php',
65 'iw_wikiid' => 'dewiki',
66 'iw_local' => 1,
67 'iw_trans' => 0
70 $zzwiki = [
71 'iw_prefix' => 'zz',
72 'iw_url' => 'http://zzwiki.org/wiki/',
73 'iw_api' => 'http://zzwiki.org/w/api.php',
74 'iw_wikiid' => 'zzwiki',
75 'iw_local' => 0,
76 'iw_trans' => 0
79 $this->populateDB( [ $dewiki, $zzwiki ] );
81 $this->overrideConfigValue( MainConfigNames::InterwikiCache, false );
83 $interwikiLookup = $this->getServiceContainer()->getInterwikiLookup();
84 $this->assertEquals(
85 [ $dewiki, $zzwiki ],
86 $interwikiLookup->getAllPrefixes(),
87 'getAllPrefixes()'
89 $this->assertEquals(
90 [ $dewiki ],
91 $interwikiLookup->getAllPrefixes( true ),
92 'getAllPrefixes()'
94 $this->assertEquals(
95 [ $zzwiki ],
96 $interwikiLookup->getAllPrefixes( false ),
97 'getAllPrefixes()'
100 $this->assertTrue( $interwikiLookup->isValidInterwiki( 'de' ), 'known prefix is valid' );
101 $this->assertFalse( $interwikiLookup->isValidInterwiki( 'xyz' ), 'unknown prefix is valid' );
103 $this->assertNull( $interwikiLookup->fetch( null ), 'no prefix' );
104 $this->assertFalse( $interwikiLookup->fetch( 'xyz' ), 'unknown prefix' );
106 $interwiki = $interwikiLookup->fetch( 'de' );
107 $this->assertInstanceOf( Interwiki::class, $interwiki );
108 $this->assertSame( $interwiki, $interwikiLookup->fetch( 'de' ), 'in-process caching' );
110 $this->assertSame( 'http://de.wikipedia.org/wiki/', $interwiki->getURL(), 'getURL' );
111 $this->assertSame( 'http://de.wikipedia.org/w/api.php', $interwiki->getAPI(), 'getAPI' );
112 $this->assertSame( 'dewiki', $interwiki->getWikiID(), 'getWikiID' );
113 $this->assertSame( true, $interwiki->isLocal(), 'isLocal' );
114 $this->assertSame( false, $interwiki->isTranscludable(), 'isTranscludable' );
116 $interwikiLookup->invalidateCache( 'de' );
117 $this->assertNotSame( $interwiki, $interwikiLookup->fetch( 'de' ), 'invalidate cache' );