From: Kunal Mehta Date: Wed, 11 May 2016 04:39:22 +0000 (-0700) Subject: Add tests for 'LinkEnd' hook functionality X-Git-Tag: 1.31.0-rc.0~7018^2 X-Git-Url: http://git.cyclocoop.org/clavettes/images/siteon3.jpg?a=commitdiff_plain;h=1facfab51b23fc1679389688367a754a918666f2;p=lhc%2Fweb%2Fwiklou.git Add tests for 'LinkEnd' hook functionality Change-Id: I5bd353756c0631b3dd1c214f814040d82d7c361f --- diff --git a/tests/phpunit/includes/LinkerTest.php b/tests/phpunit/includes/LinkerTest.php index e50b4f1490..1372d8513b 100644 --- a/tests/phpunit/includes/LinkerTest.php +++ b/tests/phpunit/includes/LinkerTest.php @@ -309,4 +309,48 @@ class LinkerTest extends MediaWikiLangTestCase { ]; // @codingStandardsIgnoreEnd } + + public static function provideLinkEndHook() { + return [ + // Override $html + [ + function( $dummy, $title, $options, &$html, &$attribs, &$ret ) { + $html = 'foobar'; + }, + 'foobar' + ], + // Modify $attribs + [ + function( $dummy, $title, $options, &$html, &$attribs, &$ret ) { + $attribs['bar'] = 'baz'; + }, + 'Special:BlankPage' + ], + // Fully override return value and abort hook + [ + function( $dummy, $title, $options, &$html, &$attribs, &$ret ) { + $ret = 'blahblahblah'; + return false; + }, + 'blahblahblah' + ], + + ]; + } + + /** + * @dataProvider provideLinkEndHook + */ + public function testLinkEndHook( $callback, $expected ) { + $this->setMwGlobals( [ + 'wgArticlePath' => '/wiki/$1', + 'wgWellFormedXml' => true, + ] ); + + $this->setMwGlobals( 'wgHooks', [ 'LinkEnd' => [ $callback ] ] ); + + $title = SpecialPage::getTitleFor( 'Blankpage' ); + $out = Linker::link( $title ); + $this->assertEquals( $expected, $out ); + } }