ImportLogFormatterTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * @covers ImportLogFormatter
  4. */
  5. class ImportLogFormatterTest extends LogFormatterTestCase {
  6. /**
  7. * Provide different rows from the logging table to test
  8. * for backward compatibility.
  9. * Do not change the existing data, just add a new database row
  10. */
  11. public static function provideUploadLogDatabaseRows() {
  12. return [
  13. // Current format
  14. [
  15. [
  16. 'type' => 'import',
  17. 'action' => 'upload',
  18. 'comment' => 'upload comment',
  19. 'namespace' => NS_MAIN,
  20. 'title' => 'ImportPage',
  21. 'params' => [
  22. '4:number:count' => '1',
  23. ],
  24. ],
  25. [
  26. 'text' => 'User imported ImportPage by file upload (1 revision)',
  27. 'api' => [
  28. 'count' => 1,
  29. ],
  30. ],
  31. ],
  32. // old format - without details
  33. [
  34. [
  35. 'type' => 'import',
  36. 'action' => 'upload',
  37. 'comment' => '1 revision: import comment',
  38. 'namespace' => NS_MAIN,
  39. 'title' => 'ImportPage',
  40. 'params' => [],
  41. ],
  42. [
  43. 'text' => 'User imported ImportPage by file upload',
  44. 'api' => [],
  45. ],
  46. ],
  47. ];
  48. }
  49. /**
  50. * @dataProvider provideUploadLogDatabaseRows
  51. */
  52. public function testUploadLogDatabaseRows( $row, $extra ) {
  53. $this->doTestLogFormatter( $row, $extra );
  54. }
  55. /**
  56. * Provide different rows from the logging table to test
  57. * for backward compatibility.
  58. * Do not change the existing data, just add a new database row
  59. */
  60. public static function provideInterwikiLogDatabaseRows() {
  61. return [
  62. // Current format
  63. [
  64. [
  65. 'type' => 'import',
  66. 'action' => 'interwiki',
  67. 'comment' => 'interwiki comment',
  68. 'namespace' => NS_MAIN,
  69. 'title' => 'ImportPage',
  70. 'params' => [
  71. '4:number:count' => '1',
  72. '5:title-link:interwiki' => 'importiw:PageImport',
  73. ],
  74. ],
  75. [
  76. 'text' => 'User imported ImportPage from importiw:PageImport (1 revision)',
  77. 'api' => [
  78. 'count' => 1,
  79. 'interwiki_ns' => 0,
  80. 'interwiki_title' => 'importiw:PageImport',
  81. ],
  82. ],
  83. ],
  84. // old format - without details
  85. [
  86. [
  87. 'type' => 'import',
  88. 'action' => 'interwiki',
  89. 'comment' => '1 revision from importiw:PageImport: interwiki comment',
  90. 'namespace' => NS_MAIN,
  91. 'title' => 'ImportPage',
  92. 'params' => [],
  93. ],
  94. [
  95. 'text' => 'User imported ImportPage from another wiki',
  96. 'api' => [],
  97. ],
  98. ],
  99. ];
  100. }
  101. /**
  102. * @dataProvider provideInterwikiLogDatabaseRows
  103. */
  104. public function testInterwikiLogDatabaseRows( $row, $extra ) {
  105. // Setup importiw: as interwiki prefix
  106. $this->setMwGlobals( 'wgHooks', [
  107. 'InterwikiLoadPrefix' => [
  108. function ( $prefix, &$data ) {
  109. if ( $prefix == 'importiw' ) {
  110. $data = [ 'iw_url' => 'wikipedia' ];
  111. }
  112. return false;
  113. }
  114. ]
  115. ] );
  116. $this->doTestLogFormatter( $row, $extra );
  117. }
  118. }