6 class ChangeTagsTest
extends MediaWikiTestCase
{
8 // TODO only modifyDisplayQuery is tested, nothing else is
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']
20 if ( isset( $modifiedQuery['exception'] ) ) {
21 $this->setExpectedException( $modifiedQuery['exception'] );
23 ChangeTags
::modifyDisplayQuery(
27 $origQuery['join_conds'],
28 $origQuery['options'],
31 if ( !isset( $modifiedQuery['exception'] ) ) {
32 $this->assertArrayEquals(
35 /* ordered = */ false,
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
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' ],
52 'simple recentchanges query' => [
54 'tables' => [ 'recentchanges' ],
55 'fields' => [ 'rc_id', 'rc_timestamp' ],
56 'conds' => [ "rc_timestamp > '20170714183203'" ],
58 'options' => [ 'ORDER BY' => 'rc_timestamp DESC' ],
61 true, // tag filtering enabled
63 'tables' => [ 'recentchanges' ],
64 'fields' => [ 'rc_id', 'rc_timestamp', 'ts_tags' => $groupConcats['recentchanges'] ],
65 'conds' => [ "rc_timestamp > '20170714183203'" ],
67 'options' => [ 'ORDER BY' => 'rc_timestamp DESC' ],
70 'simple query with strings' => [
72 'tables' => 'recentchanges',
74 'conds' => "rc_timestamp > '20170714183203'",
76 'options' => 'ORDER BY rc_timestamp DESC',
79 true, // tag filtering enabled
81 'tables' => [ 'recentchanges' ],
82 'fields' => [ 'rc_id', 'ts_tags' => $groupConcats['recentchanges'] ],
83 'conds' => [ "rc_timestamp > '20170714183203'" ],
85 'options' => [ 'ORDER BY rc_timestamp DESC' ],
88 'recentchanges query with single tag filter' => [
90 'tables' => [ 'recentchanges' ],
91 'fields' => [ 'rc_id', 'rc_timestamp' ],
92 'conds' => [ "rc_timestamp > '20170714183203'" ],
94 'options' => [ 'ORDER BY' => 'rc_timestamp DESC' ],
97 true, // tag filtering enabled
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' ],
106 'logging query with single tag filter and strings' => [
108 'tables' => 'logging',
109 'fields' => 'log_id',
110 'conds' => "log_timestamp > '20170714183203'",
112 'options' => 'ORDER BY log_timestamp DESC',
115 true, // tag filtering enabled
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' ],
124 'revision query with single tag filter' => [
126 'tables' => [ 'revision' ],
127 'fields' => [ 'rev_id', 'rev_timestamp' ],
128 'conds' => [ "rev_timestamp > '20170714183203'" ],
130 'options' => [ 'ORDER BY' => 'rev_timestamp DESC' ],
133 true, // tag filtering enabled
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' ],
142 'archive query with single tag filter' => [
144 'tables' => [ 'archive' ],
145 'fields' => [ 'ar_id', 'ar_timestamp' ],
146 'conds' => [ "ar_timestamp > '20170714183203'" ],
148 'options' => [ 'ORDER BY' => 'ar_timestamp DESC' ],
151 true, // tag filtering enabled
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' ],
160 'unsupported table name throws exception (even without tag filter)' => [
162 'tables' => [ 'foobar' ],
163 'fields' => [ 'fb_id', 'fb_timestamp' ],
164 'conds' => [ "fb_timestamp > '20170714183203'" ],
166 'options' => [ 'ORDER BY' => 'fb_timestamp DESC' ],
169 true, // tag filtering enabled
170 [ 'exception' => MWException
::class ]
172 'tag filter ignored when tag filtering is disabled' => [
174 'tables' => [ 'archive' ],
175 'fields' => [ 'ar_id', 'ar_timestamp' ],
176 'conds' => [ "ar_timestamp > '20170714183203'" ],
178 'options' => [ 'ORDER BY' => 'ar_timestamp DESC' ],
181 false, // tag filtering disabled
183 'tables' => [ 'archive' ],
184 'fields' => [ 'ar_id', 'ar_timestamp', 'ts_tags' => $groupConcats['archive'] ],
185 'conds' => [ "ar_timestamp > '20170714183203'" ],
187 'options' => [ 'ORDER BY' => 'ar_timestamp DESC' ],
190 'recentchanges query with multiple tag filter' => [
192 'tables' => [ 'recentchanges' ],
193 'fields' => [ 'rc_id', 'rc_timestamp' ],
194 'conds' => [ "rc_timestamp > '20170714183203'" ],
196 'options' => [ 'ORDER BY' => 'rc_timestamp DESC' ],
199 true, // tag filtering enabled
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' ],
208 'recentchanges query with multiple tag filter that already has DISTINCT' => [
210 'tables' => [ 'recentchanges' ],
211 'fields' => [ 'rc_id', 'rc_timestamp' ],
212 'conds' => [ "rc_timestamp > '20170714183203'" ],
214 'options' => [ 'DISTINCT', 'ORDER BY' => 'rc_timestamp DESC' ],
217 true, // tag filtering enabled
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' ],
226 'recentchanges query with multiple tag filter with strings' => [
228 'tables' => 'recentchanges',
230 'conds' => "rc_timestamp > '20170714183203'",
232 'options' => 'ORDER BY rc_timestamp DESC',
235 true, // tag filtering enabled
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' ],