3 use MediaWiki\Interwiki\InterwikiLookupAdapter
;
4 use MediaWiki\MediaWikiServices
;
7 * @covers SpecialGoToInterwiki
9 class SpecialGoToInterwikiTest
extends MediaWikiTestCase
{
11 public function testExecute() {
12 $this->setService( 'InterwikiLookup', new InterwikiLookupAdapter(
13 new HashSiteStore(), // won't be used
15 'local' => new Interwiki( 'local', 'https://local.example.com/$1',
16 'https://local.example.com/api.php', 'unittest_localwiki', 1 ),
17 'nonlocal' => new Interwiki( 'nonlocal', 'https://nonlocal.example.com/$1',
18 'https://nonlocal.example.com/api.php', 'unittest_nonlocalwiki', 0 ),
21 MediaWikiServices
::getInstance()->resetServiceForTesting( 'TitleFormatter' );
22 MediaWikiServices
::getInstance()->resetServiceForTesting( 'TitleParser' );
23 MediaWikiServices
::getInstance()->resetServiceForTesting( '_MediaWikiTitleCodec' );
26 $this->assertTrue( !Title
::newFromText( 'Foo' )->isExternal() );
27 $this->assertTrue( Title
::newFromText( 'local:Foo' )->isExternal() );
28 $this->assertTrue( Title
::newFromText( 'nonlocal:Foo' )->isExternal() );
29 $this->assertTrue( Title
::newFromText( 'local:Foo' )->isLocal() );
30 $this->assertTrue( !Title
::newFromText( 'nonlocal:Foo' )->isLocal() );
32 $goToInterwiki = MediaWikiServices
::getInstance()->getSpecialPageFactory()
33 ->getPage( 'GoToInterwiki' );
35 RequestContext
::resetMain();
36 $context = new DerivativeContext( RequestContext
::getMain() );
37 $goToInterwiki->setContext( $context );
38 $goToInterwiki->execute( 'Foo' );
39 $this->assertSame( Title
::newFromText( 'Foo' )->getFullURL(),
40 $context->getOutput()->getRedirect() );
42 RequestContext
::resetMain();
43 $context = new DerivativeContext( RequestContext
::getMain() );
44 $goToInterwiki->setContext( $context );
45 $goToInterwiki->execute( 'local:Foo' );
46 $this->assertSame( Title
::newFromText( 'local:Foo' )->getFullURL(),
47 $context->getOutput()->getRedirect() );
49 RequestContext
::resetMain();
50 $context = new DerivativeContext( RequestContext
::getMain() );
51 $goToInterwiki->setContext( $context );
52 $goToInterwiki->execute( 'nonlocal:Foo' );
53 $this->assertSame( '', $context->getOutput()->getRedirect() );
54 $this->assertContains( Title
::newFromText( 'nonlocal:Foo' )->getFullURL(),
55 $context->getOutput()->getHTML() );
57 RequestContext
::resetMain();
58 $context = new DerivativeContext( RequestContext
::getMain() );
59 $goToInterwiki->setContext( $context );
60 $goToInterwiki->execute( 'force/Foo' );
61 $this->assertSame( Title
::newFromText( 'Foo' )->getFullURL(),
62 $context->getOutput()->getRedirect() );
64 RequestContext
::resetMain();
65 $context = new DerivativeContext( RequestContext
::getMain() );
66 $goToInterwiki->setContext( $context );
67 $goToInterwiki->execute( 'force/local:Foo' );
68 $this->assertSame( '', $context->getOutput()->getRedirect() );
69 $this->assertContains( Title
::newFromText( 'local:Foo' )->getFullURL(),
70 $context->getOutput()->getHTML() );
72 RequestContext
::resetMain();
73 $context = new DerivativeContext( RequestContext
::getMain() );
74 $goToInterwiki->setContext( $context );
75 $goToInterwiki->execute( 'force/nonlocal:Foo' );
76 $this->assertSame( '', $context->getOutput()->getRedirect() );
77 $this->assertContains( Title
::newFromText( 'nonlocal:Foo' )->getFullURL(),
78 $context->getOutput()->getHTML() );