Merge "Improve "selfmove" message's wording"
[lhc/web/wiklou.git] / tests / phpunit / includes / changetags / ChangeTagsTest.php
1 <?php
2
3 /**
4 * @covers ChangeTags
5 */
6 class ChangeTagsTest extends MediaWikiTestCase {
7
8 // TODO only modifyDisplayQuery is tested, nothing else is
9
10 /** @dataProvider provideModifyDisplayQuery */
11 public function testModifyDisplayQuery( $origQuery, $filter_tag, $useTags, $modifiedQuery ) {
12 $this->setMwGlobals( 'wgUseTagFilter', $useTags );
13 // HACK resolve deferred group concats (see comment in provideModifyDisplayQuery)
14 if ( isset( $modifiedQuery['fields']['ts_tags'] ) ) {
15 $modifiedQuery['fields']['ts_tags'] = call_user_func_array(
16 [ wfGetDB( DB_REPLICA ), 'buildGroupConcatField' ],
17 $modifiedQuery['fields']['ts_tags']
18 );
19 }
20 if ( isset( $modifiedQuery['exception'] ) ) {
21 $this->setExpectedException( $modifiedQuery['exception'] );
22 }
23 ChangeTags::modifyDisplayQuery(
24 $origQuery['tables'],
25 $origQuery['fields'],
26 $origQuery['conds'],
27 $origQuery['join_conds'],
28 $origQuery['options'],
29 $filter_tag
30 );
31 if ( !isset( $modifiedQuery['exception'] ) ) {
32 $this->assertArrayEquals(
33 $modifiedQuery,
34 $origQuery,
35 /* ordered = */ false,
36 /* named = */ true
37 );
38 }
39 }
40
41 public function provideModifyDisplayQuery() {
42 // HACK if we call $dbr->buildGroupConcatField() now, it will return the wrong table names
43 // We have to have the test runner call it instead
44 $groupConcats = [
45 'recentchanges' => [ ',', 'change_tag', 'ct_tag', 'ct_rc_id=rc_id' ],
46 'logging' => [ ',', 'change_tag', 'ct_tag', 'ct_log_id=log_id' ],
47 'revision' => [ ',', 'change_tag', 'ct_tag', 'ct_rev_id=rev_id' ],
48 'archive' => [ ',', 'change_tag', 'ct_tag', 'ct_rev_id=ar_rev_id' ],
49 ];
50
51 return [
52 'simple recentchanges query' => [
53 [
54 'tables' => [ 'recentchanges' ],
55 'fields' => [ 'rc_id', 'rc_timestamp' ],
56 'conds' => [ "rc_timestamp > '20170714183203'" ],
57 'join_conds' => [],
58 'options' => [ 'ORDER BY' => 'rc_timestamp DESC' ],
59 ],
60 '', // no tag filter
61 true, // tag filtering enabled
62 [
63 'tables' => [ 'recentchanges' ],
64 'fields' => [ 'rc_id', 'rc_timestamp', 'ts_tags' => $groupConcats['recentchanges'] ],
65 'conds' => [ "rc_timestamp > '20170714183203'" ],
66 'join_conds' => [],
67 'options' => [ 'ORDER BY' => 'rc_timestamp DESC' ],
68 ]
69 ],
70 'simple query with strings' => [
71 [
72 'tables' => 'recentchanges',
73 'fields' => 'rc_id',
74 'conds' => "rc_timestamp > '20170714183203'",
75 'join_conds' => [],
76 'options' => 'ORDER BY rc_timestamp DESC',
77 ],
78 '', // no tag filter
79 true, // tag filtering enabled
80 [
81 'tables' => [ 'recentchanges' ],
82 'fields' => [ 'rc_id', 'ts_tags' => $groupConcats['recentchanges'] ],
83 'conds' => [ "rc_timestamp > '20170714183203'" ],
84 'join_conds' => [],
85 'options' => [ 'ORDER BY rc_timestamp DESC' ],
86 ]
87 ],
88 'recentchanges query with single tag filter' => [
89 [
90 'tables' => [ 'recentchanges' ],
91 'fields' => [ 'rc_id', 'rc_timestamp' ],
92 'conds' => [ "rc_timestamp > '20170714183203'" ],
93 'join_conds' => [],
94 'options' => [ 'ORDER BY' => 'rc_timestamp DESC' ],
95 ],
96 'foo',
97 true, // tag filtering enabled
98 [
99 'tables' => [ 'recentchanges', 'change_tag' ],
100 'fields' => [ 'rc_id', 'rc_timestamp', 'ts_tags' => $groupConcats['recentchanges'] ],
101 'conds' => [ "rc_timestamp > '20170714183203'", 'ct_tag' => 'foo' ],
102 'join_conds' => [ 'change_tag' => [ 'INNER JOIN', 'ct_rc_id=rc_id' ] ],
103 'options' => [ 'ORDER BY' => 'rc_timestamp DESC' ],
104 ]
105 ],
106 'logging query with single tag filter and strings' => [
107 [
108 'tables' => 'logging',
109 'fields' => 'log_id',
110 'conds' => "log_timestamp > '20170714183203'",
111 'join_conds' => [],
112 'options' => 'ORDER BY log_timestamp DESC',
113 ],
114 'foo',
115 true, // tag filtering enabled
116 [
117 'tables' => [ 'logging', 'change_tag' ],
118 'fields' => [ 'log_id', 'ts_tags' => $groupConcats['logging'] ],
119 'conds' => [ "log_timestamp > '20170714183203'", 'ct_tag' => 'foo' ],
120 'join_conds' => [ 'change_tag' => [ 'INNER JOIN', 'ct_log_id=log_id' ] ],
121 'options' => [ 'ORDER BY log_timestamp DESC' ],
122 ]
123 ],
124 'revision query with single tag filter' => [
125 [
126 'tables' => [ 'revision' ],
127 'fields' => [ 'rev_id', 'rev_timestamp' ],
128 'conds' => [ "rev_timestamp > '20170714183203'" ],
129 'join_conds' => [],
130 'options' => [ 'ORDER BY' => 'rev_timestamp DESC' ],
131 ],
132 'foo',
133 true, // tag filtering enabled
134 [
135 'tables' => [ 'revision', 'change_tag' ],
136 'fields' => [ 'rev_id', 'rev_timestamp', 'ts_tags' => $groupConcats['revision'] ],
137 'conds' => [ "rev_timestamp > '20170714183203'", 'ct_tag' => 'foo' ],
138 'join_conds' => [ 'change_tag' => [ 'INNER JOIN', 'ct_rev_id=rev_id' ] ],
139 'options' => [ 'ORDER BY' => 'rev_timestamp DESC' ],
140 ]
141 ],
142 'archive query with single tag filter' => [
143 [
144 'tables' => [ 'archive' ],
145 'fields' => [ 'ar_id', 'ar_timestamp' ],
146 'conds' => [ "ar_timestamp > '20170714183203'" ],
147 'join_conds' => [],
148 'options' => [ 'ORDER BY' => 'ar_timestamp DESC' ],
149 ],
150 'foo',
151 true, // tag filtering enabled
152 [
153 'tables' => [ 'archive', 'change_tag' ],
154 'fields' => [ 'ar_id', 'ar_timestamp', 'ts_tags' => $groupConcats['archive'] ],
155 'conds' => [ "ar_timestamp > '20170714183203'", 'ct_tag' => 'foo' ],
156 'join_conds' => [ 'change_tag' => [ 'INNER JOIN', 'ct_rev_id=ar_rev_id' ] ],
157 'options' => [ 'ORDER BY' => 'ar_timestamp DESC' ],
158 ]
159 ],
160 'unsupported table name throws exception (even without tag filter)' => [
161 [
162 'tables' => [ 'foobar' ],
163 'fields' => [ 'fb_id', 'fb_timestamp' ],
164 'conds' => [ "fb_timestamp > '20170714183203'" ],
165 'join_conds' => [],
166 'options' => [ 'ORDER BY' => 'fb_timestamp DESC' ],
167 ],
168 '',
169 true, // tag filtering enabled
170 [ 'exception' => MWException::class ]
171 ],
172 'tag filter ignored when tag filtering is disabled' => [
173 [
174 'tables' => [ 'archive' ],
175 'fields' => [ 'ar_id', 'ar_timestamp' ],
176 'conds' => [ "ar_timestamp > '20170714183203'" ],
177 'join_conds' => [],
178 'options' => [ 'ORDER BY' => 'ar_timestamp DESC' ],
179 ],
180 'foo',
181 false, // tag filtering disabled
182 [
183 'tables' => [ 'archive' ],
184 'fields' => [ 'ar_id', 'ar_timestamp', 'ts_tags' => $groupConcats['archive'] ],
185 'conds' => [ "ar_timestamp > '20170714183203'" ],
186 'join_conds' => [],
187 'options' => [ 'ORDER BY' => 'ar_timestamp DESC' ],
188 ]
189 ],
190 'recentchanges query with multiple tag filter' => [
191 [
192 'tables' => [ 'recentchanges' ],
193 'fields' => [ 'rc_id', 'rc_timestamp' ],
194 'conds' => [ "rc_timestamp > '20170714183203'" ],
195 'join_conds' => [],
196 'options' => [ 'ORDER BY' => 'rc_timestamp DESC' ],
197 ],
198 [ 'foo', 'bar' ],
199 true, // tag filtering enabled
200 [
201 'tables' => [ 'recentchanges', 'change_tag' ],
202 'fields' => [ 'rc_id', 'rc_timestamp', 'ts_tags' => $groupConcats['recentchanges'] ],
203 'conds' => [ "rc_timestamp > '20170714183203'", 'ct_tag' => [ 'foo', 'bar' ] ],
204 'join_conds' => [ 'change_tag' => [ 'INNER JOIN', 'ct_rc_id=rc_id' ] ],
205 'options' => [ 'ORDER BY' => 'rc_timestamp DESC', 'DISTINCT' ],
206 ]
207 ],
208 'recentchanges query with multiple tag filter that already has DISTINCT' => [
209 [
210 'tables' => [ 'recentchanges' ],
211 'fields' => [ 'rc_id', 'rc_timestamp' ],
212 'conds' => [ "rc_timestamp > '20170714183203'" ],
213 'join_conds' => [],
214 'options' => [ 'DISTINCT', 'ORDER BY' => 'rc_timestamp DESC' ],
215 ],
216 [ 'foo', 'bar' ],
217 true, // tag filtering enabled
218 [
219 'tables' => [ 'recentchanges', 'change_tag' ],
220 'fields' => [ 'rc_id', 'rc_timestamp', 'ts_tags' => $groupConcats['recentchanges'] ],
221 'conds' => [ "rc_timestamp > '20170714183203'", 'ct_tag' => [ 'foo', 'bar' ] ],
222 'join_conds' => [ 'change_tag' => [ 'INNER JOIN', 'ct_rc_id=rc_id' ] ],
223 'options' => [ 'DISTINCT', 'ORDER BY' => 'rc_timestamp DESC' ],
224 ]
225 ],
226 'recentchanges query with multiple tag filter with strings' => [
227 [
228 'tables' => 'recentchanges',
229 'fields' => 'rc_id',
230 'conds' => "rc_timestamp > '20170714183203'",
231 'join_conds' => [],
232 'options' => 'ORDER BY rc_timestamp DESC',
233 ],
234 [ 'foo', 'bar' ],
235 true, // tag filtering enabled
236 [
237 'tables' => [ 'recentchanges', 'change_tag' ],
238 'fields' => [ 'rc_id', 'ts_tags' => $groupConcats['recentchanges'] ],
239 'conds' => [ "rc_timestamp > '20170714183203'", 'ct_tag' => [ 'foo', 'bar' ] ],
240 'join_conds' => [ 'change_tag' => [ 'INNER JOIN', 'ct_rc_id=rc_id' ] ],
241 'options' => [ 'ORDER BY rc_timestamp DESC', 'DISTINCT' ],
242 ]
243 ],
244 ];
245 }
246
247 }