MediaWiki REL1_31
InterwikiTest.php
Go to the documentation of this file.
1<?php
3
11
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',
18 1,
19 0
20 );
21
22 $this->setContentLang( 'qqx' );
23
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() );
31 }
32
33 public function testGetUrl() {
34 $interwiki = new Interwiki(
35 'xyz',
36 'http://xyz.acme.test/wiki/$1'
37 );
38
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' ) );
41 }
42
44
45 private function populateDB( $iwrows ) {
46 $dbw = wfGetDB( DB_MASTER );
47 $dbw->delete( 'interwiki', '*', __METHOD__ );
48 $dbw->insert( 'interwiki', array_values( $iwrows ), __METHOD__ );
49 $this->tablesUsed[] = 'interwiki';
50 }
51
52 private function setWgInterwikiCache( $interwikiCache ) {
53 $this->overrideMwServices();
54 MediaWikiServices::getInstance()->resetServiceForTesting( 'InterwikiLookup' );
55 $this->setMwGlobals( 'wgInterwikiCache', $interwikiCache );
56 }
57
58 public function testDatabaseStorage() {
59 $this->markTestSkipped( 'Needs I37b8e8018b3 <https://gerrit.wikimedia.org/r/#/c/270555/>' );
60
61 // NOTE: database setup is expensive, so we only do
62 // it once and run all the tests in one go.
63 $dewiki = [
64 'iw_prefix' => 'de',
65 'iw_url' => 'http://de.wikipedia.org/wiki/',
66 'iw_api' => 'http://de.wikipedia.org/w/api.php',
67 'iw_wikiid' => 'dewiki',
68 'iw_local' => 1,
69 'iw_trans' => 0
70 ];
71
72 $zzwiki = [
73 'iw_prefix' => 'zz',
74 'iw_url' => 'http://zzwiki.org/wiki/',
75 'iw_api' => 'http://zzwiki.org/w/api.php',
76 'iw_wikiid' => 'zzwiki',
77 'iw_local' => 0,
78 'iw_trans' => 0
79 ];
80
81 $this->populateDB( [ $dewiki, $zzwiki ] );
82
83 $this->setWgInterwikiCache( false );
84
85 $interwikiLookup = MediaWikiServices::getInstance()->getInterwikiLookup();
86 $this->assertEquals(
87 [ $dewiki, $zzwiki ],
88 $interwikiLookup->getAllPrefixes(),
89 'getAllPrefixes()'
90 );
91 $this->assertEquals(
92 [ $dewiki ],
93 $interwikiLookup->getAllPrefixes( true ),
94 'getAllPrefixes()'
95 );
96 $this->assertEquals(
97 [ $zzwiki ],
98 $interwikiLookup->getAllPrefixes( false ),
99 'getAllPrefixes()'
100 );
101
102 $this->assertTrue( $interwikiLookup->isValidInterwiki( 'de' ), 'known prefix is valid' );
103 $this->assertFalse( $interwikiLookup->isValidInterwiki( 'xyz' ), 'unknown prefix is valid' );
104
105 $this->assertNull( $interwikiLookup->fetch( null ), 'no prefix' );
106 $this->assertFalse( $interwikiLookup->fetch( 'xyz' ), 'unknown prefix' );
107
108 $interwiki = $interwikiLookup->fetch( 'de' );
109 $this->assertInstanceOf( Interwiki::class, $interwiki );
110 $this->assertSame( $interwiki, $interwikiLookup->fetch( 'de' ), 'in-process caching' );
111
112 $this->assertSame( 'http://de.wikipedia.org/wiki/', $interwiki->getURL(), 'getURL' );
113 $this->assertSame( 'http://de.wikipedia.org/w/api.php', $interwiki->getAPI(), 'getAPI' );
114 $this->assertSame( 'dewiki', $interwiki->getWikiID(), 'getWikiID' );
115 $this->assertSame( true, $interwiki->isLocal(), 'isLocal' );
116 $this->assertSame( false, $interwiki->isTranscludable(), 'isTranscludable' );
117
119 $this->assertNotSame( $interwiki, $interwikiLookup->fetch( 'de' ), 'invalidate cache' );
120 }
121
122}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
setWgInterwikiCache( $interwikiCache)
populateDB( $iwrows)
Value object for representing interwiki records.
Definition Interwiki.php:27
static invalidateCache( $prefix)
Purge the cache (local and persistent) for an interwiki prefix.
Definition Interwiki.php:90
overrideMwServices(Config $configOverrides=null, array $services=[])
Stashes the global instance of MediaWikiServices, and installs a new one, allowing test cases to over...
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
MediaWikiServices is the service locator for the application scope of MediaWiki.
const DB_MASTER
Definition defines.php:29