From 1facfab51b23fc1679389688367a754a918666f2 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Tue, 10 May 2016 21:39:22 -0700 Subject: [PATCH] Add tests for 'LinkEnd' hook functionality Change-Id: I5bd353756c0631b3dd1c214f814040d82d7c361f --- tests/phpunit/includes/LinkerTest.php | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) 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 ); + } } -- 2.20.1