MediaWiki REL1_33
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 // 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
68 ];
69
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
77 ];
78
79 $this->populateDB( [ $dewiki, $zzwiki ] );
80
81 $this->setWgInterwikiCache( false );
82
83 $interwikiLookup = MediaWikiServices::getInstance()->getInterwikiLookup();
84 $this->assertEquals(
85 [ $dewiki, $zzwiki ],
86 $interwikiLookup->getAllPrefixes(),
87 'getAllPrefixes()'
88 );
89 $this->assertEquals(
90 [ $dewiki ],
91 $interwikiLookup->getAllPrefixes( true ),
92 'getAllPrefixes()'
93 );
94 $this->assertEquals(
95 [ $zzwiki ],
96 $interwikiLookup->getAllPrefixes( false ),
97 'getAllPrefixes()'
98 );
99
100 $this->assertTrue( $interwikiLookup->isValidInterwiki( 'de' ), 'known prefix is valid' );
101 $this->assertFalse( $interwikiLookup->isValidInterwiki( 'xyz' ), 'unknown prefix is valid' );
102
103 $this->assertNull( $interwikiLookup->fetch( null ), 'no prefix' );
104 $this->assertFalse( $interwikiLookup->fetch( 'xyz' ), 'unknown prefix' );
105
106 $interwiki = $interwikiLookup->fetch( 'de' );
107 $this->assertInstanceOf( Interwiki::class, $interwiki );
108 $this->assertSame( $interwiki, $interwikiLookup->fetch( 'de' ), 'in-process caching' );
109
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' );
115
116 $interwikiLookup->invalidateCache( 'de' );
117 $this->assertNotSame( $interwiki, $interwikiLookup->fetch( 'de' ), 'invalidate cache' );
118 }
119
120}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
setWgInterwikiCache( $interwikiCache)
populateDB( $iwrows)
Value object for representing interwiki records.
Definition Interwiki.php:27
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:26