1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
<?php
use MediaWiki\Context\DerivativeContext;
use MediaWiki\Context\RequestContext;
use MediaWiki\Interwiki\InterwikiLookupAdapter;
use MediaWiki\Site\HashSiteStore;
use MediaWiki\Title\Title;
/**
* @covers \MediaWiki\Specials\SpecialGoToInterwiki
*/
class SpecialGoToInterwikiTest extends MediaWikiIntegrationTestCase {
public function testExecute() {
$this->setService( 'InterwikiLookup', new InterwikiLookupAdapter(
new HashSiteStore(), // won't be used
[
'local' => new Interwiki( 'local', 'https://local.example.com/$1',
'https://local.example.com/api.php', 'unittest_localwiki', 1 ),
'nonlocal' => new Interwiki( 'nonlocal', 'https://nonlocal.example.com/$1',
'https://nonlocal.example.com/api.php', 'unittest_nonlocalwiki', 0 ),
]
) );
$this->getServiceContainer()->resetServiceForTesting( 'TitleFormatter' );
$this->getServiceContainer()->resetServiceForTesting( 'TitleParser' );
$this->getServiceContainer()->resetServiceForTesting( '_MediaWikiTitleCodec' );
$this->assertNotTrue( Title::newFromText( 'Foo' )->isExternal() );
$this->assertTrue( Title::newFromText( 'local:Foo' )->isExternal() );
$this->assertTrue( Title::newFromText( 'nonlocal:Foo' )->isExternal() );
$this->assertTrue( Title::newFromText( 'local:Foo' )->isLocal() );
$this->assertNotTrue( Title::newFromText( 'nonlocal:Foo' )->isLocal() );
$goToInterwiki = $this->getServiceContainer()->getSpecialPageFactory()
->getPage( 'GoToInterwiki' );
RequestContext::resetMain();
$context = new DerivativeContext( RequestContext::getMain() );
$goToInterwiki->setContext( $context );
$goToInterwiki->execute( 'Foo' );
$this->assertSame( Title::newFromText( 'Foo' )->getFullURL(),
$context->getOutput()->getRedirect() );
RequestContext::resetMain();
$context = new DerivativeContext( RequestContext::getMain() );
$goToInterwiki->setContext( $context );
$goToInterwiki->execute( 'local:Foo' );
$this->assertSame( Title::newFromText( 'local:Foo' )->getFullURL(),
$context->getOutput()->getRedirect() );
RequestContext::resetMain();
$context = new DerivativeContext( RequestContext::getMain() );
$goToInterwiki->setContext( $context );
$goToInterwiki->execute( 'nonlocal:Foo' );
$this->assertSame( '', $context->getOutput()->getRedirect() );
$this->assertStringContainsString( Title::newFromText( 'nonlocal:Foo' )->getFullURL(),
$context->getOutput()->getHTML() );
RequestContext::resetMain();
$context = new DerivativeContext( RequestContext::getMain() );
$goToInterwiki->setContext( $context );
$goToInterwiki->execute( 'force/Foo' );
$this->assertSame( Title::newFromText( 'Foo' )->getFullURL(),
$context->getOutput()->getRedirect() );
RequestContext::resetMain();
$context = new DerivativeContext( RequestContext::getMain() );
$goToInterwiki->setContext( $context );
$goToInterwiki->execute( 'force/local:Foo' );
$this->assertSame( '', $context->getOutput()->getRedirect() );
$this->assertStringContainsString( Title::newFromText( 'local:Foo' )->getFullURL(),
$context->getOutput()->getHTML() );
RequestContext::resetMain();
$context = new DerivativeContext( RequestContext::getMain() );
$goToInterwiki->setContext( $context );
$goToInterwiki->execute( 'force/nonlocal:Foo' );
$this->assertSame( '', $context->getOutput()->getRedirect() );
$this->assertStringContainsString( Title::newFromText( 'nonlocal:Foo' )->getFullURL(),
$context->getOutput()->getHTML() );
}
}
|