wiki.techinc.nl/tests/phpunit/includes/logging/ImportLogFormatterTest.php
C. Scott Ananian 3d40c43b1f Deprecate InterwikiLoadPrefix hook
The InterwikiLoadPrefix hook isn't compatible with Parsoid, as it is
unidirectional and doesn't support enumerating all valid prefixes
(T270444).  Set/reset $wgInterwikiCache to mock the interwiki table
for parserTests and other unit tests instead.

This is a soft deprecation, as the used-in-production
Extension:Interwiki still uses InterwikiLoadPrefix, although not in a
way that would break Parsoid (since $wgInterwikiCache is set in
production).

Bug: T270444
Change-Id: If2507017c99c4ee42c104a0890bc45a84d7239d5
2020-12-21 19:28:48 +00:00

126 lines
2.7 KiB
PHP

<?php
use MediaWiki\Interwiki\ClassicInterwikiLookup;
/**
* @covers ImportLogFormatter
*/
class ImportLogFormatterTest 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' => 'import',
'action' => 'upload',
'comment' => 'upload comment',
'namespace' => NS_MAIN,
'title' => 'ImportPage',
'params' => [
'4:number:count' => '1',
],
],
[
'text' => 'User imported ImportPage by file upload (1 revision)',
'api' => [
'count' => 1,
],
],
],
// old format - without details
[
[
'type' => 'import',
'action' => 'upload',
'comment' => '1 revision: import comment',
'namespace' => NS_MAIN,
'title' => 'ImportPage',
'params' => [],
],
[
'text' => 'User imported ImportPage by file upload',
'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 provideInterwikiLogDatabaseRows() {
return [
// Current format
[
[
'type' => 'import',
'action' => 'interwiki',
'comment' => 'interwiki comment',
'namespace' => NS_MAIN,
'title' => 'ImportPage',
'params' => [
'4:number:count' => '1',
'5:title-link:interwiki' => 'importiw:PageImport',
],
],
[
'text' => 'User imported ImportPage from importiw:PageImport (1 revision)',
'api' => [
'count' => 1,
'interwiki_ns' => 0,
'interwiki_title' => 'importiw:PageImport',
],
],
],
// old format - without details
[
[
'type' => 'import',
'action' => 'interwiki',
'comment' => '1 revision from importiw:PageImport: interwiki comment',
'namespace' => NS_MAIN,
'title' => 'ImportPage',
'params' => [],
],
[
'text' => 'User imported ImportPage from another wiki',
'api' => [],
],
],
];
}
/**
* @dataProvider provideInterwikiLogDatabaseRows
*/
public function testInterwikiLogDatabaseRows( $row, $extra ) {
// Setup importiw: as interwiki prefix
$this->setMwGlobals( [
'wgInterwikiCache' => ClassicInterwikiLookup::buildCdbHash( [
[
'iw_prefix' => 'importiw',
'iw_url' => 'wikipedia'
],
] ),
] );
$this->doTestLogFormatter( $row, $extra );
}
}