jenkins-bot has submitted this change and it was merged.
Change subject: Extract handlers for ParserOutput hooks
......................................................................
Extract handlers for ParserOutput hooks
This factors the handlers for ParserOutput related hooks
out of the general WikibaseCLientHooks class into a separate class
and makes them testable.
Change-Id: I5a76107fb9e02c94d75205738858a57b1175ac56
---
M client/WikibaseClient.hooks.php
M client/WikibaseClient.php
A client/includes/hooks/ParserOutputHooks.php
A client/tests/phpunit/includes/hooks/ParserOutputHooksTest.php
4 files changed, 575 insertions(+), 112 deletions(-)
Approvals:
Bene: Looks good to me, but someone else must approve
Aude: Looks good to me, approved
jenkins-bot: Verified
diff --git a/client/WikibaseClient.hooks.php b/client/WikibaseClient.hooks.php
index 80b2bd4..4537acc 100644
--- a/client/WikibaseClient.hooks.php
+++ b/client/WikibaseClient.hooks.php
@@ -328,77 +328,6 @@
}
/**
- * Hook runs after internal parsing
- * @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserAfterParse
- *
- * @since 0.1
- *
- * @param Parser $parser
- * @param string $text
- * @param StripState $stripState
- *
- * @return bool
- */
- public static function onParserAfterParse( Parser &$parser, &$text,
StripState $stripState ) {
- // this hook tries to access repo SiteLinkTable
- // it interferes with any test that parses something, like a
page or a message
- if ( defined( 'MW_PHPUNIT_TEST' ) ) {
- return true;
- }
-
- $title = $parser->getTitle();
-
- if ( !self::isWikibaseEnabled( $title->getNamespace() ) ) {
- // shorten out
- return true;
- }
-
- wfProfileIn( __METHOD__ );
-
- // @todo split up the multiple responsibilities here and in
lang link handler
-
- // only run this once, for the article content and not
interface stuff
- //FIXME: this also runs for messages in
EditPage::showEditTools! Ugh!
- if ( $parser->getOptions()->getInterfaceMessage() ) {
- wfProfileOut( __METHOD__ );
- return true;
- }
-
- $langLinkHandler =
WikibaseClient::getDefaultInstance()->getLangLinkHandler();
-
- $parserOutput = $parser->getOutput();
- $useRepoLinks = $langLinkHandler->useRepoLinks( $title,
$parserOutput );
-
- try {
- if ( $useRepoLinks ) {
- // add links
- $langLinkHandler->addLinksFromRepository(
$title, $parserOutput );
- }
-
- $langLinkHandler->updateItemIdProperty( $title,
$parserOutput );
- $langLinkHandler->updateOtherProjectsLinksData( $title,
$parserOutput );
- } catch ( \Exception $e ) {
- wfWarn( 'Failed to add repo links: ' . $e->getMessage()
);
- }
-
- $settings = WikibaseClient::getDefaultInstance()->getSettings();
-
- if ( $useRepoLinks || $settings->getSetting( 'alwaysSort' ) ) {
- $interwikiSorter = new InterwikiSorter(
- $settings->getSetting( 'sort' ),
- $settings->getSetting( 'interwikiSortOrders' ),
- $settings->getSetting( 'sortPrepend' )
- );
- $interwikiLinks = $parserOutput->getLanguageLinks();
- $sortedLinks = $interwikiSorter->sortLinks(
$interwikiLinks );
- $parserOutput->setLanguageLinks( $sortedLinks );
- }
-
- wfProfileOut( __METHOD__ );
- return true;
- }
-
- /**
* Add badges to the language links.
*
* @since 0.5
@@ -511,45 +440,6 @@
$beforePageDisplayHandler->addModules( $out, $skin, $actionName
);
wfProfileOut( __METHOD__ );
-
- return true;
- }
-
- /**
- * Add output page property if repo links are suppressed, and property
for item id
- *
- * @since 0.4
- *
- * @param OutputPage &$out
- * @param ParserOutput $pout
- *
- * @return bool
- */
- public static function onOutputPageParserOutput( OutputPage &$out,
ParserOutput $pout ) {
- if ( !self::isWikibaseEnabled( $out->getTitle()->getNamespace()
) ) {
- // shorten out
- return true;
- }
-
- $langLinkHandler =
WikibaseClient::getDefaultInstance()->getLangLinkHandler();
-
- $noExternalLangLinks =
$langLinkHandler->getNoExternalLangLinks( $pout );
-
- if ( $noExternalLangLinks !== array() ) {
- $out->setProperty( 'noexternallanglinks',
$noExternalLangLinks );
- }
-
- $itemId = $pout->getProperty( 'wikibase_item' );
-
- if ( $itemId !== false ) {
- $out->setProperty( 'wikibase_item', $itemId );
- }
-
- $otherProjects = $pout->getExtensionData(
'wikibase-otherprojects-sidebar' );
-
- if ( $otherProjects !== null ) {
- $out->setProperty( 'wikibase-otherprojects-sidebar',
$otherProjects );
- }
return true;
}
diff --git a/client/WikibaseClient.php b/client/WikibaseClient.php
index b4a9e3f..36b6eb5 100644
--- a/client/WikibaseClient.php
+++ b/client/WikibaseClient.php
@@ -91,8 +91,8 @@
$wgHooks['UnitTestsList'][] =
'\Wikibase\ClientHooks::registerUnitTests';
$wgHooks['BaseTemplateToolbox'][] =
'\Wikibase\ClientHooks::onBaseTemplateToolbox';
$wgHooks['OldChangesListRecentChangesLine'][] =
'\Wikibase\ClientHooks::onOldChangesListRecentChangesLine';
- $wgHooks['OutputPageParserOutput'][] =
'\Wikibase\ClientHooks::onOutputPageParserOutput';
- $wgHooks['ParserAfterParse'][] =
'\Wikibase\ClientHooks::onParserAfterParse';
+ $wgHooks['OutputPageParserOutput'][] =
'\Wikibase\Client\Hooks\ParserOutputHooks::onOutputPageParserOutput';
+ $wgHooks['ParserAfterParse'][] =
'\Wikibase\Client\Hooks\ParserOutputHooks::onParserAfterParse';
$wgHooks['ParserFirstCallInit'][] =
'\Wikibase\ClientHooks::onParserFirstCallInit';
$wgHooks['MagicWordwgVariableIDs'][] =
'\Wikibase\ClientHooks::onMagicWordwgVariableIDs';
$wgHooks['ParserGetVariableValueSwitch'][] =
'\Wikibase\ClientHooks::onParserGetVariableValueSwitch';
diff --git a/client/includes/hooks/ParserOutputHooks.php
b/client/includes/hooks/ParserOutputHooks.php
new file mode 100644
index 0000000..0776977
--- /dev/null
+++ b/client/includes/hooks/ParserOutputHooks.php
@@ -0,0 +1,208 @@
+<?php
+
+namespace Wikibase\Client\Hooks;
+
+use Exception;
+use OutputPage;
+use Parser;
+use ParserOutput;
+use StripState;
+use Wikibase\Client\WikibaseClient;
+use Wikibase\InterwikiSorter;
+use Wikibase\LangLinkHandler;
+use Wikibase\NamespaceChecker;
+
+/**
+ * ParserOutput related hook handlers.
+ *
+ * This class has a static interface for use with MediaWiki's hook mechanism;
the static
+ * handler functions will create a new instance of ParserOutputHooks and then
call the
+ * corresponding member function on that.
+ *
+ * @since 0.5.
+ *
+ * @license GPL 2+
+ * @author Katie Filbert < [email protected] >
+ * @author Daniel Kinzler
+ * @author Jeroen De Dauw < [email protected] >
+ * @author Marius Hoch < [email protected] >
+ */
+class ParserOutputHooks {
+
+ /**
+ * @var NamespaceChecker
+ */
+ private $namespaceChecker;
+
+ /**
+ * @var LangLinkHandler
+ */
+ private $langLinkHandler;
+
+ /**
+ * @var InterwikiSorter
+ */
+ private $interwikiSorter;
+
+ /**
+ * @var bool
+ */
+ private $alwaysSort;
+
+ private static function newFromGlobalState() {
+ $wikibaseClient = WikibaseClient::getDefaultInstance();
+ $settings = $wikibaseClient->getSettings();
+
+ $langLinkHandler = $wikibaseClient->getLangLinkHandler();
+
+ $interwikiSorter = new InterwikiSorter(
+ $settings->getSetting( 'sort' ),
+ $settings->getSetting( 'interwikiSortOrders' ),
+ $settings->getSetting( 'sortPrepend' )
+ );
+
+ return new ParserOutputHooks(
+ $wikibaseClient->getNamespaceChecker(),
+ $langLinkHandler,
+ $interwikiSorter,
+ $settings->getSetting( 'alwaysSort' )
+ );
+ }
+
+ /**
+ * Hook runs after internal parsing
+ * @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserAfterParse
+ *
+ * @param Parser &$parser
+ * @param string &$text
+ * @param StripState $stripState
+ *
+ * @return bool
+ */
+ public static function onParserAfterParse( Parser &$parser, &$text,
StripState $stripState ) {
+ // this hook tries to access repo SiteLinkTable
+ // it interferes with any test that parses something, like a
page or a message
+ if ( defined( 'MW_PHPUNIT_TEST' ) ) {
+ return true;
+ }
+
+ $handler = self::newFromGlobalState();
+ return $handler->doParserAfterParse( $parser, $text,
$stripState );
+ }
+
+ /**
+ * Static handler for the OutputPageParserOutput hook.
+ *
+ * @param OutputPage &$out
+ * @param ParserOutput $parserOutput
+ *
+ * @return bool
+ */
+ public static function onOutputPageParserOutput( OutputPage &$out,
ParserOutput $parserOutput ) {
+ $handler = self::newFromGlobalState();
+ return $handler->doOutputPageParserOutput( $out, $parserOutput
);
+ }
+
+ public function __construct(
+ NamespaceChecker $namespaceChecker,
+ LangLinkHandler $langLinkHandler,
+ InterwikiSorter $sorter,
+ $alwaysSort
+ ) {
+
+ $this->namespaceChecker = $namespaceChecker;
+ $this->langLinkHandler = $langLinkHandler;
+ $this->interwikiSorter = $sorter;
+ $this->alwaysSort = $alwaysSort;
+ }
+
+ /**
+ * Hook runs after internal parsing
+ * @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserAfterParse
+ *
+ * @param Parser &$parser
+ * @param string &$text
+ * @param StripState $stripState
+ *
+ * @return bool
+ */
+ public function doParserAfterParse( Parser &$parser, &$text, StripState
$stripState ) {
+ $title = $parser->getTitle();
+
+ if ( !$this->namespaceChecker->isWikibaseEnabled(
$title->getNamespace() ) ) {
+ // shorten out
+ return true;
+ }
+
+ wfProfileIn( __METHOD__ );
+
+ // @todo split up the multiple responsibilities here and in
lang link handler
+
+ // only run this once, for the article content and not
interface stuff
+ //FIXME: this also runs for messages in
EditPage::showEditTools! Ugh!
+ if ( $parser->getOptions()->getInterfaceMessage() ) {
+ wfProfileOut( __METHOD__ );
+ return true;
+ }
+
+ $parserOutput = $parser->getOutput();
+ $useRepoLinks = $this->langLinkHandler->useRepoLinks( $title,
$parserOutput );
+
+ try {
+ if ( $useRepoLinks ) {
+ // add links
+ $this->langLinkHandler->addLinksFromRepository(
$title, $parserOutput );
+ }
+
+ $this->langLinkHandler->updateItemIdProperty( $title,
$parserOutput );
+ $this->langLinkHandler->updateOtherProjectsLinksData(
$title, $parserOutput );
+ } catch ( Exception $e ) {
+ wfWarn( 'Failed to add repo links: ' . $e->getMessage()
);
+ }
+
+ if ( $useRepoLinks || $this->alwaysSort ) {
+ $interwikiLinks = $parserOutput->getLanguageLinks();
+ $sortedLinks = $this->interwikiSorter->sortLinks(
$interwikiLinks );
+ $parserOutput->setLanguageLinks( $sortedLinks );
+ }
+
+ wfProfileOut( __METHOD__ );
+ return true;
+ }
+
+ /**
+ * Add output page property if repo links are suppressed, and property
for item id
+ *
+ * @param OutputPage &$out
+ * @param ParserOutput $parserOutput
+ *
+ * @return bool
+ */
+ public function doOutputPageParserOutput( OutputPage &$out,
ParserOutput $parserOutput ) {
+ if ( !$this->namespaceChecker->isWikibaseEnabled(
$out->getTitle()->getNamespace() ) ) {
+ // shorten out
+ return true;
+ }
+
+ $noExternalLangLinks =
$this->langLinkHandler->getNoExternalLangLinks( $parserOutput );
+
+ if ( !empty( $noExternalLangLinks ) ) {
+ $out->setProperty( 'noexternallanglinks',
$noExternalLangLinks );
+ }
+
+ $itemId = $parserOutput->getProperty( 'wikibase_item' );
+
+ if ( $itemId !== false ) {
+ $out->setProperty( 'wikibase_item', $itemId );
+ }
+
+ $otherProjects = $parserOutput->getExtensionData(
'wikibase-otherprojects-sidebar' );
+
+ if ( $otherProjects !== null ) {
+ $out->setProperty( 'wikibase-otherprojects-sidebar',
$otherProjects );
+ }
+
+ return true;
+ }
+
+}
diff --git a/client/tests/phpunit/includes/hooks/ParserOutputHooksTest.php
b/client/tests/phpunit/includes/hooks/ParserOutputHooksTest.php
new file mode 100644
index 0000000..6019fa2
--- /dev/null
+++ b/client/tests/phpunit/includes/hooks/ParserOutputHooksTest.php
@@ -0,0 +1,365 @@
+<?php
+
+namespace Wikibase\Test;
+
+use FauxRequest;
+use MediaWikiSite;
+use OutputPage;
+use Parser;
+use ParserOptions;
+use ParserOutput;
+use RequestContext;
+use Site;
+use SiteStore;
+use StripState;
+use Title;
+use Wikibase\Client\Hooks\OtherProjectsSidebarGenerator;
+use Wikibase\Client\Hooks\ParserOutputHooks;
+use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\DataModel\SiteLink;
+use Wikibase\InterwikiSorter;
+use Wikibase\LangLinkHandler;
+use Wikibase\Lib\Store\SiteLinkLookup;
+use Wikibase\NamespaceChecker;
+use Wikibase\Settings;
+use Wikibase\SettingsArray;
+
+/**
+ * @covers Wikibase\Client\Hooks\ParserOutputHooks
+ *
+ * @group WikibaseClient
+ * @group Wikibase
+ * @group WikibaseHooks
+ *
+ * @licence GNU GPL v2+
+ * @author Daniel Kinzler
+ */
+class ParserOutputHooksTest extends \MediaWikiTestCase {
+
+ /**
+ * @param string $globalId
+ * @param string $group
+ * @param $language
+ *
+ * @return Site
+ */
+ private function newSite( $globalId, $group, $language ) {
+ $site = new MediaWikiSite();
+ $site->setGlobalId( $globalId );
+ $site->setGroup( $group );
+ $site->setLanguageCode( $language );
+ $site->addNavigationId( $language );
+ $site->setPagePath( 'wiki/' );
+ $site->setFilePath( 'w/' );
+ $site->setLinkPath( 'http://' . $globalId . '.test.com/wiki/$1'
);
+
+ return $site;
+ }
+
+ /**
+ * @return SiteStore
+ */
+ private function getSiteStore() {
+ $siteStore = new MockSiteStore( array(
+ $this->newSite( 'wikidatawiki', 'wikidata', 'en' ),
+ $this->newSite( 'commonswiki', 'commons', 'en' ),
+ $this->newSite( 'enwiki', 'wikipedia', 'en' ),
+ $this->newSite( 'dewiki', 'wikipedia', 'de' ),
+ ) );
+
+ return $siteStore;
+ }
+
+ /**
+ * @return SiteLinkLookup
+ */
+ private function getSiteLinkLookup() {
+ $lookup = $this->getMock( 'Wikibase\Lib\Store\SiteLinkLookup' );
+
+ $badgeQ7 = new ItemId( 'Q17' );
+
+ $links = array(
+ 'Q1' => array(
+ new SiteLink( 'dewiki', 'Sauerstoff', array(
$badgeQ7 ) ),
+ new SiteLink( 'enwiki', 'Oxygen' ),
+ new SiteLink( 'commonswiki', 'Oxygen' ),
+ ),
+ 'Q7' => array(
+ new SiteLink( 'dewiki', 'User:Foo' ),
+ new SiteLink( 'enwiki', 'User:Foo' ),
+ new SiteLink( 'commonswiki', 'User:Foo' ),
+ ),
+ );
+
+ $q1 = new ItemId( 'Q1' );
+
+ $items = array(
+ 'dewiki:Sauerstoff' => $q1,
+ 'enwiki:Oxygen' => $q1,
+ );
+
+ $lookup->expects( $this->any() )
+ ->method( 'getSiteLinksForItem' )
+ ->will( $this->returnCallback( function( ItemId $itemId
) use ( $links ) {
+ $key = $itemId->getSerialization();
+ return isset( $links[$key] ) ? $links[$key] :
array();
+ } ) );
+
+ $lookup->expects( $this->any() )
+ ->method( 'getEntityIdForSiteLink' )
+ ->will( $this->returnCallback( function( SiteLink $link
) use ( $items ) {
+ $key = $link->getSiteId() . ':' .
$link->getPageName();
+ return isset( $items[$key] ) ? $items[$key] :
null;
+ } ) );
+
+ return $lookup;
+ }
+
+ /**
+ * @param array $settings
+ *
+ * @return Settings
+ */
+ private function newSettings( array $settings ) {
+ $defaults = array(
+ 'sort' => 'code',
+ 'sortPrepend' => array(),
+ 'interwikiSortOrders' => array( 'alphabetic' => array(
+ 'ar', 'de', 'en', 'sv', 'zh'
+ ) ),
+ 'siteGlobalid' => 'enwiki',
+ 'languageLinkSiteGroup' => 'wikipedia',
+ 'namespaces' => array( NS_MAIN, NS_CATEGORY ),
+ 'alwaysSort' => false,
+ 'otherProjectsLinks' => array( 'commonswiki' ),
+ );
+
+ return new SettingsArray( array_merge( $defaults, $settings ) );
+ }
+
+ private function newParserOutputHooks( array $settings = array() ) {
+ $settings = $this->newSettings( $settings );
+
+ $siteId = $settings->getSetting( 'siteGlobalid' );
+ $siteGroup = $settings->getSetting( 'languageLinkSiteGroup' );
+ $namespaces = $settings->getSetting( 'namespaces' );
+ $otherProjectIds = $settings->getSetting( 'otherProjectsLinks'
);
+
+ $namespaceChecker = new NamespaceChecker( array(), $namespaces
);
+ $siteLinkLookup = $this->getSiteLinkLookup();
+ $siteStore = $this->getSiteStore();
+
+ $otherProjectsSidebarGenerator = new
OtherProjectsSidebarGenerator(
+ $siteId,
+ $siteLinkLookup,
+ $siteStore,
+ $otherProjectIds
+ );
+
+ $langLinkHandler = new LangLinkHandler(
+ $otherProjectsSidebarGenerator,
+ $siteId,
+ $namespaceChecker,
+ $siteLinkLookup,
+ $siteStore,
+ $siteGroup
+ );
+
+ $interwikiSorter = new InterwikiSorter(
+ $settings->getSetting( 'sort' ),
+ $settings->getSetting( 'interwikiSortOrders' ),
+ $settings->getSetting( 'sortPrepend' )
+ );
+
+ return new ParserOutputHooks(
+ $namespaceChecker,
+ $langLinkHandler,
+ $interwikiSorter,
+ $settings->getSetting( 'alwaysSort' )
+ );
+
+ }
+
+ private function newParser( Title $title, array $pageProps, array
$extensionData ) {
+ $popt = new ParserOptions();
+ $parser = new Parser();
+
+ $parser->startExternalParse( $title, $popt, Parser::OT_HTML );
+
+ $parserOutput = $parser->getOutput();
+ $this->primeParserOutput( $parserOutput, $pageProps,
$extensionData );
+
+ return $parser;
+ }
+
+ private function primeParserOutput( ParserOutput $parserOutput, array
$pageProps, array $extensionData ) {
+ foreach ( $pageProps as $name => $value ) {
+ $parserOutput->setProperty( $name, $value );
+ }
+
+ foreach ( $extensionData as $key => $value ) {
+ $parserOutput->setExtensionData( $key, $value );
+ }
+ }
+
+ public function parserAfterParseProvider() {
+ $commonsOxygen = array(
+ 'msg' => 'wikibase-otherprojects-commons',
+ 'class' => 'wb-otherproject-link
wb-otherproject-commons',
+ 'href' => 'http://commonswiki.test.com/wiki/Oxygen',
+ 'hreflang' => 'en',
+ );
+
+ return array(
+ 'repo-links' => array(
+ Title::makeTitle( NS_MAIN, 'Oxygen' ),
+ 'Q1',
+ array(),
+ array( 'de:Sauerstoff' ),
+ array( $commonsOxygen ),
+ ),
+
+ 'noexternallanglinks=*' => array(
+ Title::makeTitle( NS_MAIN, 'Oxygen' ),
+ 'Q1',
+ array( 'noexternallanglinks' => serialize(
array( '*' ) ) ),
+ array(),
+ array( $commonsOxygen ),
+ ),
+
+ 'noexternallanglinks=de' => array(
+ Title::makeTitle( NS_MAIN, 'Oxygen' ),
+ 'Q1',
+ array( 'noexternallanglinks' => serialize(
array( 'de' ) ) ),
+ array(),
+ array( $commonsOxygen ),
+ ),
+
+ 'noexternallanglinks=ja' => array(
+ Title::makeTitle( NS_MAIN, 'Oxygen' ),
+ 'Q1',
+ array( 'noexternallanglinks' => serialize(
array( 'ja' ) ) ),
+ array( 'de:Sauerstoff' ),
+ array( $commonsOxygen ),
+ ),
+
+ 'no-item' => array(
+ Title::makeTitle( NS_MAIN, 'Plutonium' ),
+ null,
+ array(),
+ array(),
+ array(),
+ ),
+
+ 'ignored-namespace' => array(
+ Title::makeTitle( NS_USER, 'Foo' ),
+ null,
+ array(),
+ array(),
+ null,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider parserAfterParseProvider
+ */
+ public function testDoParserAfterParse(
+ Title $title,
+ $expectedItem,
+ array $pagePropsBefore,
+ array $expectedLanguageLinks = null,
+ array $expectedSisterLinks = null
+ ) {
+ $parser = $this->newParser( $title, $pagePropsBefore, array() );
+ $handler = $this->newParserOutputHooks();
+
+ $text = '';
+ $stripState = new StripState( 'x' );
+
+ $handler->doParserAfterParse( $parser, $text, $stripState );
+
+ $parserOutput = $parser->getOutput();
+ $this->assertEquals( $expectedItem, $parserOutput->getProperty(
'wikibase_item' ) );
+ $this->assertLanguageLinks( $expectedLanguageLinks,
$parserOutput );
+ $this->assertSisterLinks( $expectedSisterLinks,
$parserOutput->getExtensionData( 'wikibase-otherprojects-sidebar' ) );
+ }
+
+ public function testDoOutputPageParserOutput() {
+ $title = Title::makeTitle( NS_MAIN, 'Oxygen' );
+
+ $sisterLinks = array(
+ array(
+ 'msg' => 'wikibase-otherprojects-test',
+ 'class' => 'wb-otherproject-link
wb-otherproject-test',
+ 'href' => 'http://acme.tests.com/wiki/Foo'
+ ),
+ );
+
+ $pageProps = array(
+ 'noexternallanglinks' => serialize( array( '*' ) ),
+ 'wikibase_item' => 'Q1',
+ );
+
+ $extData = array(
+ 'wikibase-otherprojects-sidebar' => $sisterLinks,
+ );
+
+ $outputProps = array(
+ 'noexternallanglinks' => array( '*' ),
+ 'wikibase_item' => 'Q1',
+ 'wikibase-otherprojects-sidebar' => $sisterLinks,
+ );
+
+ $handler = $this->newParserOutputHooks();
+
+ $parserOutput = new ParserOutput();
+
+ $context = new RequestContext( new FauxRequest() );
+ $outputPage = new OutputPage( $context );
+ $outputPage->setTitle( $title );
+
+ $this->primeParserOutput( $parserOutput, $pageProps, $extData );
+
+ $handler->doOutputPageParserOutput( $outputPage, $parserOutput
);
+
+ $this->assertOutputPageProperties( $outputProps, $outputPage );
+ }
+
+ private function assertOutputPageProperties( $props, OutputPage
$outputPage ) {
+ $this->assertInternalType( 'array', $props );
+
+ foreach ( $props as $key => $value ) {
+ $this->assertEquals( $value, $outputPage->getProperty(
$key ), 'OutputProperty: ' . $key );
+ }
+ }
+
+ private function assertLanguageLinks( $links, ParserOutput
$parserOutput ) {
+ $this->assertInternalType( 'array', $links );
+
+ $actualLinks = $parserOutput->getLanguageLinks();
+
+ foreach ( $links as $link ) {
+ $this->assertContains( $link, $actualLinks,
'LanguageLink: ' );
+ }
+
+ $this->assertSameSize( $links, $actualLinks, 'Unmatched
languageLinks!' );
+ }
+
+
+ private function assertSisterLinks( $expectedLinks, $actualLinks ) {
+ if ( !is_array( $expectedLinks ) ) {
+ $this->assertEquals( $expectedLinks, $actualLinks );
+ return;
+ }
+
+ $this->assertSameSize( $expectedLinks, $actualLinks,
'SisterLinks' );
+
+ $actual = reset( $actualLinks );
+ foreach ( $expectedLinks as $expected ) {
+ $this->assertEquals( $expected, $actual, 'SisterLink: '
);
+ $actual = next( $actualLinks );
+ }
+ }
+
+}
--
To view, visit https://gerrit.wikimedia.org/r/159078
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5a76107fb9e02c94d75205738858a57b1175ac56
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Bene <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: JanZerebecki <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits