Daniel Kinzler has uploaded a new change for review.
https://gerrit.wikimedia.org/r/82812
Change subject: Make ExternalChangeLine more robust.
......................................................................
Make ExternalChangeLine more robust.
This removes some assumptions from ExternalChangeLine.
This also adds a test case for ExternalChangeLine, but does
not fully implement it.
Change-Id: I63b62e60ffee2f2c3af8c445f3723f6d68018442
---
M client/includes/recentchanges/ExternalChangesLine.php
A client/tests/phpunit/includes/recentchanges/ExternalChangesLineTest.php
2 files changed, 103 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/12/82812/1
diff --git a/client/includes/recentchanges/ExternalChangesLine.php
b/client/includes/recentchanges/ExternalChangesLine.php
index 7c1cf18..988d5f5 100644
--- a/client/includes/recentchanges/ExternalChangesLine.php
+++ b/client/includes/recentchanges/ExternalChangesLine.php
@@ -147,12 +147,16 @@
if ( is_array( $comment ) ) {
if ( $entityData['type'] === 'wikibase-item~add' ) {
// @todo: provide a link to the entity
+ // @todo: move this to SiteLinkCommentCreator
$message = wfMessage( 'wikibase-comment-linked'
)->text();
} else if ( array_key_exists( 'sitelink', $comment ) ) {
// @fixme site link change message
$message = wfMessage( 'wikibase-comment-update'
)->text();
- } else {
+ } elseif ( array_key_exists( 'message', $comment ) ) {
$message = wfMessage( $comment['message']
)->text();
+ } else {
+ wfLogWarning( __METHOD__ . ': comment array is
missing "message" field!' );
+ $message = wfMessage( 'wikibase-comment-update'
)->text();
}
} else {
$msg = wfMessage( $comment );
diff --git
a/client/tests/phpunit/includes/recentchanges/ExternalChangesLineTest.php
b/client/tests/phpunit/includes/recentchanges/ExternalChangesLineTest.php
new file mode 100644
index 0000000..e764032
--- /dev/null
+++ b/client/tests/phpunit/includes/recentchanges/ExternalChangesLineTest.php
@@ -0,0 +1,98 @@
+<?php
+
+namespace Wikibase\Client\Test;
+use Wikibase\ExternalChangesLine;
+
+/**
+ * @covers Wikibase\ExternalChangesLine
+ *
+ * @since 0.1
+ *
+ * @ingroup WikibaseClient
+ * @ingroup Test
+ *
+ * @group Wikibase
+ * @group WikibaseClient
+ * @group WikibaseChange
+ *
+ * @license GPL 2+
+ * @author Daniel Kinzler
+ */
+class ExternalChangesLineTest extends \PHPUnit_Framework_TestCase {
+
+ /**
+ */
+ public function testChangesLine( /* $cl, $rc */ ) {
+ $this->markTestIncomplete( 'Test me!' );
+ }
+
+ /**
+ * @dataProvider parseCommentProvider
+ */
+ public function testParseComment( $entityData, $expected, $warnings =
'fail' ) {
+ if ( $warnings === 'suppress' ) {
+ wfSuppressWarnings();
+ }
+
+ $actual = ExternalChangesLine::parseComment( $entityData );
+ $this->assertEquals( $expected, $actual );
+
+ if ( $warnings === 'suppress' ) {
+ wfRestoreWarnings();
+ }
+ }
+
+ public static function parseCommentProvider() {
+ return array(
+ 'plain string' => array(
+ array(
+ 'type' => 'wikibase-item~change',
+ 'comment' => 'wikibase-comment-update',
+ ),
+ wfMessage( 'wikibase-comment-update' )->text()
+ ),
+ 'wikibase-item~add' => array(
+ array(
+ 'type' => 'wikibase-item~add',
+ 'comment' => array( 'message' =>
'wikibase-comment-update' ),
+ // comment will be ignored, but must be
an array
+ ),
+ wfMessage( 'wikibase-comment-linked' )->text()
+ ),
+ 'message array' => array(
+ array(
+ 'type' => 'wikibase-item~restore',
+ 'comment' => array( 'message' =>
'wikibase-comment-restore' ),
+ ),
+ wfMessage( 'wikibase-comment-restore' )->text()
+ ),
+ 'broken message array' => array(
+ array(
+ 'type' => 'wikibase-item~restore',
+ 'comment' => array( 'foo' =>
'wikibase-comment-restore' ),
+ ),
+ wfMessage( 'wikibase-comment-update' )->text(),
+ 'suppress'
+ ),
+ );
+ }
+
+ /**
+ */
+ public function testGetComment( /* $entityData */ ) {
+ $this->markTestIncomplete( 'Test me!' );
+ }
+
+ /**
+ */
+ public function testGetTimestamp( /* $cl, $rc */ ) {
+ $this->markTestIncomplete( 'Test me!' );
+ }
+
+ /**
+ */
+ public function testUserLinks( /* $cl, $userName */ ) {
+ $this->markTestIncomplete( 'Test me!' );
+ }
+
+}
--
To view, visit https://gerrit.wikimedia.org/r/82812
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I63b62e60ffee2f2c3af8c445f3723f6d68018442
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits