Test the LogFormatter by passing old and new database rows to it.
The text shown on Special:Log and the api result returned by
list=logevents is tested.
Change-Id: Icfcba506f4fa3010cdaf973aa2df23b6e92c25e4
# 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/password
'PasswordTestCase' => "$testDir/phpunit/includes/password/PasswordTestCase.php",
--- /dev/null
+<?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(
+ 'text' => 'Sysop blocked Logtestuser with an expiry time of indefinite (anonymous users only)',
+ 'api' => array(
+ 'duration' => 'infinite',
+ 'flags' => array( 'anononly' ),
+ ),
+ ),
+ ),
+
+ // 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,
+ 'text' => 'Sysop blocked Logtestuser with an expiry time of indefinite (anonymous users only)',
+ 'api' => array(
+ 'duration' => 'infinite',
+ 'flags' => array( 'anononly' ),
+ ),
+ ),
+ ),
+
+ // 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,
+ 'text' => 'Sysop blocked Logtestuser with an expiry time of indefinite',
+ 'api' => array(
+ 'duration' => 'infinite',
+ 'flags' => array(),
+ ),
+ ),
+ ),
+
+ // 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,
+ 'text' => 'Sysop blocked Logtestuser with an expiry time of indefinite',
+ 'api' => array(
+ 'duration' => 'infinite',
+ 'flags' => array(),
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @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(
+ 'text' => 'Sysop changed block settings for Logtestuser with an expiry time of'
+ . ' indefinite (anonymous users only)',
+ 'api' => array(
+ 'duration' => 'infinite',
+ 'flags' => array( 'anononly' ),
+ ),
+ ),
+ ),
+
+ // 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,
+ 'text' => 'Sysop changed block settings for Logtestuser with an expiry time of'
+ . ' indefinite (anonymous users only)',
+ 'api' => array(
+ 'duration' => 'infinite',
+ 'flags' => array( 'anononly' ),
+ ),
+ ),
+ ),
+
+ // 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,
+ 'text' => 'Sysop changed block settings for Logtestuser with an expiry time of indefinite',
+ 'api' => array(
+ 'duration' => 'infinite',
+ 'flags' => array(),
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider provideReblockLogDatabaseRows
+ */
+ public function testReblockLogDatabaseRows( $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(
+ 'text' => 'Sysop unblocked Logtestuser',
+ 'api' => array(),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @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(
+ 'text' => 'Sysop blocked Logtestuser with an expiry time of indefinite (anonymous users only)',
+ 'api' => array(
+ 'duration' => 'infinite',
+ 'flags' => array( 'anononly' ),
+ ),
+ ),
+ ),
+
+ // 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,
+ 'text' => 'Sysop blocked Logtestuser with an expiry time of indefinite (anonymous users only)',
+ 'api' => array(
+ 'duration' => 'infinite',
+ 'flags' => array( 'anononly' ),
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @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(
+ 'text' => 'Sysop changed block settings for Logtestuser with an expiry time of'
+ . ' indefinite (anonymous users only)',
+ 'api' => array(
+ 'duration' => 'infinite',
+ 'flags' => array( 'anononly' ),
+ ),
+ ),
+ ),
+
+ // 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,
+ 'text' => 'Sysop changed block settings for Logtestuser with an expiry time of'
+ . ' indefinite (anonymous users only)',
+ 'api' => array(
+ 'duration' => 'infinite',
+ 'flags' => array( 'anononly' ),
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider provideSuppressReblockLogDatabaseRows
+ */
+ public function testSuppressReblockLogDatabaseRows( $row, $extra ) {
+ $this->doTestLogFormatter( $row, $extra );
+ }
+}
--- /dev/null
+<?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(
+ 'text' => 'User deleted page Page',
+ 'api' => array(),
+ ),
+ ),
+
+ // Legacy format
+ array(
+ array(
+ 'type' => 'delete',
+ 'action' => 'delete',
+ 'comment' => 'delete comment',
+ 'namespace' => NS_MAIN,
+ 'title' => 'Page',
+ 'params' => array(),
+ ),
+ array(
+ 'legacy' => true,
+ 'text' => 'User deleted page Page',
+ 'api' => array(),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @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(
+ 'text' => 'User restored page Page',
+ 'api' => array(),
+ ),
+ ),
+
+ // Legacy format
+ array(
+ array(
+ 'type' => 'delete',
+ 'action' => 'restore',
+ 'comment' => 'delete comment',
+ 'namespace' => NS_MAIN,
+ 'title' => 'Page',
+ 'params' => array(),
+ ),
+ array(
+ 'legacy' => true,
+ 'text' => 'User restored page Page',
+ 'api' => array(),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @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(
+ 'text' => 'User changed visibility of 3 revisions on page Page: edit summary '
+ . 'hidden and content unhidden',
+ 'api' => array(
+ 'type' => 'archive',
+ 'ids' => array( '1', '3', '4' ),
+ 'old' => array(
+ 'bitmask' => 1,
+ 'content' => true,
+ 'comment' => false,
+ 'user' => false,
+ 'restricted' => false,
+ ),
+ 'new' => array(
+ 'bitmask' => 2,
+ 'content' => false,
+ 'comment' => true,
+ 'user' => false,
+ 'restricted' => false,
+ ),
+ ),
+ ),
+ ),
+
+ // 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,
+ 'text' => 'User changed visibility of 3 revisions on page Page: edit summary '
+ . 'hidden and content unhidden',
+ 'api' => array(
+ 'type' => 'archive',
+ 'ids' => array( '1', '3', '4' ),
+ 'old' => array(
+ 'bitmask' => 1,
+ 'content' => true,
+ 'comment' => false,
+ 'user' => false,
+ 'restricted' => false,
+ ),
+ 'new' => array(
+ 'bitmask' => 2,
+ 'content' => false,
+ 'comment' => true,
+ 'user' => false,
+ 'restricted' => false,
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @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(
+ 'text' => 'User changed visibility of 3 log events on Page: edit summary hidden '
+ . 'and content unhidden',
+ 'api' => array(
+ 'type' => 'logging',
+ 'ids' => array( '1', '3', '4' ),
+ 'old' => array(
+ 'bitmask' => 1,
+ 'content' => true,
+ 'comment' => false,
+ 'user' => false,
+ 'restricted' => false,
+ ),
+ 'new' => array(
+ 'bitmask' => 2,
+ 'content' => false,
+ 'comment' => true,
+ 'user' => false,
+ 'restricted' => false,
+ ),
+ ),
+ ),
+ ),
+
+ // 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,
+ 'text' => 'User changed visibility of 3 log events on Page: edit summary hidden '
+ . 'and content unhidden',
+ 'api' => array(
+ 'type' => 'logging',
+ 'ids' => array( '1', '3', '4' ),
+ 'old' => array(
+ 'bitmask' => 1,
+ 'content' => true,
+ 'comment' => false,
+ 'user' => false,
+ 'restricted' => false,
+ ),
+ 'new' => array(
+ 'bitmask' => 2,
+ 'content' => false,
+ 'comment' => true,
+ 'user' => false,
+ 'restricted' => false,
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @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' => '10',
+ ),
+ ),
+ array(
+ 'text' => 'User secretly changed visibility of 3 revisions on page Page: edit '
+ . 'summary hidden, content unhidden and applied restrictions to administrators',
+ 'api' => array(
+ 'type' => 'archive',
+ 'ids' => array( '1', '3', '4' ),
+ 'old' => array(
+ 'bitmask' => 1,
+ 'content' => true,
+ 'comment' => false,
+ 'user' => false,
+ 'restricted' => false,
+ ),
+ 'new' => array(
+ 'bitmask' => 10,
+ 'content' => false,
+ 'comment' => true,
+ 'user' => false,
+ 'restricted' => true,
+ ),
+ ),
+ ),
+ ),
+
+ // 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=10',
+ ),
+ ),
+ array(
+ 'legacy' => true,
+ 'text' => 'User secretly changed visibility of 3 revisions on page Page: edit '
+ . 'summary hidden, content unhidden and applied restrictions to administrators',
+ 'api' => array(
+ 'type' => 'archive',
+ 'ids' => array( '1', '3', '4' ),
+ 'old' => array(
+ 'bitmask' => 1,
+ 'content' => true,
+ 'comment' => false,
+ 'user' => false,
+ 'restricted' => false,
+ ),
+ 'new' => array(
+ 'bitmask' => 10,
+ 'content' => false,
+ 'comment' => true,
+ 'user' => false,
+ 'restricted' => true,
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @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' => '10',
+ ),
+ ),
+ array(
+ 'text' => 'User secretly changed visibility of 3 log events on Page: edit '
+ . 'summary hidden, content unhidden and applied restrictions to administrators',
+ 'api' => array(
+ 'type' => 'logging',
+ 'ids' => array( '1', '3', '4' ),
+ 'old' => array(
+ 'bitmask' => 1,
+ 'content' => true,
+ 'comment' => false,
+ 'user' => false,
+ 'restricted' => false,
+ ),
+ 'new' => array(
+ 'bitmask' => 10,
+ 'content' => false,
+ 'comment' => true,
+ 'user' => false,
+ 'restricted' => true,
+ ),
+ ),
+ ),
+ ),
+
+ // Legacy format
+ array(
+ array(
+ 'type' => 'suppress',
+ 'action' => 'event',
+ 'comment' => 'Suppress comment',
+ 'namespace' => NS_MAIN,
+ 'title' => 'Page',
+ 'params' => array(
+ '1,3,4',
+ 'ofield=1',
+ 'nfield=10',
+ ),
+ ),
+ array(
+ 'legacy' => true,
+ 'text' => 'User secretly changed visibility of 3 log events on Page: edit '
+ . 'summary hidden, content unhidden and applied restrictions to administrators',
+ 'api' => array(
+ 'type' => 'logging',
+ 'ids' => array( '1', '3', '4' ),
+ 'old' => array(
+ 'bitmask' => 1,
+ 'content' => true,
+ 'comment' => false,
+ 'user' => false,
+ 'restricted' => false,
+ ),
+ 'new' => array(
+ 'bitmask' => 10,
+ 'content' => false,
+ 'comment' => true,
+ 'user' => false,
+ 'restricted' => true,
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @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(
+ 'text' => 'User suppressed page Page',
+ 'api' => array(),
+ ),
+ ),
+
+ // Legacy format
+ array(
+ array(
+ 'type' => 'suppress',
+ 'action' => 'delete',
+ 'comment' => 'delete comment',
+ 'namespace' => NS_MAIN,
+ 'title' => 'Page',
+ 'params' => array(),
+ ),
+ array(
+ 'legacy' => true,
+ 'text' => 'User suppressed page Page',
+ 'api' => array(),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider provideSuppressDeleteLogDatabaseRows
+ */
+ public function testSuppressDeleteLogDatabaseRows( $row, $extra ) {
+ $this->doTestLogFormatter( $row, $extra );
+ }
+}
--- /dev/null
+<?php
+
+/**
+ * @since 1.26
+ */
+abstract class LogFormatterTestCase extends MediaWikiLangTestCase {
+
+ public function doTestLogFormatter( $row, $extra ) {
+ RequestContext::resetMain();
+ $row = $this->expandDatabaseRow( $row, $this->isLegacy( $extra ) );
+
+ $formatter = LogFormatter::newFromRow( $row );
+
+ $this->assertEquals(
+ $extra['text'],
+ self::removeSomeHtml( $formatter->getActionText() ),
+ 'Action text is equal to expected text'
+ );
+
+ $this->assertEquals(
+ $extra['api'],
+ self::removeApiMetaData( $formatter->formatParametersForApi() ),
+ 'Api log params is equal to expected array'
+ );
+ }
+
+ 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,
+ );
+ }
+
+ private static function removeSomeHtml( $html ) {
+ return trim( preg_replace( '/<(a|span)[^>]*>([^<]*)<\/\1>/', '$2', $html ) );
+ }
+
+ private static function removeApiMetaData( $val ) {
+ if ( is_array( $val ) ) {
+ unset( $val['_element'] );
+ unset( $val['_type'] );
+ foreach ( $val as $key => $value ) {
+ $val[$key] = self::removeApiMetaData( $value );
+ }
+ }
+ return $val;
+ }
+}
--- /dev/null
+<?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(
+ 'text' => 'User merged OldPage into NewPage (revisions up to 16:07, 4 August 2014)',
+ 'api' => array(
+ 'mergepoint' => '2014-08-04T16:07:10Z',
+ 'dest_ns' => 0,
+ 'dest_title' => 'NewPage',
+ ),
+ ),
+ ),
+
+ // Legacy format
+ array(
+ array(
+ 'type' => 'merge',
+ 'action' => 'merge',
+ 'comment' => 'merge comment',
+ 'namespace' => NS_MAIN,
+ 'title' => 'OldPage',
+ 'params' => array(
+ 'NewPage',
+ '20140804160710',
+ ),
+ ),
+ array(
+ 'legacy' => true,
+ 'text' => 'User merged OldPage into NewPage (revisions up to 16:07, 4 August 2014)',
+ 'api' => array(
+ 'mergepoint' => '2014-08-04T16:07:10Z',
+ 'dest_ns' => 0,
+ 'dest_title' => 'NewPage',
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider provideMergeLogDatabaseRows
+ */
+ public function testMergeLogDatabaseRows( $row, $extra ) {
+ $this->doTestLogFormatter( $row, $extra );
+ }
+}
--- /dev/null
+<?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(
+ 'text' => 'User moved page OldPage to NewPage',
+ 'api' => array(
+ 'target_ns' => 0,
+ 'target_title' => 'NewPage',
+ 'suppressredirect' => false,
+ ),
+ ),
+ ),
+
+ // 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(
+ 'text' => 'User moved page OldPage to NewPage without leaving a redirect',
+ 'api' => array(
+ 'target_ns' => 0,
+ 'target_title' => 'NewPage',
+ 'suppressredirect' => true,
+ ),
+ ),
+ ),
+
+ // legacy format - with redirect
+ array(
+ array(
+ 'type' => 'move',
+ 'action' => 'move',
+ 'comment' => 'move comment',
+ 'namespace' => NS_MAIN,
+ 'title' => 'OldPage',
+ 'params' => array(
+ 'NewPage',
+ '',
+ ),
+ ),
+ array(
+ 'legacy' => true,
+ 'text' => 'User moved page OldPage to NewPage',
+ 'api' => array(
+ 'target_ns' => 0,
+ 'target_title' => 'NewPage',
+ 'suppressredirect' => false,
+ ),
+ ),
+ ),
+
+ // 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,
+ 'text' => 'User moved page OldPage to NewPage without leaving a redirect',
+ 'api' => array(
+ 'target_ns' => 0,
+ 'target_title' => 'NewPage',
+ 'suppressredirect' => true,
+ ),
+ ),
+ ),
+
+ // 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,
+ 'text' => 'User moved page OldPage to NewPage',
+ 'api' => array(
+ 'target_ns' => 0,
+ 'target_title' => 'NewPage',
+ 'suppressredirect' => false,
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @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(
+ 'text' => 'User moved page OldPage to NewPage over redirect',
+ 'api' => array(
+ 'target_ns' => 0,
+ 'target_title' => 'NewPage',
+ 'suppressredirect' => false,
+ ),
+ ),
+ ),
+
+ // 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(
+ 'text' => 'User moved page OldPage to NewPage over a redirect without leaving a redirect',
+ 'api' => array(
+ 'target_ns' => 0,
+ 'target_title' => 'NewPage',
+ 'suppressredirect' => true,
+ ),
+ ),
+ ),
+
+ // 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,
+ 'text' => 'User moved page OldPage to NewPage over redirect',
+ 'api' => array(
+ 'target_ns' => 0,
+ 'target_title' => 'NewPage',
+ 'suppressredirect' => false,
+ ),
+ ),
+ ),
+
+ // 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,
+ 'text' => 'User moved page OldPage to NewPage over a redirect without leaving a redirect',
+ 'api' => array(
+ 'target_ns' => 0,
+ 'target_title' => 'NewPage',
+ 'suppressredirect' => true,
+ ),
+ ),
+ ),
+
+ // 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,
+ 'text' => 'User moved page OldPage to NewPage over redirect',
+ 'api' => array(
+ 'target_ns' => 0,
+ 'target_title' => 'NewPage',
+ 'suppressredirect' => false,
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider provideMoveRedirLogDatabaseRows
+ */
+ public function testMoveRedirLogDatabaseRows( $row, $extra ) {
+ $this->doTestLogFormatter( $row, $extra );
+ }
+}
--- /dev/null
+<?php
+
+/**
+ * @group Database
+ */
+class NewUsersLogFormatterTest extends LogFormatterTestCase {
+
+ protected function setUp() {
+ parent::setUp();
+
+ // Register LogHandler, see $wgNewUserLog in Setup.php
+ $this->mergeMwGlobalArrayValue( 'wgLogActionsHandlers', array(
+ 'newusers/newusers' => 'NewUsersLogFormatter',
+ 'newusers/create' => 'NewUsersLogFormatter',
+ 'newusers/create2' => 'NewUsersLogFormatter',
+ 'newusers/byemail' => 'NewUsersLogFormatter',
+ 'newusers/autocreate' => 'NewUsersLogFormatter',
+ ) );
+ }
+
+ /**
+ * 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,
+ 'text' => 'User account New user was created',
+ 'api' => array(),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @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(
+ 'text' => 'User account New user was created',
+ 'api' => array(
+ 'userid' => 1,
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @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' => 'User',
+ 'namespace' => NS_USER,
+ 'title' => 'UTSysop',
+ 'params' => array(
+ '4::userid' => '1',
+ ),
+ ),
+ array(
+ 'text' => 'User account UTSysop was created by User',
+ 'api' => array(
+ 'userid' => 1,
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @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 provideByemailLogDatabaseRows() {
+ return array(
+ // Current format
+ array(
+ array(
+ 'type' => 'newusers',
+ 'action' => 'byemail',
+ 'comment' => 'newusers comment',
+ 'user' => 0,
+ 'user_text' => 'Sysop',
+ 'namespace' => NS_USER,
+ 'title' => 'UTSysop',
+ 'params' => array(
+ '4::userid' => '1',
+ ),
+ ),
+ array(
+ 'text' => 'User account UTSysop was created by Sysop and password was sent by email',
+ 'api' => array(
+ 'userid' => 1,
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider provideByemailLogDatabaseRows
+ */
+ public function testByemailLogDatabaseRows( $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(
+ 'text' => 'User account New user was created automatically',
+ 'api' => array(
+ 'userid' => 1,
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider provideAutocreateLogDatabaseRows
+ */
+ public function testAutocreateLogDatabaseRows( $row, $extra ) {
+ $this->doTestLogFormatter( $row, $extra );
+ }
+}
--- /dev/null
+<?php
+
+class PageLangLogFormatterTest extends LogFormatterTestCase {
+
+ protected function setUp() {
+ parent::setUp();
+
+ // Disable cldr extension
+ $this->setMwGlobals( 'wgHooks', array() );
+ // Register LogHandler, see $wgPageLanguageUseDB in Setup.php
+ $this->mergeMwGlobalArrayValue( 'wgLogActionsHandlers', array(
+ 'pagelang/pagelang' => 'PageLangLogFormatter',
+ ) );
+ }
+
+ /**
+ * 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(
+ 'text' => 'User changed page language for Page from English (en) to Deutsch (de) [default].',
+ 'api' => array(
+ 'oldlanguage' => 'en',
+ 'newlanguage' => 'de[def]'
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider providePageLangLogDatabaseRows
+ */
+ public function testPageLangLogDatabaseRows( $row, $extra ) {
+ $this->doTestLogFormatter( $row, $extra );
+ }
+}
--- /dev/null
+<?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(
+ 'text' => 'User marked revision 2 of page Page patrolled',
+ 'api' => array(
+ 'curid' => 2,
+ 'previd' => 1,
+ 'auto' => false,
+ ),
+ ),
+ ),
+
+ // 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(
+ 'text' => 'User automatically marked revision 2 of page Page patrolled',
+ 'api' => array(
+ 'curid' => 2,
+ 'previd' => 1,
+ 'auto' => true,
+ ),
+ ),
+ ),
+
+ // Legacy format
+ array(
+ array(
+ 'type' => 'patrol',
+ 'action' => 'patrol',
+ 'comment' => 'patrol comment',
+ 'namespace' => NS_MAIN,
+ 'title' => 'Page',
+ 'params' => array(
+ '2',
+ '1',
+ '0',
+ ),
+ ),
+ array(
+ 'legacy' => true,
+ 'text' => 'User marked revision 2 of page Page patrolled',
+ 'api' => array(
+ 'curid' => 2,
+ 'previd' => 1,
+ 'auto' => false,
+ ),
+ ),
+ ),
+
+ // 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,
+ 'text' => 'User automatically marked revision 2 of page Page patrolled',
+ 'api' => array(
+ 'curid' => 2,
+ 'previd' => 1,
+ 'auto' => true,
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider providePatrolLogDatabaseRows
+ */
+ public function testPatrolLogDatabaseRows( $row, $extra ) {
+ $this->doTestLogFormatter( $row, $extra );
+ }
+}
--- /dev/null
+<?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_USER,
+ 'title' => 'User',
+ 'params' => array(
+ '4::oldgroups' => array(),
+ '5::newgroups' => array( 'sysop', 'bureaucrat' ),
+ ),
+ ),
+ array(
+ 'text' => 'Sysop changed group membership for User:User from (none) to '
+ . 'administrator and bureaucrat',
+ 'api' => array(
+ 'oldgroups' => array(),
+ 'newgroups' => array( 'sysop', 'bureaucrat' ),
+ ),
+ ),
+ ),
+
+ // 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,
+ 'text' => 'Sysop changed group membership for User:User from (none) to '
+ . 'administrator and bureaucrat',
+ 'api' => array(
+ 'oldgroups' => array(),
+ 'newgroups' => array( 'sysop', 'bureaucrat' ),
+ ),
+ ),
+ ),
+
+ // 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,
+ 'text' => 'Sysop changed group membership for User:User',
+ 'api' => array(),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @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_USER,
+ 'title' => 'Sysop',
+ 'params' => array(
+ '4::oldgroups' => array( 'sysop' ),
+ '5::newgroups' => array( 'sysop', 'bureaucrat' ),
+ ),
+ ),
+ array(
+ 'text' => 'Sysop was automatically promoted from administrator to '
+ . 'administrator and bureaucrat',
+ 'api' => array(
+ 'oldgroups' => array( 'sysop' ),
+ 'newgroups' => array( 'sysop', 'bureaucrat' ),
+ ),
+ ),
+ ),
+
+ // Legacy format
+ array(
+ array(
+ 'type' => 'rights',
+ 'action' => 'autopromote',
+ 'comment' => 'rights comment',
+ 'user' => 0,
+ 'user_text' => 'Sysop',
+ 'namespace' => NS_USER,
+ 'title' => 'Sysop',
+ 'params' => array(
+ 'sysop',
+ 'sysop, bureaucrat',
+ ),
+ ),
+ array(
+ 'legacy' => true,
+ 'text' => 'Sysop was automatically promoted from administrator to '
+ . 'administrator and bureaucrat',
+ 'api' => array(
+ 'oldgroups' => array( 'sysop' ),
+ 'newgroups' => array( 'sysop', 'bureaucrat' ),
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider provideAutopromoteLogDatabaseRows
+ */
+ public function testAutopromoteLogDatabaseRows( $row, $extra ) {
+ $this->doTestLogFormatter( $row, $extra );
+ }
+}
--- /dev/null
+<?php
+
+class UploadLogFormatterTest 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 provideUploadLogDatabaseRows() {
+ return array(
+ // Current format
+ array(
+ array(
+ 'type' => 'upload',
+ 'action' => 'upload',
+ 'comment' => 'upload comment',
+ 'namespace' => NS_FILE,
+ 'title' => 'File.png',
+ 'params' => array(
+ 'img_sha1' => 'hash',
+ 'img_timestamp' => '20150101000000',
+ ),
+ ),
+ array(
+ 'text' => 'User uploaded File:File.png',
+ 'api' => array(
+ 'img_sha1' => 'hash',
+ 'img_timestamp' => '2015-01-01T00:00:00Z',
+ ),
+ ),
+ ),
+
+ // Old format without params
+ array(
+ array(
+ 'type' => 'upload',
+ 'action' => 'upload',
+ 'comment' => 'upload comment',
+ 'namespace' => NS_FILE,
+ 'title' => 'File.png',
+ 'params' => array(),
+ ),
+ array(
+ 'text' => 'User uploaded File:File.png',
+ 'api' => array(),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider provideUploadLogDatabaseRows
+ */
+ public function testUploadLogDatabaseRows( $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 provideOverwriteLogDatabaseRows() {
+ return array(
+ // Current format
+ array(
+ array(
+ 'type' => 'upload',
+ 'action' => 'overwrite',
+ 'comment' => 'upload comment',
+ 'namespace' => NS_FILE,
+ 'title' => 'File.png',
+ 'params' => array(
+ 'img_sha1' => 'hash',
+ 'img_timestamp' => '20150101000000',
+ ),
+ ),
+ array(
+ 'text' => 'User uploaded a new version of File:File.png',
+ 'api' => array(
+ 'img_sha1' => 'hash',
+ 'img_timestamp' => '2015-01-01T00:00:00Z',
+ ),
+ ),
+ ),
+
+ // Old format without params
+ array(
+ array(
+ 'type' => 'upload',
+ 'action' => 'overwrite',
+ 'comment' => 'upload comment',
+ 'namespace' => NS_FILE,
+ 'title' => 'File.png',
+ 'params' => array(),
+ ),
+ array(
+ 'text' => 'User uploaded a new version of File:File.png',
+ 'api' => array(),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider provideOverwriteLogDatabaseRows
+ */
+ public function testOverwriteLogDatabaseRows( $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 provideRevertLogDatabaseRows() {
+ return array(
+ // Current format
+ array(
+ array(
+ 'type' => 'upload',
+ 'action' => 'revert',
+ 'comment' => 'upload comment',
+ 'namespace' => NS_FILE,
+ 'title' => 'File.png',
+ 'params' => array(
+ 'img_sha1' => 'hash',
+ 'img_timestamp' => '20150101000000',
+ ),
+ ),
+ array(
+ 'text' => 'User uploaded File:File.png',
+ 'api' => array(
+ 'img_sha1' => 'hash',
+ 'img_timestamp' => '2015-01-01T00:00:00Z',
+ ),
+ ),
+ ),
+
+ // Old format without params
+ array(
+ array(
+ 'type' => 'upload',
+ 'action' => 'revert',
+ 'comment' => 'upload comment',
+ 'namespace' => NS_FILE,
+ 'title' => 'File.png',
+ 'params' => array(),
+ ),
+ array(
+ 'text' => 'User uploaded File:File.png',
+ 'api' => array(),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider provideRevertLogDatabaseRows
+ */
+ public function testRevertLogDatabaseRows( $row, $extra ) {
+ $this->doTestLogFormatter( $row, $extra );
+ }
+}