Umherirrender has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/200320

Change subject: [PoC] Add unit tests for all LogFormatters
......................................................................

[PoC] Add unit tests for all LogFormatters

Test the LogFormatter by passing old and new database rows to it.

Change-Id: Icfcba506f4fa3010cdaf973aa2df23b6e92c25e4
---
M tests/TestsAutoLoader.php
A tests/phpunit/includes/logging/BlockLogFormatterTest.php
A tests/phpunit/includes/logging/DeleteLogFormatterTest.php
A tests/phpunit/includes/logging/LogFormatterTestCase.php
A tests/phpunit/includes/logging/MergeLogFormatterTest.php
A tests/phpunit/includes/logging/MoveLogFormatterTest.php
A tests/phpunit/includes/logging/NewUsersLogFormatterTest.php
A tests/phpunit/includes/logging/PageLangLogFormatterTest.php
A tests/phpunit/includes/logging/PatrolLogFormatterTest.php
A tests/phpunit/includes/logging/ProtectLogFormatterTest.php
A tests/phpunit/includes/logging/RightsLogFormatterTest.php
11 files changed, 1,802 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/20/200320/1

diff --git a/tests/TestsAutoLoader.php b/tests/TestsAutoLoader.php
index b0f29d5..fa29482 100644
--- a/tests/TestsAutoLoader.php
+++ b/tests/TestsAutoLoader.php
@@ -82,6 +82,9 @@
        # tests/phpunit/includes/diff
        'FakeDiffOp' => "$testDir/phpunit/includes/diff/FakeDiffOp.php",
 
+       # tests/phpunit/includes/logging
+       'LogFormatterTestCase' => 
"$testDir/phpunit/includes/logging/LogFormatterTestCase.php",
+
        # tests/phpunit/includes/passwords
        'PasswordTestCase' => 
"$testDir/phpunit/includes/password/PasswordTestCase.php",
 
diff --git a/tests/phpunit/includes/logging/BlockLogFormatterTest.php 
b/tests/phpunit/includes/logging/BlockLogFormatterTest.php
new file mode 100644
index 0000000..34c9f20
--- /dev/null
+++ b/tests/phpunit/includes/logging/BlockLogFormatterTest.php
@@ -0,0 +1,335 @@
+<?php
+
+class BlockLogFormatterTest extends LogFormatterTestCase {
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideBlockLogDatabaseRows() {
+               return array(
+                       // Current log format
+                       array(
+                               array(
+                                       'type' => 'block',
+                                       'action' => 'block',
+                                       'comment' => 'Block comment',
+                                       'user' => 0,
+                                       'user_text' => 'Sysop',
+                                       'namespace' => NS_USER,
+                                       'title' => 'Logtestuser',
+                                       'params' => array(
+                                               '5::duration' => 'infinite',
+                                               '6::flags' => 'anononly',
+                                       ),
+                               ),
+                               array(
+                                       'key' => 'logentry-block-block',
+                                       'paramCount' => 6,
+                               ),
+                       ),
+
+                       // Old legacy log
+                       array(
+                               array(
+                                       'type' => 'block',
+                                       'action' => 'block',
+                                       'comment' => 'Block comment',
+                                       'user' => 0,
+                                       'user_text' => 'Sysop',
+                                       'namespace' => NS_USER,
+                                       'title' => 'Logtestuser',
+                                       'params' => array(
+                                               'infinite',
+                                               'anononly',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-block-block',
+                                       'paramCount' => 6,
+                               ),
+                       ),
+
+                       // Old legacy log without flag
+                       array(
+                               array(
+                                       'type' => 'block',
+                                       'action' => 'block',
+                                       'comment' => 'Block comment',
+                                       'user' => 0,
+                                       'user_text' => 'Sysop',
+                                       'namespace' => NS_USER,
+                                       'title' => 'Logtestuser',
+                                       'params' => array(
+                                               'infinite',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-block-block',
+                                       'paramCount' => 6,
+                               ),
+                       ),
+
+                       // Very old legacy log without duration
+                       array(
+                               array(
+                                       'type' => 'block',
+                                       'action' => 'block',
+                                       'comment' => 'Block comment',
+                                       'user' => 0,
+                                       'user_text' => 'Sysop',
+                                       'namespace' => NS_USER,
+                                       'title' => 'Logtestuser',
+                                       'params' => array(),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-block-block',
+                                       'paramCount' => 6,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideBlockLogDatabaseRows
+        */
+       public function testBlockLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideReblockLogDatabaseRows() {
+               return array(
+                       // Current log format
+                       array(
+                               array(
+                                       'type' => 'block',
+                                       'action' => 'reblock',
+                                       'comment' => 'Block comment',
+                                       'user' => 0,
+                                       'user_text' => 'Sysop',
+                                       'namespace' => NS_USER,
+                                       'title' => 'Logtestuser',
+                                       'params' => array(
+                                               '5::duration' => 'infinite',
+                                               '6::flags' => 'anononly',
+                                       ),
+                               ),
+                               array(
+                                       'key' => 'logentry-block-reblock',
+                                       'paramCount' => 6,
+                               ),
+                       ),
+
+                       // Old log
+                       array(
+                               array(
+                                       'type' => 'block',
+                                       'action' => 'reblock',
+                                       'comment' => 'Block comment',
+                                       'user' => 0,
+                                       'user_text' => 'Sysop',
+                                       'namespace' => NS_USER,
+                                       'title' => 'Logtestuser',
+                                       'params' => array(
+                                               'infinite',
+                                               'anononly',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-block-reblock',
+                                       'paramCount' => 6,
+                               ),
+                       ),
+
+                       // Older log without flag
+                       array(
+                               array(
+                                       'type' => 'block',
+                                       'action' => 'reblock',
+                                       'comment' => 'Block comment',
+                                       'user' => 0,
+                                       'user_text' => 'Sysop',
+                                       'namespace' => NS_USER,
+                                       'title' => 'Logtestuser',
+                                       'params' => array(
+                                               'infinite',
+                                       )
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-block-reblock',
+                                       'paramCount' => 6,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideReblockLogDatabaseRows
+        */
+       public function testRelockLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideUnblockLogDatabaseRows() {
+               return array(
+                       // Current log format
+                       array(
+                               array(
+                                       'type' => 'block',
+                                       'action' => 'unblock',
+                                       'comment' => 'Block comment',
+                                       'user' => 0,
+                                       'user_text' => 'Sysop',
+                                       'namespace' => NS_USER,
+                                       'title' => 'Logtestuser',
+                                       'params' => array(),
+                               ),
+                               array(
+                                       'key' => 'logentry-block-unblock',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideUnblockLogDatabaseRows
+        */
+       public function testUnblockLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideSuppressBlockLogDatabaseRows() {
+               return array(
+                       // Current log format
+                       array(
+                               array(
+                                       'type' => 'suppress',
+                                       'action' => 'block',
+                                       'comment' => 'Block comment',
+                                       'user' => 0,
+                                       'user_text' => 'Sysop',
+                                       'namespace' => NS_USER,
+                                       'title' => 'Logtestuser',
+                                       'params' => array(
+                                               '5::duration' => 'infinite',
+                                               '6::flags' => 'anononly',
+                                       ),
+                               ),
+                               array(
+                                       'key' => 'logentry-suppress-block',
+                                       'paramCount' => 6,
+                               ),
+                       ),
+
+                       // legacy log
+                       array(
+                               array(
+                                       'type' => 'suppress',
+                                       'action' => 'block',
+                                       'comment' => 'Block comment',
+                                       'user' => 0,
+                                       'user_text' => 'Sysop',
+                                       'namespace' => NS_USER,
+                                       'title' => 'Logtestuser',
+                                       'params' => array(
+                                               'infinite',
+                                               'anononly',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-suppress-block',
+                                       'paramCount' => 6,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideSuppressBlockLogDatabaseRows
+        */
+       public function testSuppressBlockLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideSuppressReblockLogDatabaseRows() {
+               return array(
+                       // Current log format
+                       array(
+                               array(
+                                       'type' => 'suppress',
+                                       'action' => 'reblock',
+                                       'comment' => 'Block comment',
+                                       'user' => 0,
+                                       'user_text' => 'Sysop',
+                                       'namespace' => NS_USER,
+                                       'title' => 'Logtestuser',
+                                       'params' => array(
+                                               '5::duration' => 'infinite',
+                                               '6::flags' => 'anononly',
+                                       ),
+                               ),
+                               array(
+                                       'key' => 'logentry-suppress-reblock',
+                                       'paramCount' => 6,
+                               ),
+                       ),
+
+                       // Legacy format
+                       array(
+                               array(
+                                       'type' => 'suppress',
+                                       'action' => 'reblock',
+                                       'comment' => 'Block comment',
+                                       'user' => 0,
+                                       'user_text' => 'Sysop',
+                                       'namespace' => NS_USER,
+                                       'title' => 'Logtestuser',
+                                       'params' => array(
+                                               'infinite',
+                                               'anononly',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-suppress-reblock',
+                                       'paramCount' => 6,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideSuppressReblockLogDatabaseRows
+        */
+       public function testSuppressRelockLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+}
diff --git a/tests/phpunit/includes/logging/DeleteLogFormatterTest.php 
b/tests/phpunit/includes/logging/DeleteLogFormatterTest.php
new file mode 100644
index 0000000..0bbbcd7
--- /dev/null
+++ b/tests/phpunit/includes/logging/DeleteLogFormatterTest.php
@@ -0,0 +1,383 @@
+<?php
+
+class DeleteLogFormatterTest extends LogFormatterTestCase {
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideDeleteLogDatabaseRows() {
+               return array(
+                       // Current format
+                       array(
+                               array(
+                                       'type' => 'delete',
+                                       'action' => 'delete',
+                                       'comment' => 'delete comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'Page',
+                                       'params' => array(),
+                               ),
+                               array(
+                                       'key' => 'logentry-delete-delete',
+                                       'paramCount' => 3,
+                               ),
+                       ),
+
+                       // Legacy format
+                       array(
+                               array(
+                                       'type' => 'delete',
+                                       'action' => 'delete',
+                                       'comment' => 'delete comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'Page',
+                                       'params' => array(),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-delete-delete',
+                                       'paramCount' => 3,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideDeleteLogDatabaseRows
+        */
+       public function testDeleteLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideRestoreLogDatabaseRows() {
+               return array(
+                       // Current format
+                       array(
+                               array(
+                                       'type' => 'delete',
+                                       'action' => 'restore',
+                                       'comment' => 'delete comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'Page',
+                                       'params' => array(),
+                               ),
+                               array(
+                                       'key' => 'logentry-delete-restore',
+                                       'paramCount' => 3,
+                               ),
+                       ),
+
+                       // Legacy format
+                       array(
+                               array(
+                                       'type' => 'delete',
+                                       'action' => 'restore',
+                                       'comment' => 'delete comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'Page',
+                                       'params' => array(),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-delete-restore',
+                                       'paramCount' => 3,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideRestoreLogDatabaseRows
+        */
+       public function testRestoreLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideRevisionLogDatabaseRows() {
+               return array(
+                       // Current format
+                       array(
+                               array(
+                                       'type' => 'delete',
+                                       'action' => 'revision',
+                                       'comment' => 'delete comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'Page',
+                                       'params' => array(
+                                               '4::type' => 'archive',
+                                               '5::ids' => array( '1', '3', 
'4' ),
+                                               '6::ofield' => '1',
+                                               '7::nfield' => '2',
+                                       ),
+                               ),
+                               array(
+                                       'key' => 'logentry-delete-revision',
+                                       'paramCount' => 5,
+                               ),
+                       ),
+
+                       // Legacy format
+                       array(
+                               array(
+                                       'type' => 'delete',
+                                       'action' => 'revision',
+                                       'comment' => 'delete comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'Page',
+                                       'params' => array(
+                                               'archive',
+                                               '1,3,4',
+                                               'ofield=1',
+                                               'nfield=2',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-delete-revision',
+                                       'paramCount' => 5,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideRevisionLogDatabaseRows
+        */
+       public function testRevisionLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideEventLogDatabaseRows() {
+               return array(
+                       // Current format
+                       array(
+                               array(
+                                       'type' => 'delete',
+                                       'action' => 'event',
+                                       'comment' => 'delete comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'Page',
+                                       'params' => array(
+                                               '4::ids' => array( '1', '3', 
'4' ),
+                                               '5::ofield' => '1',
+                                               '6::nfield' => '2',
+                                       ),
+                               ),
+                               array(
+                                       'key' => 'logentry-delete-event',
+                                       'paramCount' => 5,
+                               ),
+                       ),
+
+                       // Legacy format
+                       array(
+                               array(
+                                       'type' => 'delete',
+                                       'action' => 'event',
+                                       'comment' => 'delete comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'Page',
+                                       'params' => array(
+                                               '1,3,4',
+                                               'ofield=1',
+                                               'nfield=2',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-delete-event',
+                                       'paramCount' => 5,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideEventLogDatabaseRows
+        */
+       public function testEventLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideSuppressRevisionLogDatabaseRows() {
+               return array(
+                       // Current format
+                       array(
+                               array(
+                                       'type' => 'suppress',
+                                       'action' => 'revision',
+                                       'comment' => 'Suppress comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'Page',
+                                       'params' => array(
+                                               '4::type' => 'archive',
+                                               '5::ids' => array( '1', '3', 
'4' ),
+                                               '6::ofield' => '1',
+                                               '7::nfield' => '2',
+                                       ),
+                               ),
+                               array(
+                                       'key' => 'logentry-suppress-revision',
+                                       'paramCount' => 5,
+                               ),
+                       ),
+
+                       // Legacy format
+                       array(
+                               array(
+                                       'type' => 'suppress',
+                                       'action' => 'revision',
+                                       'comment' => 'Suppress comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'Page',
+                                       'params' => array(
+                                               'archive',
+                                               '1,3,4',
+                                               'ofield=1',
+                                               'nfield=2',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-suppress-revision',
+                                       'paramCount' => 5,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideSuppressRevisionLogDatabaseRows
+        */
+       public function testSuppressRevisionLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideSuppressEventLogDatabaseRows() {
+               return array(
+                       // Current format
+                       array(
+                               array(
+                                       'type' => 'suppress',
+                                       'action' => 'event',
+                                       'comment' => 'Suppress comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'Page',
+                                       'params' => array(
+                                               '4::ids' => array( '1', '3', 
'4' ),
+                                               '5::ofield' => '1',
+                                               '6::nfield' => '2',
+                                       ),
+                               ),
+                               array(
+                                       'key' => 'logentry-suppress-event',
+                                       'paramCount' => 5,
+                               ),
+                       ),
+
+                       // Legacy format
+                       array(
+                               array(
+                                       'type' => 'suppress',
+                                       'action' => 'event',
+                                       'comment' => 'Suppress comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'Page',
+                                       'params' => array(
+                                               '1,3,4',
+                                               'ofield=1',
+                                               'nfield=2',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-suppress-event',
+                                       'paramCount' => 5,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideSuppressEventLogDatabaseRows
+        */
+       public function testSuppressEventLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideSuppressDeleteLogDatabaseRows() {
+               return array(
+                       // Current format
+                       array(
+                               array(
+                                       'type' => 'suppress',
+                                       'action' => 'delete',
+                                       'comment' => 'delete comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'Page',
+                                       'params' => array(),
+                               ),
+                               array(
+                                       'key' => 'logentry-suppress-delete',
+                                       'paramCount' => 3,
+                               ),
+                       ),
+
+                       // Legacy format
+                       array(
+                               array(
+                                       'type' => 'suppress',
+                                       'action' => 'delete',
+                                       'comment' => 'delete comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'Page',
+                                       'params' => array(),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-suppress-delete',
+                                       'paramCount' => 3,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideSuppressDeleteLogDatabaseRows
+        */
+       public function testSuppressDeleteLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+}
diff --git a/tests/phpunit/includes/logging/LogFormatterTestCase.php 
b/tests/phpunit/includes/logging/LogFormatterTestCase.php
new file mode 100644
index 0000000..8234dd6
--- /dev/null
+++ b/tests/phpunit/includes/logging/LogFormatterTestCase.php
@@ -0,0 +1,50 @@
+<?php
+
+class LogFormatterTestCase extends MediaWikiLangTestCase {
+
+       public function doTestLogFormatter( $row, $extra ) {
+               $row = $this->expandDatabaseRow( $row, $this->isLegacy( $extra 
) );
+
+               $logEntry = DatabaseLogEntry::newFromRow( $row );
+               $formatter = LogFormatter::newFromEntry( $logEntry );
+
+               // Make LogFormatter::getActionMessage public for testing and 
call it
+               $reflectionMethod = new ReflectionMethod( 'LogFormatter', 
'getActionMessage' );
+               $reflectionMethod->setAccessible( true );
+               $actionMsg = $reflectionMethod->invoke( $formatter );
+
+               $this->assertEquals(
+                       $extra['key'],
+                       $actionMsg->getKey(),
+                       'LogFormatter chooses the same message key as expected'
+               );
+               $this->assertEquals(
+                       $extra['paramCount'],
+                       count( $actionMsg->getParams() ),
+                       'LogFormatter gives the same count of message 
parameters as expected'
+               );
+       }
+
+       protected function isLegacy( $extra ) {
+               return isset( $extra['legacy'] ) && $extra['legacy'];
+       }
+
+       protected function expandDatabaseRow( $data, $legacy ) {
+               return array(
+                       // no log_id because no insert in database
+                       'log_type' => $data['type'],
+                       'log_action' => $data['action'],
+                       'log_timestamp' => isset( $data['timestamp'] ) ? 
$data['timestamp'] : wfTimestampNow(),
+                       'log_user' => isset( $data['user'] ) ? $data['user'] : 
0,
+                       'log_user_text' => isset( $data['user_text'] ) ? 
$data['user_text'] : 'User',
+                       'log_namespace' => isset( $data['namespace'] ) ? 
$data['namespace'] : NS_MAIN,
+                       'log_title' => isset( $data['title'] ) ? $data['title'] 
: 'Main_Page',
+                       'log_page' => isset( $data['page'] ) ? $data['page'] : 
0,
+                       'log_comment' => isset( $data['comment'] ) ? 
$data['comment'] : '',
+                       'log_params' => $legacy
+                               ? LogPage::makeParamBlob( $data['params'] )
+                               : LogEntryBase::makeParamBlob( $data['params'] 
),
+                       'log_deleted' => isset( $data['deleted'] ) ? 
$data['deleted'] : 0,
+               );
+       }
+}
diff --git a/tests/phpunit/includes/logging/MergeLogFormatterTest.php 
b/tests/phpunit/includes/logging/MergeLogFormatterTest.php
new file mode 100644
index 0000000..d7be33f
--- /dev/null
+++ b/tests/phpunit/includes/logging/MergeLogFormatterTest.php
@@ -0,0 +1,59 @@
+<?php
+
+class MergeLogFormatterTest extends LogFormatterTestCase {
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideMergeLogDatabaseRows() {
+               return array(
+                       // Current format
+                       array(
+                               array(
+                                       'type' => 'merge',
+                                       'action' => 'merge',
+                                       'comment' => 'Merge comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'OldPage',
+                                       'params' => array(
+                                               '4::dest' => 'NewPage',
+                                               '5::mergepoint' => 
'20140804160710',
+                                       ),
+                               ),
+                               array(
+                                       'key' => 'logentry-merge-merge',
+                                       'paramCount' => 5,
+                               ),
+                       ),
+
+                       // Legacy format
+                       array(
+                               array(
+                                       'type' => 'merge',
+                                       'action' => 'merge',
+                                       'comment' => 'merge comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'OldPage',
+                                       'params' => array(
+                                               'NewPage',
+                                               '20140804160710',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-merge-merge',
+                                       'paramCount' => 5,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideMergeLogDatabaseRows
+        */
+       public function testMergeLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+}
diff --git a/tests/phpunit/includes/logging/MoveLogFormatterTest.php 
b/tests/phpunit/includes/logging/MoveLogFormatterTest.php
new file mode 100644
index 0000000..9775bce
--- /dev/null
+++ b/tests/phpunit/includes/logging/MoveLogFormatterTest.php
@@ -0,0 +1,230 @@
+<?php
+
+class MoveLogFormatterTest extends LogFormatterTestCase {
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideMoveLogDatabaseRows() {
+               return array(
+                       // Current format - with redirect
+                       array(
+                               array(
+                                       'type' => 'move',
+                                       'action' => 'move',
+                                       'comment' => 'move comment with 
redirect',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'OldPage',
+                                       'params' => array(
+                                               '4::target' => 'NewPage',
+                                               '5::noredir' => '0',
+                                       ),
+                               ),
+                               array(
+                                       'key' => 'logentry-move-move',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+
+                       // Current format - without redirect
+                       array(
+                               array(
+                                       'type' => 'move',
+                                       'action' => 'move',
+                                       'comment' => 'move comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'OldPage',
+                                       'params' => array(
+                                               '4::target' => 'NewPage',
+                                               '5::noredir' => '1',
+                                       ),
+                               ),
+                               array(
+                                       'key' => 
'logentry-move-move-noredirect',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+
+                       // legacy format - with redirect
+                       array(
+                               array(
+                                       'type' => 'move',
+                                       'action' => 'move',
+                                       'comment' => 'move comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'OldPage',
+                                       'params' => array(
+                                               'NewPage',
+                                               '',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-move-move',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+
+                       // legacy format - without redirect
+                       array(
+                               array(
+                                       'type' => 'move',
+                                       'action' => 'move',
+                                       'comment' => 'move comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'OldPage',
+                                       'params' => array(
+                                               'NewPage',
+                                               '1',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 
'logentry-move-move-noredirect',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+
+                       // old format without flag for redirect suppression
+                       array(
+                               array(
+                                       'type' => 'move',
+                                       'action' => 'move',
+                                       'comment' => 'move comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'OldPage',
+                                       'params' => array(
+                                               'NewPage',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-move-move',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideMoveLogDatabaseRows
+        */
+       public function testMoveLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideMoveRedirLogDatabaseRows() {
+               return array(
+                       // Current format - with redirect
+                       array(
+                               array(
+                                       'type' => 'move',
+                                       'action' => 'move_redir',
+                                       'comment' => 'move comment with 
redirect',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'OldPage',
+                                       'params' => array(
+                                               '4::target' => 'NewPage',
+                                               '5::noredir' => '0',
+                                       ),
+                               ),
+                               array(
+                                       'key' => 'logentry-move-move_redir',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+
+                       // Current format - without redirect
+                       array(
+                               array(
+                                       'type' => 'move',
+                                       'action' => 'move_redir',
+                                       'comment' => 'move comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'OldPage',
+                                       'params' => array(
+                                               '4::target' => 'NewPage',
+                                               '5::noredir' => '1',
+                                       ),
+                               ),
+                               array(
+                                       'key' => 
'logentry-move-move_redir-noredirect',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+
+                       // legacy format - with redirect
+                       array(
+                               array(
+                                       'type' => 'move',
+                                       'action' => 'move_redir',
+                                       'comment' => 'move comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'OldPage',
+                                       'params' => array(
+                                               'NewPage',
+                                               '',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-move-move_redir',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+
+                       // legacy format - without redirect
+                       array(
+                               array(
+                                       'type' => 'move',
+                                       'action' => 'move_redir',
+                                       'comment' => 'move comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'OldPage',
+                                       'params' => array(
+                                               'NewPage',
+                                               '1',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 
'logentry-move-move_redir-noredirect',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+
+                       // old format without flag for redirect suppression
+                       array(
+                               array(
+                                       'type' => 'move',
+                                       'action' => 'move_redir',
+                                       'comment' => 'move comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'OldPage',
+                                       'params' => array(
+                                               'NewPage',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-move-move_redir',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideMoveRedirLogDatabaseRows
+        */
+       public function testMoveRedirLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+}
diff --git a/tests/phpunit/includes/logging/NewUsersLogFormatterTest.php 
b/tests/phpunit/includes/logging/NewUsersLogFormatterTest.php
new file mode 100644
index 0000000..25a224d
--- /dev/null
+++ b/tests/phpunit/includes/logging/NewUsersLogFormatterTest.php
@@ -0,0 +1,183 @@
+<?php
+
+class NewUsersLogFormatterTest extends LogFormatterTestCase {
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideNewUsersLogDatabaseRows() {
+               return array(
+                       // Only old logs
+                       array(
+                               array(
+                                       'type' => 'newusers',
+                                       'action' => 'newusers',
+                                       'comment' => 'newusers comment',
+                                       'user' => 0,
+                                       'user_text' => 'New user',
+                                       'namespace' => NS_USER,
+                                       'title' => 'New user',
+                                       'params' => array(),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-newusers-newusers',
+                                       'paramCount' => 3,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideNewUsersLogDatabaseRows
+        */
+       public function testNewUsersLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideCreateLogDatabaseRows() {
+               return array(
+                       // Current format
+                       array(
+                               array(
+                                       'type' => 'newusers',
+                                       'action' => 'create',
+                                       'comment' => 'newusers comment',
+                                       'user' => 0,
+                                       'user_text' => 'New user',
+                                       'namespace' => NS_USER,
+                                       'title' => 'New user',
+                                       'params' => array(
+                                               '4::userid' => '1',
+                                       ),
+                               ),
+                               array(
+                                       'key' => 'logentry-newusers-create',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideCreateLogDatabaseRows
+        */
+       public function testCreateLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideCreate2LogDatabaseRows() {
+               return array(
+                       // Current format
+                       array(
+                               array(
+                                       'type' => 'newusers',
+                                       'action' => 'create2',
+                                       'comment' => 'newusers comment',
+                                       'user' => 0,
+                                       'user_text' => 'New user',
+                                       'namespace' => NS_USER,
+                                       'title' => 'New user',
+                                       'params' => array(
+                                               '4::userid' => '1',
+                                       ),
+                               ),
+                               array(
+                                       'key' => 'logentry-newusers-create2',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideCreate2LogDatabaseRows
+        */
+       public function testCreate2LogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideBymailLogDatabaseRows() {
+               return array(
+                       // Current format
+                       array(
+                               array(
+                                       'type' => 'newusers',
+                                       'action' => 'bymail',
+                                       'comment' => 'newusers comment',
+                                       'user' => 0,
+                                       'user_text' => 'Sysop',
+                                       'namespace' => NS_USER,
+                                       'title' => 'New user',
+                                       'params' => array(
+                                               '4::userid' => '1',
+                                       ),
+                               ),
+                               array(
+                                       'key' => 'logentry-newusers-bymail',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideBymailLogDatabaseRows
+        */
+       public function testBymailLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideAutocreateLogDatabaseRows() {
+               return array(
+                       // Current format
+                       array(
+                               array(
+                                       'type' => 'newusers',
+                                       'action' => 'autocreate',
+                                       'comment' => 'newusers comment',
+                                       'user' => 0,
+                                       'user_text' => 'New user',
+                                       'namespace' => NS_USER,
+                                       'title' => 'New user',
+                                       'params' => array(
+                                               '4::userid' => '1',
+                                       ),
+                               ),
+                               array(
+                                       'key' => 'logentry-newusers-autocreate',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideAutocreateLogDatabaseRows
+        */
+       public function testAutocreateLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+}
diff --git a/tests/phpunit/includes/logging/PageLangLogFormatterTest.php 
b/tests/phpunit/includes/logging/PageLangLogFormatterTest.php
new file mode 100644
index 0000000..7508a00
--- /dev/null
+++ b/tests/phpunit/includes/logging/PageLangLogFormatterTest.php
@@ -0,0 +1,39 @@
+<?php
+
+class PageLangLogFormatterTest extends LogFormatterTestCase {
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function providePageLangLogDatabaseRows() {
+               return array(
+                       // Current format
+                       array(
+                               array(
+                                       'type' => 'pagelang',
+                                       'action' => 'pagelang',
+                                       'comment' => 'page lang comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'Page',
+                                       'params' => array(
+                                               '4::oldlanguage' => 'en',
+                                               '5::newlanguage' => 'de[def]',
+                                       ),
+                               ),
+                               array(
+                                       'key' => 'logentry-pagelang-pagelang',
+                                       'paramCount' => 5,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider providePageLangLogDatabaseRows
+        */
+       public function testPageLangLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+}
diff --git a/tests/phpunit/includes/logging/PatrolLogFormatterTest.php 
b/tests/phpunit/includes/logging/PatrolLogFormatterTest.php
new file mode 100644
index 0000000..2a0f6c5
--- /dev/null
+++ b/tests/phpunit/includes/logging/PatrolLogFormatterTest.php
@@ -0,0 +1,102 @@
+<?php
+
+class PatrolLogFormatterTest extends LogFormatterTestCase {
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function providePatrolLogDatabaseRows() {
+               return array(
+                       // Current format
+                       array(
+                               array(
+                                       'type' => 'patrol',
+                                       'action' => 'patrol',
+                                       'comment' => 'patrol comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'Page',
+                                       'params' => array(
+                                               '4::curid' => 2,
+                                               '5::previd' => 1,
+                                               '6::auto' => 0,
+                                       ),
+                               ),
+                               array(
+                                       'key' => 'logentry-patrol-patrol',
+                                       'paramCount' => 6,
+                               ),
+                       ),
+
+                       // Current format - autopatrol
+                       array(
+                               array(
+                                       'type' => 'patrol',
+                                       'action' => 'patrol',
+                                       'comment' => 'patrol comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'Page',
+                                       'params' => array(
+                                               '4::curid' => 2,
+                                               '5::previd' => 1,
+                                               '6::auto' => 1,
+                                       ),
+                               ),
+                               array(
+                                       'key' => 'logentry-patrol-patrol-auto',
+                                       'paramCount' => 6,
+                               ),
+                       ),
+
+                       // Legacy format
+                       array(
+                               array(
+                                       'type' => 'patrol',
+                                       'action' => 'patrol',
+                                       'comment' => 'patrol comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'Page',
+                                       'params' => array(
+                                               '2',
+                                               '1',
+                                               '0',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-patrol-patrol',
+                                       'paramCount' => 6,
+                               ),
+                       ),
+
+                       // Legacy format - autopatrol
+                       array(
+                               array(
+                                       'type' => 'patrol',
+                                       'action' => 'patrol',
+                                       'comment' => 'patrol comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'Page',
+                                       'params' => array(
+                                               '2',
+                                               '1',
+                                               '1',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-patrol-patrol-auto',
+                                       'paramCount' => 6,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider providePatrolLogDatabaseRows
+        */
+       public function testPatrolLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+}
diff --git a/tests/phpunit/includes/logging/ProtectLogFormatterTest.php 
b/tests/phpunit/includes/logging/ProtectLogFormatterTest.php
new file mode 100644
index 0000000..13daca8
--- /dev/null
+++ b/tests/phpunit/includes/logging/ProtectLogFormatterTest.php
@@ -0,0 +1,277 @@
+<?php
+
+class ProtectLogFormatterTest extends LogFormatterTestCase {
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideProtectLogDatabaseRows() {
+               return array(
+                       // Current format
+                       array(
+                               array(
+                                       'type' => 'protect',
+                                       'action' => 'protect',
+                                       'comment' => 'protect comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'ProtectPage',
+                                       'params' => array(
+                                               '4::description' => 'Test 
description [edit=sysop:move=sysop]',
+                                               '5::cascade' => '',
+                                       ),
+                               ),
+                               array(
+                                       'key' => 'logentry-protect-protect',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+
+                       // Current format with cascade
+                       array(
+                               array(
+                                       'type' => 'protect',
+                                       'action' => 'protect',
+                                       'comment' => 'protect comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'ProtectPage',
+                                       'params' => array(
+                                               '4::description' => 'Test 
description [edit=sysop:move=sysop]',
+                                               '5::cascade' => 'cascade',
+                                       ),
+                               ),
+                               array(
+                                       'key' => 
'logentry-protect-protect-cascade',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+
+                       // Legacy format
+                       array(
+                               array(
+                                       'type' => 'protect',
+                                       'action' => 'protect',
+                                       'comment' => 'protect comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'ProtectPage',
+                                       'params' => array(
+                                               'Test description 
[edit=sysop:move=sysop]',
+                                               '',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-protect-protect',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+
+                       // Legacy format with cascade
+                       array(
+                               array(
+                                       'type' => 'protect',
+                                       'action' => 'protect',
+                                       'comment' => 'protect comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'ProtectPage',
+                                       'params' => array(
+                                               'Test description 
[edit=sysop:move=sysop]',
+                                               'cascade',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 
'logentry-protect-protect-cascade',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideProtectLogDatabaseRows
+        */
+       public function testProtectLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideModifyLogDatabaseRows() {
+               return array(
+                       // Current format
+                       array(
+                               array(
+                                       'type' => 'protect',
+                                       'action' => 'modify',
+                                       'comment' => 'protect comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'ProtectPage',
+                                       'params' => array(
+                                               '4::description' => 'Test 
description [edit=sysop:move=sysop]',
+                                               '5::cascade' => '',
+                                       ),
+                               ),
+                               array(
+                                       'key' => 'logentry-protect-modify',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+
+                       // Current format with cascade
+                       array(
+                               array(
+                                       'type' => 'protect',
+                                       'action' => 'modify',
+                                       'comment' => 'protect comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'ProtectPage',
+                                       'params' => array(
+                                               '4::description' => 'Test 
description [edit=sysop:move=sysop]',
+                                               '5::cascade' => 'cascade',
+                                       ),
+                               ),
+                               array(
+                                       'key' => 
'logentry-protect-modify-cascade',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+
+                       // Legacy format
+                       array(
+                               array(
+                                       'type' => 'protect',
+                                       'action' => 'modify',
+                                       'comment' => 'protect comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'ProtectPage',
+                                       'params' => array(
+                                               'Test description 
[edit=sysop:move=sysop]',
+                                               '',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-protect-modify',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+
+                       // Legacy format with cascade
+                       array(
+                               array(
+                                       'type' => 'protect',
+                                       'action' => 'modify',
+                                       'comment' => 'protect comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'ProtectPage',
+                                       'params' => array(
+                                               'Test description 
[edit=sysop:move=sysop]',
+                                               'cascade',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 
'logentry-protect-modify-cascade',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideModifyLogDatabaseRows
+        */
+       public function testModifyLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideUnprotectLogDatabaseRows() {
+               return array(
+                       // Current format
+                       array(
+                               array(
+                                       'type' => 'protect',
+                                       'action' => 'unprotect',
+                                       'comment' => 'unprotect comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'ProtectPage',
+                                       'params' => array(),
+                               ),
+                               array(
+                                       'key' => 'logentry-protect-unprotect',
+                                       'paramCount' => 3,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideUnprotectLogDatabaseRows
+        */
+       public function testUnprotectLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideMoveProtLogDatabaseRows() {
+               return array(
+                       // Current format
+                       array(
+                               array(
+                                       'type' => 'protect',
+                                       'action' => 'move_prot',
+                                       'comment' => 'Move comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'NewPage',
+                                       'params' => array(
+                                               '4::oldtitle' => 'OldPage',
+                                       ),
+                               ),
+                               array(
+                                       'key' => 'logentry-protect-move_prot',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+
+                       // Legacy format
+                       array(
+                               array(
+                                       'type' => 'protect',
+                                       'action' => 'move_prot',
+                                       'comment' => 'Move comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'NewPage',
+                                       'params' => array(
+                                               'OldPage',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-protect-move_prot',
+                                       'paramCount' => 4,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideMoveProtLogDatabaseRows
+        */
+       public function testMoveProtLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+}
diff --git a/tests/phpunit/includes/logging/RightsLogFormatterTest.php 
b/tests/phpunit/includes/logging/RightsLogFormatterTest.php
new file mode 100644
index 0000000..e0c960b
--- /dev/null
+++ b/tests/phpunit/includes/logging/RightsLogFormatterTest.php
@@ -0,0 +1,141 @@
+<?php
+
+class RightsLogFormatterTest extends LogFormatterTestCase {
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideRightsLogDatabaseRows() {
+               return array(
+                       // Current format
+                       array(
+                               array(
+                                       'type' => 'rights',
+                                       'action' => 'rights',
+                                       'comment' => 'rights comment',
+                                       'user' => 0,
+                                       'user_text' => 'Sysop',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'User',
+                                       'params' => array(
+                                               '4::oldgroups' => array(),
+                                               '5::newgroups' => array( 
'sysop', 'bureaucrat' ),
+                                       ),
+                               ),
+                               array(
+                                       'key' => 'logentry-rights-rights',
+                                       'paramCount' => 5,
+                               ),
+                       ),
+
+                       // Legacy format
+                       array(
+                               array(
+                                       'type' => 'rights',
+                                       'action' => 'rights',
+                                       'comment' => 'rights comment',
+                                       'user' => 0,
+                                       'user_text' => 'Sysop',
+                                       'namespace' => NS_USER,
+                                       'title' => 'User',
+                                       'params' => array(
+                                               '',
+                                               'sysop, bureaucrat',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-rights-rights',
+                                       'paramCount' => 5,
+                               ),
+                       ),
+
+                       // Really old entry
+                       array(
+                               array(
+                                       'type' => 'rights',
+                                       'action' => 'rights',
+                                       'comment' => 'rights comment',
+                                       'user' => 0,
+                                       'user_text' => 'Sysop',
+                                       'namespace' => NS_USER,
+                                       'title' => 'User',
+                                       'params' => array(),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 
'logentry-rights-rights-legacy',
+                                       'paramCount' => 3,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideRightsLogDatabaseRows
+        */
+       public function testRightsLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideAutopromoteLogDatabaseRows() {
+               return array(
+                       // Current format
+                       array(
+                               array(
+                                       'type' => 'rights',
+                                       'action' => 'autopromote',
+                                       'comment' => 'rights comment',
+                                       'user' => 0,
+                                       'user_text' => 'Sysop',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'User',
+                                       'params' => array(
+                                               '4::oldgroups' => array( 
'sysop' ),
+                                               '5::newgroups' => array( 
'sysop', 'bureaucrat' ),
+                                       ),
+                               ),
+                               array(
+                                       'key' => 'logentry-rights-autopromote',
+                                       'paramCount' => 5,
+                               ),
+                       ),
+
+                       // Legacy format
+                       array(
+                               array(
+                                       'type' => 'rights',
+                                       'action' => 'autopromote',
+                                       'comment' => 'rights comment',
+                                       'user' => 0,
+                                       'user_text' => 'Sysop',
+                                       'namespace' => NS_USER,
+                                       'title' => 'User',
+                                       'params' => array(
+                                               'sysop',
+                                               'sysop, bureaucrat',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'key' => 'logentry-rights-autopromote',
+                                       'paramCount' => 5,
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideAutopromoteLogDatabaseRows
+        */
+       public function testAutopromoteLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icfcba506f4fa3010cdaf973aa2df23b6e92c25e4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <umherirrender_de...@web.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to