2016-04-23 19:00:18 +00:00
|
|
|
<?php
|
2019-05-28 14:04:23 +00:00
|
|
|
|
2022-07-28 20:36:55 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2023-07-14 12:48:42 +00:00
|
|
|
use Wikimedia\Rdbms\Platform\ISQLPlatform;
|
2022-07-28 20:36:55 +00:00
|
|
|
|
2016-04-23 19:00:18 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Interwiki
|
|
|
|
|
* @group Database
|
|
|
|
|
*/
|
2020-06-30 15:09:24 +00:00
|
|
|
class InterwikiTest extends MediaWikiIntegrationTestCase {
|
2016-04-23 19:00:18 +00:00
|
|
|
|
|
|
|
|
public function testConstructor() {
|
|
|
|
|
$interwiki = new Interwiki(
|
|
|
|
|
'xyz',
|
|
|
|
|
'http://xyz.acme.test/wiki/$1',
|
|
|
|
|
'http://xyz.acme.test/w/api.php',
|
|
|
|
|
'xyzwiki',
|
|
|
|
|
1,
|
|
|
|
|
0
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->setContentLang( 'qqx' );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( '(interwiki-name-xyz)', $interwiki->getName() );
|
|
|
|
|
$this->assertSame( '(interwiki-desc-xyz)', $interwiki->getDescription() );
|
|
|
|
|
$this->assertSame( 'http://xyz.acme.test/w/api.php', $interwiki->getAPI() );
|
|
|
|
|
$this->assertSame( 'http://xyz.acme.test/wiki/$1', $interwiki->getURL() );
|
|
|
|
|
$this->assertSame( 'xyzwiki', $interwiki->getWikiID() );
|
|
|
|
|
$this->assertTrue( $interwiki->isLocal() );
|
|
|
|
|
$this->assertFalse( $interwiki->isTranscludable() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetUrl() {
|
|
|
|
|
$interwiki = new Interwiki(
|
|
|
|
|
'xyz',
|
|
|
|
|
'http://xyz.acme.test/wiki/$1'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertSame( 'http://xyz.acme.test/wiki/$1', $interwiki->getURL() );
|
|
|
|
|
$this->assertSame( 'http://xyz.acme.test/wiki/Foo%26Bar', $interwiki->getURL( 'Foo&Bar' ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//// tests for static data access methods below ///////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
private function populateDB( $iwrows ) {
|
2023-09-25 18:49:16 +00:00
|
|
|
$dbw = $this->getDb();
|
2023-07-14 12:48:42 +00:00
|
|
|
$dbw->newDeleteQueryBuilder()
|
In query builders, use insertInto() and deleteFrom() instead of insert() and delete()
The design principle for SelectQueryBuilder was to make the chained
builder calls look as much like SQL as possible, so that developers
could leverage their knowledge of SQL to understand what the query
builder is doing.
That's why SelectQueryBuilder::select() takes a list of fields, and by
the same principle, it makes sense for UpdateQueryBuilder::update() to
take a table. However with "insert" and "delete", the SQL designers
chose to add prepositions "into" and "from", and I think it makes sense
to follow that here.
In terms of natural language, we update a table, but we don't delete a
table, or insert a table. We delete rows from a table, or insert rows
into a table. The table is not the object of the verb.
So, add insertInto() as an alias for insert(), and add deleteFrom() as
an alias for delete(). Use the new methods in MW core callers where
PHPStorm knows the type.
Change-Id: Idb327a54a57a0fb2288ea067472c1e9727016000
2023-09-08 00:06:59 +00:00
|
|
|
->deleteFrom( 'interwiki' )
|
2023-07-14 12:48:42 +00:00
|
|
|
->where( ISQLPlatform::ALL_ROWS )
|
|
|
|
|
->caller( __METHOD__ )->execute();
|
2016-04-23 19:00:18 +00:00
|
|
|
$dbw->insert( 'interwiki', array_values( $iwrows ), __METHOD__ );
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-30 22:04:52 +00:00
|
|
|
private function setWgInterwikiCache( $interwikiCache ) {
|
2022-07-28 20:36:55 +00:00
|
|
|
$this->overrideConfigValue( MainConfigNames::InterwikiCache, $interwikiCache );
|
2015-10-30 22:04:52 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-23 19:00:18 +00:00
|
|
|
public function testDatabaseStorage() {
|
|
|
|
|
// NOTE: database setup is expensive, so we only do
|
|
|
|
|
// it once and run all the tests in one go.
|
|
|
|
|
$dewiki = [
|
|
|
|
|
'iw_prefix' => 'de',
|
|
|
|
|
'iw_url' => 'http://de.wikipedia.org/wiki/',
|
|
|
|
|
'iw_api' => 'http://de.wikipedia.org/w/api.php',
|
|
|
|
|
'iw_wikiid' => 'dewiki',
|
|
|
|
|
'iw_local' => 1,
|
|
|
|
|
'iw_trans' => 0
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$zzwiki = [
|
|
|
|
|
'iw_prefix' => 'zz',
|
|
|
|
|
'iw_url' => 'http://zzwiki.org/wiki/',
|
|
|
|
|
'iw_api' => 'http://zzwiki.org/w/api.php',
|
|
|
|
|
'iw_wikiid' => 'zzwiki',
|
|
|
|
|
'iw_local' => 0,
|
|
|
|
|
'iw_trans' => 0
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$this->populateDB( [ $dewiki, $zzwiki ] );
|
|
|
|
|
|
2015-10-30 22:04:52 +00:00
|
|
|
$this->setWgInterwikiCache( false );
|
2016-04-23 19:00:18 +00:00
|
|
|
|
2022-01-12 20:13:39 +00:00
|
|
|
$interwikiLookup = $this->getServiceContainer()->getInterwikiLookup();
|
2016-04-23 19:00:18 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
[ $dewiki, $zzwiki ],
|
2017-01-10 09:51:50 +00:00
|
|
|
$interwikiLookup->getAllPrefixes(),
|
2016-04-23 19:00:18 +00:00
|
|
|
'getAllPrefixes()'
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
[ $dewiki ],
|
2017-01-10 09:51:50 +00:00
|
|
|
$interwikiLookup->getAllPrefixes( true ),
|
2016-04-23 19:00:18 +00:00
|
|
|
'getAllPrefixes()'
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
[ $zzwiki ],
|
2017-01-10 09:51:50 +00:00
|
|
|
$interwikiLookup->getAllPrefixes( false ),
|
2016-04-23 19:00:18 +00:00
|
|
|
'getAllPrefixes()'
|
|
|
|
|
);
|
|
|
|
|
|
2017-01-10 09:51:50 +00:00
|
|
|
$this->assertTrue( $interwikiLookup->isValidInterwiki( 'de' ), 'known prefix is valid' );
|
|
|
|
|
$this->assertFalse( $interwikiLookup->isValidInterwiki( 'xyz' ), 'unknown prefix is valid' );
|
2016-04-23 19:00:18 +00:00
|
|
|
|
2017-01-10 09:51:50 +00:00
|
|
|
$this->assertNull( $interwikiLookup->fetch( null ), 'no prefix' );
|
|
|
|
|
$this->assertFalse( $interwikiLookup->fetch( 'xyz' ), 'unknown prefix' );
|
2016-04-23 19:00:18 +00:00
|
|
|
|
2017-01-10 09:51:50 +00:00
|
|
|
$interwiki = $interwikiLookup->fetch( 'de' );
|
2018-01-13 00:02:09 +00:00
|
|
|
$this->assertInstanceOf( Interwiki::class, $interwiki );
|
2017-01-10 09:51:50 +00:00
|
|
|
$this->assertSame( $interwiki, $interwikiLookup->fetch( 'de' ), 'in-process caching' );
|
2016-04-23 19:00:18 +00:00
|
|
|
|
|
|
|
|
$this->assertSame( 'http://de.wikipedia.org/wiki/', $interwiki->getURL(), 'getURL' );
|
|
|
|
|
$this->assertSame( 'http://de.wikipedia.org/w/api.php', $interwiki->getAPI(), 'getAPI' );
|
|
|
|
|
$this->assertSame( 'dewiki', $interwiki->getWikiID(), 'getWikiID' );
|
|
|
|
|
$this->assertSame( true, $interwiki->isLocal(), 'isLocal' );
|
|
|
|
|
$this->assertSame( false, $interwiki->isTranscludable(), 'isTranscludable' );
|
|
|
|
|
|
2018-06-07 18:40:46 +00:00
|
|
|
$interwikiLookup->invalidateCache( 'de' );
|
2017-01-10 09:51:50 +00:00
|
|
|
$this->assertNotSame( $interwiki, $interwikiLookup->fetch( 'de' ), 'invalidate cache' );
|
2016-04-23 19:00:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|