Anomie has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/363633 )

Change subject: Update RecentChange attributes handling for core change 
Ic3a434c0
......................................................................

Update RecentChange attributes handling for core change Ic3a434c0

Creating a RecentChange object by passing a fake row is somewhat fragile
if the contents of said row ever change, as is happening in Ic3a434c0.

This change updates Wikibase for Ic3a434c0 in a manner that should be
compatible with core both before and after that change.

Change-Id: I4a1236a81098ec0e924c0569a9b146478bbc235c
---
M client/includes/RecentChanges/RecentChangeFactory.php
M client/tests/phpunit/includes/RecentChanges/ChangeLineFormatterTest.php
M client/tests/phpunit/includes/RecentChanges/ExternalChangeFactoryTest.php
M client/tests/phpunit/includes/RecentChanges/RecentChangeFactoryTest.php
M 
client/tests/phpunit/includes/RecentChanges/RecentChangesDuplicateDetectorTest.php
M lib/tests/phpunit/Changes/EntityChangeTest.php
6 files changed, 42 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/33/363633/1

diff --git a/client/includes/RecentChanges/RecentChangeFactory.php 
b/client/includes/RecentChanges/RecentChangeFactory.php
index acfe273..bcc2f56 100644
--- a/client/includes/RecentChanges/RecentChangeFactory.php
+++ b/client/includes/RecentChanges/RecentChangeFactory.php
@@ -57,6 +57,16 @@
 
                $targetSpecificAttributes = 
$this->buildTargetSpecificAttributes( $change, $target );
                $attribs = array_merge( $preparedAttribs, 
$targetSpecificAttributes );
+
+               // Creating a RecentChange by passing a faked-up row needs the 
correct
+               // fields, which are changing in Ic3a434c0.
+               if ( class_exists( \CommentStore::class ) ) {
+                       $attribs += [
+                               'rc_comment_text' => $attribs['rc_comment'],
+                               'rc_comment_data' => null,
+                       ];
+               }
+
                $rc = RecentChange::newFromRow( (object)$attribs );
                $rc->setExtra( [ 'pageStatus' => 'changed' ] );
 
@@ -102,10 +112,10 @@
                        'wikibase-repo-change' => $metadata,
                ];
 
-               return [
+               $attribs = [
                        'rc_user' => 0,
                        'rc_user_text' => $userText,
-                       'rc_comment' => $this->getEditCommentMulti( $change ),
+                       'rc_comment' => trim( $this->getEditCommentMulti( 
$change ) ),
                        'rc_type' => RC_EXTERNAL,
                        'rc_minor' => true, // for now, always consider these 
minor
                        'rc_bot' => $isBot,
@@ -118,6 +128,17 @@
                        'rc_deleted' => false,
                        'rc_new' => false,
                ];
+
+               // Creating a RecentChange by passing a faked-up row needs the 
correct
+               // fields, which are changing in Ic3a434c0.
+               if ( class_exists( \CommentStore::class ) ) {
+                       $attribs += [
+                               'rc_comment_text' => $attribs['rc_comment'],
+                               'rc_comment_data' => null,
+                       ];
+               }
+
+               return $attribs;
        }
 
        /**
diff --git 
a/client/tests/phpunit/includes/RecentChanges/ChangeLineFormatterTest.php 
b/client/tests/phpunit/includes/RecentChanges/ChangeLineFormatterTest.php
index d340601..84d9aab 100644
--- a/client/tests/phpunit/includes/RecentChanges/ChangeLineFormatterTest.php
+++ b/client/tests/phpunit/includes/RecentChanges/ChangeLineFormatterTest.php
@@ -523,6 +523,8 @@
                        'rc_namespace' => $title->getNamespace(),
                        'rc_title' => $title->getDBkey(),
                        'rc_comment' => $comment,
+                       'rc_comment_text' => $comment, // For Ic3a434c0
+                       'rc_comment_data' => null,
                        'rc_minor' => true,
                        'rc_bot' => $params['wikibase-repo-change']['bot'],
                        'rc_new' => false,
diff --git 
a/client/tests/phpunit/includes/RecentChanges/ExternalChangeFactoryTest.php 
b/client/tests/phpunit/includes/RecentChanges/ExternalChangeFactoryTest.php
index 4d5e94c..adb0b84 100644
--- a/client/tests/phpunit/includes/RecentChanges/ExternalChangeFactoryTest.php
+++ b/client/tests/phpunit/includes/RecentChanges/ExternalChangeFactoryTest.php
@@ -341,6 +341,8 @@
                        'rc_namespace' => 0,
                        'rc_title' => 'Canada',
                        'rc_comment' => '',
+                       'rc_comment_text' => '', // For Ic3a434c0
+                       'rc_comment_data' => null,
                        'rc_minor' => 1,
                        'rc_bot' => $bot ? 1 : 0,
                        'rc_new' => 0,
diff --git 
a/client/tests/phpunit/includes/RecentChanges/RecentChangeFactoryTest.php 
b/client/tests/phpunit/includes/RecentChanges/RecentChangeFactoryTest.php
index b56fbd5..96b624f 100644
--- a/client/tests/phpunit/includes/RecentChanges/RecentChangeFactoryTest.php
+++ b/client/tests/phpunit/includes/RecentChanges/RecentChangeFactoryTest.php
@@ -234,7 +234,7 @@
 
                $rc = $factory->newRecentChange( $change, $target, 
$preparedAttribs );
 
-               $this->assertRCEquals( $expected, $rc->getAttributes() );
+               $this->assertRCEquals( $expected, array_intersect_key( 
$rc->getAttributes(), $expected ) );
        }
 
        private function assertRCEquals( array $expected, array $actual ) {
diff --git 
a/client/tests/phpunit/includes/RecentChanges/RecentChangesDuplicateDetectorTest.php
 
b/client/tests/phpunit/includes/RecentChanges/RecentChangesDuplicateDetectorTest.php
index 5f0dbf2..2331546 100644
--- 
a/client/tests/phpunit/includes/RecentChanges/RecentChangesDuplicateDetectorTest.php
+++ 
b/client/tests/phpunit/includes/RecentChanges/RecentChangesDuplicateDetectorTest.php
@@ -192,6 +192,16 @@
 
                $changeData = array_merge( $defaults, $changeData );
 
+               // The faked-up RecentChange row needs to have the proper 
fields for
+               // MediaWiki core change Ic3a434c0. And can't have them without 
that
+               // patch or the ->save() in initRecentChanges() will fail.
+               if ( class_exists( \CommentStore::class ) ) {
+                       $changeData += [
+                               'rc_comment_text' => $changeData['rc_comment'],
+                               'rc_comment_data' => null,
+                       ];
+               }
+
                $change = RecentChange::newFromRow( (object)$changeData );
                $change->setExtra( [
                        'pageStatus' => 'changed'
diff --git a/lib/tests/phpunit/Changes/EntityChangeTest.php 
b/lib/tests/phpunit/Changes/EntityChangeTest.php
index 0cf4635..9deb658 100644
--- a/lib/tests/phpunit/Changes/EntityChangeTest.php
+++ b/lib/tests/phpunit/Changes/EntityChangeTest.php
@@ -146,7 +146,11 @@
                $row->rc_cur_id = 6;
                $row->rc_bot = 1;
                $row->rc_deleted = 0;
+               // The faked-up RecentChange row needs to have the proper 
fields for
+               // MediaWiki core change Ic3a434c0.
                $row->rc_comment = 'Test!';
+               $row->rc_comment_text = 'Test!';
+               $row->rc_comment_data = null;
 
                $rc = RecentChange::newFromRow( $row );
 

-- 
To view, visit https://gerrit.wikimedia.org/r/363633
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4a1236a81098ec0e924c0569a9b146478bbc235c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to