jenkins-bot has submitted this change and it was merged.
Change subject: add tests for MovePageNotice
......................................................................
add tests for MovePageNotice
Change-Id: Ia4aa9907f7da135d38f325bc8a567ab96ca3f59c
---
M client/WikibaseClient.hooks.php
M client/includes/hooks/MovePageNotice.php
A client/tests/phpunit/includes/hooks/MovePageNoticeTest.php
3 files changed, 140 insertions(+), 48 deletions(-)
Approvals:
Addshore: Looks good to me, approved
jenkins-bot: Verified
diff --git a/client/WikibaseClient.hooks.php b/client/WikibaseClient.hooks.php
index f8144f3..d5ac7cb 100644
--- a/client/WikibaseClient.hooks.php
+++ b/client/WikibaseClient.hooks.php
@@ -2,10 +2,12 @@
namespace Wikibase;
use IContextSource;
+use MovePageForm;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use SplFileInfo;
use SiteSQLStore;
+use Title;
use Wikibase\Client\WikibaseClient;
use Wikibase\Client\MovePageNotice;
use Wikibase\DataModel\SimpleSiteLink;
@@ -171,13 +173,13 @@
*
* @since 0.3
*
- * @param \MovePageForm $movePage
- * @param \Title &$oldTitle
- * @param \Title &$newTitle
+ * @param MovePageForm $movePage
+ * @param Title &$oldTitle
+ * @param Title &$newTitle
*
* @return bool
*/
- public static function onSpecialMovepageAfterMove( \MovePageForm
$movePage, \Title &$oldTitle, \Title &$newTitle ) {
+ public static function onSpecialMovepageAfterMove( MovePageForm
$movePage, Title &$oldTitle, Title &$newTitle ) {
$siteLinkLookup =
WikibaseClient::getDefaultInstance()->getStore()->getSiteLinkTable();
$repoLinker =
WikibaseClient::getDefaultInstance()->newRepoLinker();
@@ -187,12 +189,15 @@
$repoLinker
);
- $movePageNotice->reportRepoUpdate(
- $movePage->getOutput(),
+ $html = $movePageNotice->getPageMoveNoticeHtml(
$oldTitle,
$newTitle
);
+ $out = $movePage->getOutput();
+ $out->addModules( 'wikibase.client.page-move' );
+ $out->addHTML( $html );
+
return true;
}
diff --git a/client/includes/hooks/MovePageNotice.php
b/client/includes/hooks/MovePageNotice.php
index 445ece4..dae5864 100644
--- a/client/includes/hooks/MovePageNotice.php
+++ b/client/includes/hooks/MovePageNotice.php
@@ -1,6 +1,10 @@
<?php
namespace Wikibase\Client;
+
+use Html;
+use OutputPage;
+use Title;
use Wikibase\SiteLinkLookup;
use Wikibase\RepoLinker;
use Wikibase\DataModel\SimpleSiteLink;
@@ -9,25 +13,7 @@
* Adds a notice about the Wikibase Item belonging to the current page
* after a move (in case there's one).
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
* @since 0.4
- *
- * @file
- * @ingroup WikibaseClient
*
* @licence GNU GPL v2+
* @author Marius Hoch < [email protected] >
@@ -36,7 +22,7 @@
final class MovePageNotice {
/**
- * @var \SiteLinkLookup
+ * @var SiteLinkLookup
*/
protected $siteLinkLookup;
@@ -51,9 +37,9 @@
protected $repoLinker;
/**
- * @param Wikibase\SiteLinkLookup $siteLinkLookup
+ * @param SiteLinkLookup $siteLinkLookup
* @param string $siteId Global id of the client wiki
- * @param Wikibase\RepoLinker $repoLinker
+ * @param RepoLinker $repoLinker
*/
public function __construct( SiteLinkLookup $siteLinkLookup, $siteId,
RepoLinker $repoLinker ) {
$this->siteLinkLookup = $siteLinkLookup;
@@ -65,11 +51,11 @@
* Create a repo link directly to the item.
* We can't use Special:ItemByTitle here as the item might have already
been updated.
*
- * @param \Title $title
+ * @param Title $title
*
* @return string|null
*/
- protected function getItemUrl( $title ) {
+ protected function getItemUrl( Title $title ) {
$entityId = $this->siteLinkLookup->getEntityIdForSiteLink(
new SimpleSiteLink(
$this->siteId,
@@ -87,33 +73,39 @@
/**
* Append the appropriate content to the page
*
- * @param \OutputPage $output
- * @param \Title $oldTitle Title of the page before the move
- * @param \Title $newTitle Title of the page after the move
+ * @param OutputPage $output
+ * @param Title $oldTitle Title of the page before the move
+ * @param Title $newTitle Title of the page after the move
*/
- public function reportRepoUpdate( \OutputPage $out, \Title $oldTitle,
\Title $newTitle ) {
+ public function getPageMoveNoticeHtml( Title $oldTitle, Title $newTitle
) {
$itemLink = $this->getItemUrl( $oldTitle );
if ( !$itemLink ) {
return;
}
- if ( isset( $newTitle->wikibasePushedMoveToRepo ) ) {
- // We're going to update the item using the repo job
queue \o/
- $msg = 'wikibase-after-page-move-queued';
- } else {
- // The user has to update the item per hand for some
reason
- $msg = 'wikibase-after-page-move';
- }
+ $msg = $this->getPageMoveMessage( $newTitle );
- $out->addModules( 'wikibase.client.page-move' );
- $out->addHTML(
- \Html::rawElement(
- 'div',
- array( 'id' => 'wbc-after-page-move',
- 'class' => 'plainlinks' ),
- wfMessage( $msg, $itemLink )->parse()
- )
+ $html = Html::rawElement(
+ 'div',
+ array(
+ 'id' => 'wbc-after-page-move',
+ 'class' => 'plainlinks'
+ ),
+ wfMessage( $msg, $itemLink )->parse()
);
+
+ return $html;
}
+
+ protected function getPageMoveMessage( Title $newTitle ) {
+ if ( isset( $newTitle->wikibasePushedMoveToRepo ) && (
$newTitle->wikibasePushedMoveToRepo === true ) ) {
+ // We're going to update the item using the repo job queue \o/
+ return 'wikibase-after-page-move-queued';
+ }
+
+ // The user has to update the item per hand for some reason
+ return 'wikibase-after-page-move';
+ }
+
}
diff --git a/client/tests/phpunit/includes/hooks/MovePageNoticeTest.php
b/client/tests/phpunit/includes/hooks/MovePageNoticeTest.php
new file mode 100644
index 0000000..63100b4
--- /dev/null
+++ b/client/tests/phpunit/includes/hooks/MovePageNoticeTest.php
@@ -0,0 +1,95 @@
+<?php
+
+namespace Wikibase\Test;
+
+use Language;
+use Title;
+use Wikibase\Client\MovePageNotice;
+use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\DataModel\SimpleSiteLink;
+use Wikibase\RepoLinker;
+
+/**
+ * @covers Wikibase\Client\PageMoveNotice
+ *
+ * @since 0.4
+ *
+ * @group WikibaseClient
+ * @group Database
+ *
+ * @licence GNU GPL v2+
+ * @author Katie Filbert < [email protected] >
+ */
+class MovePageNoticeTest extends \MediaWikiTestCase {
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->setMwGlobals( array(
+ 'wgLang' => Language::factory( 'de' )
+ ) );
+ }
+
+ protected function getRepoLinker() {
+ $baseUrl = 'http://www.example.com';
+ $articlePath = '/wiki/$1';
+ $scriptPath = '';
+ $repoNamespaces = array(
+ 'wikibase-item' => '',
+ 'wikibase-property' => 'Property:'
+ );
+
+ return new RepoLinker( $baseUrl, $articlePath, $scriptPath,
$repoNamespaces );
+ }
+
+ /**
+ * @dataProvider getMovePageNoticeHtmlProvider
+ */
+ public function testGetMovePageNoticeHtml( $expected, Title $oldTitle,
Title $newTitle, $message ) {
+ $siteLinkLookup = $this->getMock(
+ 'Wikibase\SiteLinkTable',
+ array( 'getEntityIdForSiteLink' ),
+ array( 'SiteLinkTable', true )
+ );
+
+ $siteLinkLookup->expects( $this->any() )
+ ->method( 'getEntityIdForSiteLink' )
+ ->with( new SimpleSiteLink( 'dewiki', 'New Amsterdam' )
)
+ ->will( $this->returnValue( new ItemId( 'Q4880' ) ) );
+
+ $movePageNotice = new MovePageNotice(
+ $siteLinkLookup,
+ 'dewiki',
+ $this->getRepoLinker()
+ );
+
+ $this->assertEquals(
+ $expected,
+ $movePageNotice->getPageMoveNoticeHtml( $oldTitle,
$newTitle ),
+ $message
+ );
+ }
+
+ public function getMovePageNoticeHtmlProvider() {
+ $oldTitle = Title::newFromText( 'New Amsterdam' );
+ $newTitle = Title::newFromText( 'New York City' );
+ $expected = $this->getParsedMessage( 'wikibase-after-page-move'
);
+
+ $newTitle2 = Title::newFromText( 'New York' );
+ $newTitle2->wikibasePushedMoveToRepo = true;
+ $expected2 = $this->getParsedMessage(
'wikibase-after-page-move-queued' );
+
+ return array(
+ array( $expected, $oldTitle, $newTitle, 'after page
move' ),
+ array( $expected2, $oldTitle, $newTitle2, 'page move
queued' )
+ );
+ }
+
+ protected function getParsedMessage( $messageKey ) {
+ return '<div id="wbc-after-page-move" class="plainlinks">'
+ . wfMessage( $messageKey,
'http://www.example.com/wiki/Q4880' )
+ ->inLanguage( 'de' )->parse()
+ . '</div>';
+ }
+
+}
--
To view, visit https://gerrit.wikimedia.org/r/91553
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia4aa9907f7da135d38f325bc8a567ab96ca3f59c
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits