jenkins-bot has submitted this change and it was merged. Change subject: Clear extension data in ParserClearState handler ......................................................................
Clear extension data in ParserClearState handler While the related parser function sets the accumulated related pages as extension data on the parser output (see RelatedArticles\Hooks::onFuncRelated). The ParserClearState handler, however, sets the empty list as a property, which is then stored in the DB. Changes: * Make RelatedArticles\Hooks::onParserClearState use ParserOutput#setExtensionData, mirroring ::onFuncRelated * Add a unit test for the the handler Bug: T115698 Change-Id: I3deaf1e8ee78944250c3f26315ee2450b444a035 --- M extension.json M includes/Hooks.php A tests/phpunit/HooksTest.php 3 files changed, 57 insertions(+), 1 deletion(-) Approvals: Jdlrobson: Looks good to me, approved jenkins-bot: Verified diff --git a/extension.json b/extension.json index 0fb7ca7..56a786b 100644 --- a/extension.json +++ b/extension.json @@ -31,6 +31,9 @@ ], "SkinTemplateToolboxEnd": [ "RelatedArticles\\Hooks::onSkinTemplateToolboxEnd" + ], + "UnitTestsList": [ + "RelatedArticles\\Hooks::onUnitTestsList" ] }, "MessagesDirs": { diff --git a/includes/Hooks.php b/includes/Hooks.php index bcbbdac..c83c95a 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -74,7 +74,12 @@ * @return boolean Always <code>true</code> */ public static function onParserClearState( Parser &$parser ) { - $parser->getOutput()->setProperty( 'RelatedArticles', array() ); + $parserOutput = $parser->getOutput(); + + $parserOutput->setExtensionData( 'RelatedArticles', array() ); + + // FIXME: Remove in 30 days (T115698) + $parserOutput->unsetProperty( 'RelatedArticles' ); return true; } @@ -259,4 +264,18 @@ return true; } + /** + * Handler for the <code>UnitTestsList</code> hook. + * + * Adds the path to this extension's PHPUnit test suite to the set of + * paths. + * + * @param array $paths + * @return boolean Always <code>true</code> + */ + public static function onUnitTestsList( array &$paths ) { + $paths[] = __DIR__ . '/../tests/phpunit'; + + return true; + } } diff --git a/tests/phpunit/HooksTest.php b/tests/phpunit/HooksTest.php new file mode 100644 index 0000000..f3331b7 --- /dev/null +++ b/tests/phpunit/HooksTest.php @@ -0,0 +1,34 @@ +<?php + +namespace Tests\RelatedArticles; + +use PHPUnit_Framework_TestCase; +use Parser; +use ParserOutput; +use RelatedArticles\Hooks; + +class HooksTest extends PHPUnit_Framework_TestCase { + + public function test_onParserClearState() { + $parser = new Parser(); + $parserOutput = $parser->mOutput = new ParserOutput(); + $relatedArticles = array( 'Maybeshewill' ); + + $parserOutput->setExtensionData( 'RelatedArticles', $relatedArticles ); + $parserOutput->setProperty( 'RelatedArticles', $relatedArticles ); + + Hooks::onParserClearState( $parser ); + + $this->assertEquals( + array(), + $parserOutput->getExtensionData( 'RelatedArticles' ), + 'It clears the list of related articles.' + ); + + $this->assertEquals( + false, + $parserOutput->getProperty( 'RelatedArticles' ), + '[T115698] It unsets the list of related articles that were set as a property.' + ); + } +} -- To view, visit https://gerrit.wikimedia.org/r/246836 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I3deaf1e8ee78944250c3f26315ee2450b444a035 Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/RelatedArticles Gerrit-Branch: master Gerrit-Owner: Phuedx <g...@samsmith.io> Gerrit-Reviewer: Hashar <has...@free.fr> Gerrit-Reviewer: Jdlrobson <jrob...@wikimedia.org> Gerrit-Reviewer: Phuedx <g...@samsmith.io> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits