<?php
-use MediaWiki\MediaWikiServices;
/**
* @group Database
*/
-
class LinkerTest extends MediaWikiLangTestCase {
/**
public function provideCasesForFormatComment() {
$wikiId = 'enwiki'; // $wgConf has a fake entry for this
- // @codingStandardsIgnoreStart Generic.Files.LineLength
+ // phpcs:disable Generic.Files.LineLength
return [
// Linker::formatComment
[
false, false, $wikiId
],
];
- // @codingStandardsIgnoreEnd
+ // phpcs:enable
}
/**
}
public static function provideCasesForFormatLinksInComment() {
- // @codingStandardsIgnoreStart Generic.Files.LineLength
+ // phpcs:disable Generic.Files.LineLength
return [
[
'foo bar <a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a>',
'enwiki',
],
];
- // @codingStandardsIgnoreEnd
+ // phpcs:enable
}
public static function provideLinkBeginHook() {
- // @codingStandardsIgnoreStart Generic.Files.LineLength
+ // phpcs:disable Generic.Files.LineLength
return [
// Modify $html
[
- function( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
+ function ( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
$html = 'foobar';
},
'<a href="/wiki/Special:BlankPage" title="Special:BlankPage">foobar</a>'
],
// Modify $attribs
[
- function( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
+ function ( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
$attribs['bar'] = 'baz';
},
'<a href="/wiki/Special:BlankPage" title="Special:BlankPage" bar="baz">Special:BlankPage</a>'
],
// Modify $query
[
- function( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
+ function ( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
$query['bar'] = 'baz';
},
'<a href="/w/index.php?title=Special:BlankPage&bar=baz" title="Special:BlankPage">Special:BlankPage</a>'
],
// Force HTTP $options
[
- function( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
+ function ( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
$options = [ 'http' ];
},
'<a href="http://example.org/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a>'
],
// Force 'forcearticlepath' in $options
[
- function( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
+ function ( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
$options = [ 'forcearticlepath' ];
$query['foo'] = 'bar';
},
],
// Abort early
[
- function( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
+ function ( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
$ret = 'foobar';
return false;
},
'foobar'
],
];
- // @codingStandardsIgnoreEnd
+ // phpcs:enable
}
/**
* @dataProvider provideLinkBeginHook
*/
public function testLinkBeginHook( $callback, $expected ) {
+ $this->hideDeprecated( 'LinkBegin hook (used in hook-LinkBegin-closure)' );
$this->setMwGlobals( [
'wgArticlePath' => '/wiki/$1',
'wgServer' => '//example.org',
* @dataProvider provideLinkEndHook
*/
public function testLinkEndHook( $callback, $expected ) {
+ $this->hideDeprecated( 'LinkEnd hook (used in hook-LinkEnd-closure)' );
$this->setMwGlobals( [
'wgArticlePath' => '/wiki/$1',
] );
$out = Linker::link( $title );
$this->assertEquals( $expected, $out );
}
-
- /**
- * @covers Linker::getLinkColour
- */
- public function testGetLinkColour() {
- $this->hideDeprecated( 'Linker::getLinkColour' );
- $linkCache = MediaWikiServices::getInstance()->getLinkCache();
- $foobarTitle = Title::makeTitle( NS_MAIN, 'FooBar' );
- $redirectTitle = Title::makeTitle( NS_MAIN, 'Redirect' );
- $userTitle = Title::makeTitle( NS_USER, 'Someuser' );
- $linkCache->addGoodLinkObj(
- 1, // id
- $foobarTitle,
- 10, // len
- 0 // redir
- );
- $linkCache->addGoodLinkObj(
- 2, // id
- $redirectTitle,
- 10, // len
- 1 // redir
- );
-
- $linkCache->addGoodLinkObj(
- 3, // id
- $userTitle,
- 10, // len
- 0 // redir
- );
-
- $this->assertEquals(
- '',
- Linker::getLinkColour( $foobarTitle, 0 )
- );
-
- $this->assertEquals(
- 'stub',
- Linker::getLinkColour( $foobarTitle, 20 )
- );
-
- $this->assertEquals(
- 'mw-redirect',
- Linker::getLinkColour( $redirectTitle, 0 )
- );
-
- $this->assertEquals(
- '',
- Linker::getLinkColour( $userTitle, 20 )
- );
- }
}