<?php
+use MediaWiki\MediaWikiServices;
+
/**
* @group Database
* @group Title
*/
public function testSecureAndSplitValid( $text ) {
$this->secureAndSplitGlobals();
- $this->assertInstanceOf( 'Title', Title::newFromText( $text ), "Valid: $text" );
+ $this->assertInstanceOf( Title::class, Title::newFromText( $text ), "Valid: $text" );
}
/**
/**
* Auth-less test of Title::isValidMoveOperation
*
- * @group Database
* @param string $source
* @param string $target
* @param array|string|bool $expected Required error
$this->setContentLang( $contLang );
$title = Title::newFromText( $titleText );
- $this->assertInstanceOf( 'Title', $title,
+ $this->assertInstanceOf( Title::class, $title,
"Test must be passed a valid title text, you gave '$titleText'"
);
$this->assertEquals( $expected,
}
/**
+ * @covers Title::newFromTitleValue
* @dataProvider provideNewFromTitleValue
*/
public function testNewFromTitleValue( TitleValue $value ) {
}
/**
+ * @covers Title::getTitleValue
* @dataProvider provideGetTitleValue
*/
public function testGetTitleValue( $text ) {
}
/**
+ * @covers Title::getFragment
* @dataProvider provideGetFragment
*
* @param string $full
*/
public function testExists() {
$title = Title::makeTitle( NS_PROJECT, 'New page' );
- $linkCache = LinkCache::singleton();
+ $linkCache = MediaWikiServices::getInstance()->getLinkCache();
$article = new Article( $title );
$page = $article->getPage();
public function testGetPrefixedDBKey( Title $title, $expected ) {
$this->assertEquals( $expected, $title->getPrefixedDBkey() );
}
+
+ /**
+ * @covers Title::getFragmentForURL
+ * @dataProvider provideGetFragmentForURL
+ *
+ * @param string $titleStr
+ * @param string $expected
+ */
+ public function testGetFragmentForURL( $titleStr, $expected ) {
+ $this->setMwGlobals( [
+ 'wgFragmentMode' => [ 'html5' ],
+ 'wgExternalInterwikiFragmentMode' => 'legacy',
+ ] );
+ $dbw = wfGetDB( DB_MASTER );
+ $dbw->insert( 'interwiki',
+ [
+ [
+ 'iw_prefix' => 'de',
+ 'iw_url' => 'http://de.wikipedia.org/wiki/',
+ 'iw_api' => 'http://de.wikipedia.org/w/api.php',
+ 'iw_wikiid' => 'dewiki',
+ 'iw_local' => 1,
+ 'iw_trans' => 0,
+ ],
+ [
+ 'iw_prefix' => 'zz',
+ 'iw_url' => 'http://zzwiki.org/wiki/',
+ 'iw_api' => 'http://zzwiki.org/w/api.php',
+ 'iw_wikiid' => 'zzwiki',
+ 'iw_local' => 0,
+ 'iw_trans' => 0,
+ ],
+ ],
+ __METHOD__,
+ [ 'IGNORE' ]
+ );
+
+ $title = Title::newFromText( $titleStr );
+ self::assertEquals( $expected, $title->getFragmentForURL() );
+
+ $dbw->delete( 'interwiki', '*', __METHOD__ );
+ }
+
+ public function provideGetFragmentForURL() {
+ return [
+ [ 'Foo', '' ],
+ [ 'Foo#ümlåût', '#ümlåût' ],
+ [ 'de:Foo#Bå®', '#Bå®' ],
+ [ 'zz:Foo#тест', '#.D1.82.D0.B5.D1.81.D1.82' ],
+ ];
+ }
}