Make the 'interwiki' option temporarily accept null as well as true/false (and default to null instead of false) so form fields which disallow interwiki titles can avoid deprecation warnings. This also includes implementing the new error message. The idea is that for the duration of the deprecation process, form fields can be set explicitly to interwiki => false (which will eventually become the default). It would be super annoying to have to do this for all title fields, but this way it's only needed for fields where users actually submit interwiki titles with some frequency. Also improve the logic for legacy fields (which do not set the option either way): since these (while emitting a warning) allow an interwiki title, it does not make sense to apply namespace etc. checks to that title. Bug: T288155 Change-Id: Ic00f4a0f27747b5ff0893b4c01f42f68a99771ab
67 lines
2.4 KiB
PHP
67 lines
2.4 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Interwiki\InterwikiLookupAdapter;
|
|
|
|
/**
|
|
* @covers HTMLTitleTextFieldTest
|
|
*/
|
|
class HTMLTitleTextFieldTest extends MediaWikiIntegrationTestCase {
|
|
|
|
/**
|
|
* @dataProvider provideInterwiki
|
|
*/
|
|
public function testInterwiki( array $config, string $value, bool $isValid ) {
|
|
$this->setupInterwikiTable();
|
|
$field = new HTMLTitleTextField( $config + [ 'fieldname' => 'foo' ] );
|
|
$result = $field->validate( $value, [ 'foo' => $value ] );
|
|
if ( $isValid ) {
|
|
$this->assertSame( true, $result );
|
|
} else {
|
|
// phpcs:ignore MediaWiki.PHPUnit.AssertEquals.True
|
|
$this->assertNotSame( true, $result );
|
|
}
|
|
}
|
|
|
|
public function provideInterwiki() {
|
|
return [
|
|
'local title' => [ [ 'interwiki' => false ], 'SomeTitle', true ],
|
|
'interwiki title, disallowed' => [ [ 'interwiki' => false ],
|
|
'unittest_foo:SomeTitle', false ],
|
|
'interwiki title, allowed' => [ [ 'interwiki' => true ],
|
|
'unittest_foo:SomeTitle', true ],
|
|
'namespace safety check' => [ [ 'interwiki' => true, 'namespace' => NS_TALK ],
|
|
'SomeTitle', false ],
|
|
'interwiki ignores namespace' => [ [ 'interwiki' => true, 'namespace' => NS_TALK ],
|
|
'unittest_foo:SomeTitle', true ],
|
|
'creatable safety check' => [ [ 'interwiki' => true, 'creatable' => true ],
|
|
'Special:Version', false ],
|
|
'interwiki ignores creatable' => [ [ 'interwiki' => true, 'creatable' => true ],
|
|
'unittest_foo:Special:Version', true ],
|
|
'exists safety check' => [ [ 'interwiki' => true, 'exists' => true ],
|
|
'SomeTitle', false ],
|
|
'interwiki ignores exists' => [ [ 'interwiki' => true, 'exists' => true ],
|
|
'unittest_foo:SomeTitle', true ],
|
|
];
|
|
}
|
|
|
|
public function testInterwiki_relative() {
|
|
$this->expectException( InvalidArgumentException::class );
|
|
$field = new HTMLTitleTextField( [ 'fieldname' => 'foo', 'interwiki' => true, 'relative' => true ] );
|
|
$field->validate( 'SomeTitle', [ 'foo' => 'SomeTitle' ] );
|
|
}
|
|
|
|
public function testInterwiki_deprecation() {
|
|
$this->expectError();
|
|
$field = new HTMLTitleTextField( [ 'fieldname' => 'foo' ] );
|
|
$field->validate( 'unittest_foo:SomeTitle', [ 'foo' => 'SomeTitle' ] );
|
|
}
|
|
|
|
protected function setupInterwikiTable() {
|
|
$site = new Site( Site::TYPE_MEDIAWIKI );
|
|
$site->setGlobalId( 'unittest_foowiki' );
|
|
$site->addInterwikiId( 'unittest_foo' );
|
|
$this->setService( 'InterwikiLookup', new InterwikiLookupAdapter( new HashSiteStore( [ $site ] ) ) );
|
|
$this->assertTrue( Title::newFromText( 'unittest_foo:SomeTitle' )->isExternal() );
|
|
}
|
|
|
|
}
|