wiki.techinc.nl/tests/phpunit/includes/logging/UploadLogFormatterTest.php
MGChecker 84c46d38b7 Add separate log action for file reverts
This change s adds 'revert' as a separate log action for file reverts, as it
allows special formatting of log entries and revisions in UI and filtering
for file reverts specifically.

Even though there are no log entries with this log action right now, it does
seem that this was intended as some point, as there are corresponding
test cases in UploadLogFormatterTest, and is listed in
$wgLogActionsHandlers and https://www.mediawiki.org/wiki/API:Logevents
as well. Furthermore, the i18n message 'logentry-upload-revert' already
existed before this change.

Because this functionality can not be provided by tags, the 'mw-undo' tag
is not suited for this use case. However, it could be added additionally to
all log entries with this log action..

Bug: T60209
Change-Id: Ie1ccd8053dc5de58b2297a8460219f0233aab968
2019-03-02 22:16:55 +00:00

169 lines
3.6 KiB
PHP

<?php
/**
* @covers UploadLogFormatter
*/
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 [
// Current format
[
[
'type' => 'upload',
'action' => 'upload',
'comment' => 'upload comment',
'namespace' => NS_FILE,
'title' => 'File.png',
'params' => [
'img_sha1' => 'hash',
'img_timestamp' => '20150101000000',
],
],
[
'text' => 'User uploaded File:File.png',
'api' => [
'img_sha1' => 'hash',
'img_timestamp' => '2015-01-01T00:00:00Z',
],
],
],
// Old format without params
[
[
'type' => 'upload',
'action' => 'upload',
'comment' => 'upload comment',
'namespace' => NS_FILE,
'title' => 'File.png',
'params' => [],
],
[
'text' => 'User uploaded File:File.png',
'api' => [],
],
],
];
}
/**
* @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 [
// Current format
[
[
'type' => 'upload',
'action' => 'overwrite',
'comment' => 'upload comment',
'namespace' => NS_FILE,
'title' => 'File.png',
'params' => [
'img_sha1' => 'hash',
'img_timestamp' => '20150101000000',
],
],
[
'text' => 'User uploaded a new version of File:File.png',
'api' => [
'img_sha1' => 'hash',
'img_timestamp' => '2015-01-01T00:00:00Z',
],
],
],
// Old format without params
[
[
'type' => 'upload',
'action' => 'overwrite',
'comment' => 'upload comment',
'namespace' => NS_FILE,
'title' => 'File.png',
'params' => [],
],
[
'text' => 'User uploaded a new version of File:File.png',
'api' => [],
],
],
];
}
/**
* @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 [
// Current format
[
[
'type' => 'upload',
'action' => 'revert',
'comment' => 'upload comment',
'namespace' => NS_FILE,
'title' => 'File.png',
'params' => [
'img_sha1' => 'hash',
'img_timestamp' => '20150101000000',
],
],
[
'text' => 'User reverted File:File.png to an old version',
'api' => [
'img_sha1' => 'hash',
'img_timestamp' => '2015-01-01T00:00:00Z',
],
],
],
// Old format without params
[
[
'type' => 'upload',
'action' => 'revert',
'comment' => 'upload comment',
'namespace' => NS_FILE,
'title' => 'File.png',
'params' => [],
],
[
'text' => 'User reverted File:File.png to an old version',
'api' => [],
],
],
];
}
/**
* @dataProvider provideRevertLogDatabaseRows
*/
public function testRevertLogDatabaseRows( $row, $extra ) {
$this->doTestLogFormatter( $row, $extra );
}
}