summaryrefslogtreecommitdiff
path: root/www/wiki/tests/phpunit/includes/logging/ImportLogFormatterTest.php
blob: 80e4c0bc8ab8034c2a287cc144a422310f7775f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php

/**
 * @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( 'wgHooks', [
			'InterwikiLoadPrefix' => [
				function ( $prefix, &$data ) {
					if ( $prefix == 'importiw' ) {
						$data = [ 'iw_url' => 'wikipedia' ];
					}
					return false;
				}
			]
		] );

		$this->doTestLogFormatter( $row, $extra );
	}
}