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
127
128
129
130
131
132
133
|
<?php
/**
* @group Echo
* @covers EchoSuppressionRowUpdateGenerator
*/
class SuppressionMaintenanceTest extends MediaWikiTestCase {
public static function provider_updateRow() {
$input = [
'event_id' => 2,
'event_type' => 'mention',
'event_variant' => null,
'event_agent_id' => 3,
'event_agent_ip' => null,
'event_page_title' => '',
'event_page_namespace' => 0,
'event_page_extra' => null,
'event_extra' => null,
'event_page_id' => null,
];
return [
[ 'Unrelated row must result in no update', [], $input ],
[
'Page title and namespace for non-existant page must move into event_extra',
[ // expected update
'event_extra' => serialize( [
'page_title' => 'Yabba Dabba Do',
'page_namespace' => NS_MAIN
] ),
],
[ // input row
'event_page_title' => 'Yabba Dabba Do',
'event_page_namespace' => NS_MAIN,
] + $input,
],
[
'Page title and namespace for existing page must be result in update to event_page_id',
[ // expected update
'event_page_id' => 42,
],
[ // input row
'event_page_title' => 'Mount Rushmore',
'event_page_namespace' => NS_MAIN,
] + $input,
self::attachTitleFor( 42, 'Mount Rushmore', NS_MAIN )
],
[
'When updating non-existant page must keep old extra data',
[ // expected update
'event_extra' => serialize( [
'foo' => 'bar',
'page_title' => 'Yabba Dabba Do',
'page_namespace' => NS_MAIN
] ),
],
[ // input row
'event_page_title' => 'Yabba Dabba Do',
'event_page_namespace' => NS_MAIN,
'event_extra' => serialize( [ 'foo' => 'bar' ] ),
] + $input,
],
[
'Must update link-from-title/namespace to link-from-page-id for page-linked events',
[ // expected update
'event_extra' => serialize( [ 'link-from-page-id' => 99 ] ),
],
[ // input row
'event_type' => 'page-linked',
'event_extra' => serialize( [
'link-from-title' => 'Horse',
'link-from-namespace' => NS_USER_TALK
] ),
] + $input,
self::attachTitleFor( 99, 'Horse', NS_USER_TALK )
],
[
'Must perform both generic update and page-linked update at same time',
[ // expected update
'event_extra' => serialize( [ 'link-from-page-id' => 8675309 ] ),
'event_page_id' => 8675309,
],
[ // input row
'event_type' => 'page-linked',
'event_extra' => serialize( [
'link-from-title' => 'Jenny',
'link-from-namespace' => NS_MAIN,
] ),
'event_page_title' => 'Jenny',
'event_page_namespace' => NS_MAIN,
] + $input,
self::attachTitleFor( 8675309, 'Jenny', NS_MAIN ),
],
];
}
protected static function attachTitleFor( $id, $providedText, $providedNamespace ) {
return function ( $test, $gen ) use ( $id, $providedText, $providedNamespace ) {
$title = $test->getMock( 'Title' );
$title->expects( $test->any() )
->method( 'getArticleId' )
->will( $test->returnValue( $id ) );
$titles = [ $providedNamespace => [ $providedText => $title ] ];
$gen->setNewTitleFromNsAndText( function ( $namespace, $text ) use ( $titles ) {
if ( isset( $titles[$namespace][$text] ) ) {
return $titles[$namespace][$text];
}
return Title::makeTitleSafe( $namespace, $text );
} );
};
}
/**
* @dataProvider provider_updateRow
*/
public function testUpdateRow( $message, $expected, $input, $callable = null ) {
$gen = new EchoSuppressionRowUpdateGenerator;
if ( $callable ) {
call_user_func( $callable, $this, $gen );
}
$update = $gen->update( (object)$input );
$this->assertEquals( $expected, $update, $message );
}
}
|