Fix assertArrayEquals() calls with bogus 3rd parameter
[lhc/web/wiklou.git] / tests / phpunit / includes / specialpage / ChangesListSpecialPageTest.php
1 <?php
2
3 use Wikimedia\TestingAccessWrapper;
4
5 /**
6 * Test class for ChangesListSpecialPage class
7 *
8 * Copyright © 2011-, Antoine Musso, Stephane Bisson, Matthew Flaschen
9 *
10 * @author Antoine Musso
11 * @author Stephane Bisson
12 * @author Matthew Flaschen
13 * @group Database
14 *
15 * @covers ChangesListSpecialPage
16 */
17 class ChangesListSpecialPageTest extends AbstractChangesListSpecialPageTestCase {
18 protected function getPage() {
19 $mock = $this->getMockBuilder( ChangesListSpecialPage::class )
20 ->setConstructorArgs(
21 [
22 'ChangesListSpecialPage',
23 ''
24 ]
25 )
26 ->setMethods( [ 'getPageTitle' ] )
27 ->getMockForAbstractClass();
28
29 $mock->method( 'getPageTitle' )->willReturn(
30 Title::makeTitle( NS_SPECIAL, 'ChangesListSpecialPage' )
31 );
32
33 $mock = TestingAccessWrapper::newFromObject(
34 $mock
35 );
36
37 return $mock;
38 }
39
40 private function buildQuery(
41 $requestOptions = null,
42 $user = null
43 ) {
44 $context = new RequestContext;
45 $context->setRequest( new FauxRequest( $requestOptions ) );
46 if ( $user ) {
47 $context->setUser( $user );
48 }
49
50 $this->changesListSpecialPage->setContext( $context );
51 $this->changesListSpecialPage->filterGroups = [];
52 $formOptions = $this->changesListSpecialPage->setup( null );
53
54 #  Filter out rc_timestamp conditions which depends on the test runtime
55 # This condition is not needed as of march 2, 2011 -- hashar
56 # @todo FIXME: Find a way to generate the correct rc_timestamp
57
58 $tables = [];
59 $fields = [];
60 $queryConditions = [];
61 $query_options = [];
62 $join_conds = [];
63
64 call_user_func_array(
65 [ $this->changesListSpecialPage, 'buildQuery' ],
66 [
67 &$tables,
68 &$fields,
69 &$queryConditions,
70 &$query_options,
71 &$join_conds,
72 $formOptions
73 ]
74 );
75
76 $queryConditions = array_filter(
77 $queryConditions,
78 'ChangesListSpecialPageTest::filterOutRcTimestampCondition'
79 );
80
81 return $queryConditions;
82 }
83
84 /** helper to test SpecialRecentchanges::buildQuery() */
85 private function assertConditions(
86 $expected,
87 $requestOptions = null,
88 $message = '',
89 $user = null
90 ) {
91 $queryConditions = $this->buildQuery( $requestOptions, $user );
92
93 $this->assertEquals(
94 self::normalizeCondition( $expected ),
95 self::normalizeCondition( $queryConditions ),
96 $message
97 );
98 }
99
100 private static function normalizeCondition( $conds ) {
101 $dbr = wfGetDB( DB_REPLICA );
102 $normalized = array_map(
103 function ( $k, $v ) use ( $dbr ) {
104 if ( is_array( $v ) ) {
105 sort( $v );
106 }
107 // (Ab)use makeList() to format only this entry
108 return $dbr->makeList( [ $k => $v ], Database::LIST_AND );
109 },
110 array_keys( $conds ),
111 $conds
112 );
113 sort( $normalized );
114 return $normalized;
115 }
116
117 /** return false if condition begins with 'rc_timestamp ' */
118 private static function filterOutRcTimestampCondition( $var ) {
119 return ( is_array( $var ) || strpos( $var, 'rc_timestamp ' ) === false );
120 }
121
122 public function testRcNsFilter() {
123 $this->assertConditions(
124 [ # expected
125 "rc_namespace = '0'",
126 ],
127 [
128 'namespace' => NS_MAIN,
129 ],
130 "rc conditions with one namespace"
131 );
132 }
133
134 public function testRcNsFilterInversion() {
135 $this->assertConditions(
136 [ # expected
137 "rc_namespace != '0'",
138 ],
139 [
140 'namespace' => NS_MAIN,
141 'invert' => 1,
142 ],
143 "rc conditions with namespace inverted"
144 );
145 }
146
147 public function testRcNsFilterMultiple() {
148 $this->assertConditions(
149 [ # expected
150 "rc_namespace IN ('1','2','3')",
151 ],
152 [
153 'namespace' => '1;2;3',
154 ],
155 "rc conditions with multiple namespaces"
156 );
157 }
158
159 public function testRcNsFilterMultipleAssociated() {
160 $this->assertConditions(
161 [ # expected
162 "rc_namespace IN ('0','1','4','5','6','7')",
163 ],
164 [
165 'namespace' => '1;4;7',
166 'associated' => 1,
167 ],
168 "rc conditions with multiple namespaces and associated"
169 );
170 }
171
172 public function testRcNsFilterMultipleAssociatedInvert() {
173 $this->assertConditions(
174 [ # expected
175 "rc_namespace NOT IN ('2','3','8','9')",
176 ],
177 [
178 'namespace' => '2;3;9',
179 'associated' => 1,
180 'invert' => 1
181 ],
182 "rc conditions with multiple namespaces, associated and inverted"
183 );
184 }
185
186 public function testRcNsFilterMultipleInvert() {
187 $this->assertConditions(
188 [ # expected
189 "rc_namespace NOT IN ('1','2','3')",
190 ],
191 [
192 'namespace' => '1;2;3',
193 'invert' => 1,
194 ],
195 "rc conditions with multiple namespaces inverted"
196 );
197 }
198
199 public function testRcHidemyselfFilter() {
200 $this->setMwGlobals(
201 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
202 );
203 $this->overrideMwServices();
204
205 $user = $this->getTestUser()->getUser();
206 $user->getActorId( wfGetDB( DB_MASTER ) );
207 $this->assertConditions(
208 [ # expected
209 "NOT((rc_user = '{$user->getId()}'))",
210 ],
211 [
212 'hidemyself' => 1,
213 ],
214 "rc conditions: hidemyself=1 (logged in)",
215 $user
216 );
217
218 $user = User::newFromName( '10.11.12.13', false );
219 $id = $user->getActorId( wfGetDB( DB_MASTER ) );
220 $this->assertConditions(
221 [ # expected
222 "NOT((rc_user_text = '10.11.12.13'))",
223 ],
224 [
225 'hidemyself' => 1,
226 ],
227 "rc conditions: hidemyself=1 (anon)",
228 $user
229 );
230 }
231
232 public function testRcHidebyothersFilter() {
233 $this->setMwGlobals(
234 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
235 );
236 $this->overrideMwServices();
237
238 $user = $this->getTestUser()->getUser();
239 $user->getActorId( wfGetDB( DB_MASTER ) );
240 $this->assertConditions(
241 [ # expected
242 "(rc_user_text = '{$user->getName()}')",
243 ],
244 [
245 'hidebyothers' => 1,
246 ],
247 "rc conditions: hidebyothers=1 (logged in)",
248 $user
249 );
250
251 $user = User::newFromName( '10.11.12.13', false );
252 $id = $user->getActorId( wfGetDB( DB_MASTER ) );
253 $this->assertConditions(
254 [ # expected
255 "(rc_user_text = '10.11.12.13')",
256 ],
257 [
258 'hidebyothers' => 1,
259 ],
260 "rc conditions: hidebyothers=1 (anon)",
261 $user
262 );
263 }
264
265 public function testRcHidepageedits() {
266 $this->assertConditions(
267 [ # expected
268 "rc_type != '0'",
269 ],
270 [
271 'hidepageedits' => 1,
272 ],
273 "rc conditions: hidepageedits=1"
274 );
275 }
276
277 public function testRcHidenewpages() {
278 $this->assertConditions(
279 [ # expected
280 "rc_type != '1'",
281 ],
282 [
283 'hidenewpages' => 1,
284 ],
285 "rc conditions: hidenewpages=1"
286 );
287 }
288
289 public function testRcHidelog() {
290 $this->assertConditions(
291 [ # expected
292 "rc_type != '3'",
293 ],
294 [
295 'hidelog' => 1,
296 ],
297 "rc conditions: hidelog=1"
298 );
299 }
300
301 public function testRcHidehumans() {
302 $this->assertConditions(
303 [ # expected
304 'rc_bot' => 1,
305 ],
306 [
307 'hidebots' => 0,
308 'hidehumans' => 1,
309 ],
310 "rc conditions: hidebots=0 hidehumans=1"
311 );
312 }
313
314 public function testRcHidepatrolledDisabledFilter() {
315 $this->setMwGlobals( 'wgUseRCPatrol', false );
316 $user = $this->getTestUser()->getUser();
317 $this->assertConditions(
318 [ # expected
319 ],
320 [
321 'hidepatrolled' => 1,
322 ],
323 "rc conditions: hidepatrolled=1 (user not allowed)",
324 $user
325 );
326 }
327
328 public function testRcHideunpatrolledDisabledFilter() {
329 $this->setMwGlobals( 'wgUseRCPatrol', false );
330 $user = $this->getTestUser()->getUser();
331 $this->assertConditions(
332 [ # expected
333 ],
334 [
335 'hideunpatrolled' => 1,
336 ],
337 "rc conditions: hideunpatrolled=1 (user not allowed)",
338 $user
339 );
340 }
341 public function testRcHidepatrolledFilter() {
342 $user = $this->getTestSysop()->getUser();
343 $this->assertConditions(
344 [ # expected
345 'rc_patrolled' => 0,
346 ],
347 [
348 'hidepatrolled' => 1,
349 ],
350 "rc conditions: hidepatrolled=1",
351 $user
352 );
353 }
354
355 public function testRcHideunpatrolledFilter() {
356 $user = $this->getTestSysop()->getUser();
357 $this->assertConditions(
358 [ # expected
359 'rc_patrolled' => [ 1, 2 ],
360 ],
361 [
362 'hideunpatrolled' => 1,
363 ],
364 "rc conditions: hideunpatrolled=1",
365 $user
366 );
367 }
368
369 public function testRcReviewStatusFilter() {
370 $user = $this->getTestSysop()->getUser();
371 $this->assertConditions(
372 [ #expected
373 'rc_patrolled' => 1,
374 ],
375 [
376 'reviewStatus' => 'manual'
377 ],
378 "rc conditions: reviewStatus=manual",
379 $user
380 );
381 $this->assertConditions(
382 [ #expected
383 'rc_patrolled' => [ 0, 2 ],
384 ],
385 [
386 'reviewStatus' => 'unpatrolled;auto'
387 ],
388 "rc conditions: reviewStatus=unpatrolled;auto",
389 $user
390 );
391 }
392
393 public function testRcHideminorFilter() {
394 $this->assertConditions(
395 [ # expected
396 "rc_minor = 0",
397 ],
398 [
399 'hideminor' => 1,
400 ],
401 "rc conditions: hideminor=1"
402 );
403 }
404
405 public function testRcHidemajorFilter() {
406 $this->assertConditions(
407 [ # expected
408 "rc_minor = 1",
409 ],
410 [
411 'hidemajor' => 1,
412 ],
413 "rc conditions: hidemajor=1"
414 );
415 }
416
417 public function testHideCategorization() {
418 $this->assertConditions(
419 [
420 # expected
421 "rc_type != '6'"
422 ],
423 [
424 'hidecategorization' => 1
425 ],
426 "rc conditions: hidecategorization=1"
427 );
428 }
429
430 public function testFilterUserExpLevelAll() {
431 $this->assertConditions(
432 [
433 # expected
434 ],
435 [
436 'userExpLevel' => 'registered;unregistered;newcomer;learner;experienced',
437 ],
438 "rc conditions: userExpLevel=registered;unregistered;newcomer;learner;experienced"
439 );
440 }
441
442 public function testFilterUserExpLevelRegisteredUnregistered() {
443 $this->assertConditions(
444 [
445 # expected
446 ],
447 [
448 'userExpLevel' => 'registered;unregistered',
449 ],
450 "rc conditions: userExpLevel=registered;unregistered"
451 );
452 }
453
454 public function testFilterUserExpLevelRegisteredUnregisteredLearner() {
455 $this->assertConditions(
456 [
457 # expected
458 ],
459 [
460 'userExpLevel' => 'registered;unregistered;learner',
461 ],
462 "rc conditions: userExpLevel=registered;unregistered;learner"
463 );
464 }
465
466 public function testFilterUserExpLevelAllExperienceLevels() {
467 $this->setMwGlobals(
468 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
469 );
470 $this->overrideMwServices();
471
472 $this->assertConditions(
473 [
474 # expected
475 'rc_user != 0',
476 ],
477 [
478 'userExpLevel' => 'newcomer;learner;experienced',
479 ],
480 "rc conditions: userExpLevel=newcomer;learner;experienced"
481 );
482 }
483
484 public function testFilterUserExpLevelRegistrered() {
485 $this->setMwGlobals(
486 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
487 );
488 $this->overrideMwServices();
489
490 $this->assertConditions(
491 [
492 # expected
493 'rc_user != 0',
494 ],
495 [
496 'userExpLevel' => 'registered',
497 ],
498 "rc conditions: userExpLevel=registered"
499 );
500 }
501
502 public function testFilterUserExpLevelUnregistrered() {
503 $this->setMwGlobals(
504 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
505 );
506 $this->overrideMwServices();
507
508 $this->assertConditions(
509 [
510 # expected
511 'rc_user = 0',
512 ],
513 [
514 'userExpLevel' => 'unregistered',
515 ],
516 "rc conditions: userExpLevel=unregistered"
517 );
518 }
519
520 public function testFilterUserExpLevelRegistreredOrLearner() {
521 $this->setMwGlobals(
522 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
523 );
524 $this->overrideMwServices();
525
526 $this->assertConditions(
527 [
528 # expected
529 'rc_user != 0',
530 ],
531 [
532 'userExpLevel' => 'registered;learner',
533 ],
534 "rc conditions: userExpLevel=registered;learner"
535 );
536 }
537
538 public function testFilterUserExpLevelUnregistreredOrExperienced() {
539 $this->setMwGlobals(
540 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
541 );
542 $this->overrideMwServices();
543
544 $conds = $this->buildQuery( [ 'userExpLevel' => 'unregistered;experienced' ] );
545
546 $this->assertRegExp(
547 '/\(rc_user = 0\) OR '
548 . '\(\(user_editcount >= 500\) AND \(user_registration <= \'[^\']+\'\)\)/',
549 reset( $conds ),
550 "rc conditions: userExpLevel=unregistered;experienced"
551 );
552 }
553
554 public function testFilterUserExpLevel() {
555 $now = time();
556 $this->setMwGlobals( [
557 'wgLearnerEdits' => 10,
558 'wgLearnerMemberSince' => 4,
559 'wgExperiencedUserEdits' => 500,
560 'wgExperiencedUserMemberSince' => 30,
561 ] );
562
563 $this->createUsers( [
564 'Newcomer1' => [ 'edits' => 2, 'days' => 2 ],
565 'Newcomer2' => [ 'edits' => 12, 'days' => 3 ],
566 'Newcomer3' => [ 'edits' => 8, 'days' => 5 ],
567 'Learner1' => [ 'edits' => 15, 'days' => 10 ],
568 'Learner2' => [ 'edits' => 450, 'days' => 20 ],
569 'Learner3' => [ 'edits' => 460, 'days' => 33 ],
570 'Learner4' => [ 'edits' => 525, 'days' => 28 ],
571 'Experienced1' => [ 'edits' => 538, 'days' => 33 ],
572 ], $now );
573
574 // newcomers only
575 $this->assertArrayEquals(
576 [ 'Newcomer1', 'Newcomer2', 'Newcomer3' ],
577 $this->fetchUsers( [ 'newcomer' ], $now )
578 );
579
580 // newcomers and learner
581 $this->assertArrayEquals(
582 [
583 'Newcomer1', 'Newcomer2', 'Newcomer3',
584 'Learner1', 'Learner2', 'Learner3', 'Learner4',
585 ],
586 $this->fetchUsers( [ 'newcomer', 'learner' ], $now )
587 );
588
589 // newcomers and more learner
590 $this->assertArrayEquals(
591 [
592 'Newcomer1', 'Newcomer2', 'Newcomer3',
593 'Experienced1',
594 ],
595 $this->fetchUsers( [ 'newcomer', 'experienced' ], $now )
596 );
597
598 // learner only
599 $this->assertArrayEquals(
600 [ 'Learner1', 'Learner2', 'Learner3', 'Learner4' ],
601 $this->fetchUsers( [ 'learner' ], $now )
602 );
603
604 // more experienced only
605 $this->assertArrayEquals(
606 [ 'Experienced1' ],
607 $this->fetchUsers( [ 'experienced' ], $now )
608 );
609
610 // learner and more experienced
611 $this->assertArrayEquals(
612 [
613 'Learner1', 'Learner2', 'Learner3', 'Learner4',
614 'Experienced1',
615 ],
616 $this->fetchUsers( [ 'learner', 'experienced' ], $now )
617 );
618 }
619
620 private function createUsers( $specs, $now ) {
621 $dbw = wfGetDB( DB_MASTER );
622 foreach ( $specs as $name => $spec ) {
623 User::createNew(
624 $name,
625 [
626 'editcount' => $spec['edits'],
627 'registration' => $dbw->timestamp( $this->daysAgo( $spec['days'], $now ) ),
628 'email' => 'ut',
629 ]
630 );
631 }
632 }
633
634 private function fetchUsers( $filters, $now ) {
635 $tables = [];
636 $conds = [];
637 $fields = [];
638 $query_options = [];
639 $join_conds = [];
640
641 sort( $filters );
642
643 call_user_func_array(
644 [ $this->changesListSpecialPage, 'filterOnUserExperienceLevel' ],
645 [
646 get_class( $this->changesListSpecialPage ),
647 $this->changesListSpecialPage->getContext(),
648 $this->changesListSpecialPage->getDB(),
649 &$tables,
650 &$fields,
651 &$conds,
652 &$query_options,
653 &$join_conds,
654 $filters,
655 $now
656 ]
657 );
658
659 // @todo: This is not at all safe or sane. It just blindly assumes
660 // nothing in $conds depends on any other tables.
661 $result = wfGetDB( DB_MASTER )->select(
662 'user',
663 'user_name',
664 array_filter( $conds ) + [ 'user_email' => 'ut' ]
665 );
666
667 $usernames = [];
668 foreach ( $result as $row ) {
669 $usernames[] = $row->user_name;
670 }
671
672 return $usernames;
673 }
674
675 private function daysAgo( $days, $now ) {
676 $secondsPerDay = 86400;
677 return $now - $days * $secondsPerDay;
678 }
679
680 public function testGetStructuredFilterJsData() {
681 $this->changesListSpecialPage->filterGroups = [];
682
683 $definition = [
684 [
685 'name' => 'gub-group',
686 'title' => 'gub-group-title',
687 'class' => ChangesListBooleanFilterGroup::class,
688 'filters' => [
689 [
690 'name' => 'hidefoo',
691 'label' => 'foo-label',
692 'description' => 'foo-description',
693 'default' => true,
694 'showHide' => 'showhidefoo',
695 'priority' => 2,
696 ],
697 [
698 'name' => 'hidebar',
699 'label' => 'bar-label',
700 'description' => 'bar-description',
701 'default' => false,
702 'priority' => 4,
703 ]
704 ],
705 ],
706
707 [
708 'name' => 'des-group',
709 'title' => 'des-group-title',
710 'class' => ChangesListStringOptionsFilterGroup::class,
711 'isFullCoverage' => true,
712 'filters' => [
713 [
714 'name' => 'grault',
715 'label' => 'grault-label',
716 'description' => 'grault-description',
717 ],
718 [
719 'name' => 'garply',
720 'label' => 'garply-label',
721 'description' => 'garply-description',
722 ],
723 ],
724 'queryCallable' => function () {
725 },
726 'default' => ChangesListStringOptionsFilterGroup::NONE,
727 ],
728
729 [
730 'name' => 'unstructured',
731 'class' => ChangesListBooleanFilterGroup::class,
732 'filters' => [
733 [
734 'name' => 'hidethud',
735 'showHide' => 'showhidethud',
736 'default' => true,
737 ],
738
739 [
740 'name' => 'hidemos',
741 'showHide' => 'showhidemos',
742 'default' => false,
743 ],
744 ],
745 ],
746
747 ];
748
749 $this->changesListSpecialPage->registerFiltersFromDefinitions( $definition );
750
751 $this->assertArrayEquals(
752 [
753 // Filters that only display in the unstructured UI are
754 // are not included, and neither are groups that would
755 // be empty due to the above.
756 'groups' => [
757 [
758 'name' => 'gub-group',
759 'title' => 'gub-group-title',
760 'type' => ChangesListBooleanFilterGroup::TYPE,
761 'priority' => -1,
762 'filters' => [
763 [
764 'name' => 'hidebar',
765 'label' => 'bar-label',
766 'description' => 'bar-description',
767 'default' => false,
768 'priority' => 4,
769 'cssClass' => null,
770 'conflicts' => [],
771 'subset' => [],
772 'defaultHighlightColor' => null
773 ],
774 [
775 'name' => 'hidefoo',
776 'label' => 'foo-label',
777 'description' => 'foo-description',
778 'default' => true,
779 'priority' => 2,
780 'cssClass' => null,
781 'conflicts' => [],
782 'subset' => [],
783 'defaultHighlightColor' => null
784 ],
785 ],
786 'fullCoverage' => true,
787 'conflicts' => [],
788 ],
789
790 [
791 'name' => 'des-group',
792 'title' => 'des-group-title',
793 'type' => ChangesListStringOptionsFilterGroup::TYPE,
794 'priority' => -2,
795 'fullCoverage' => true,
796 'filters' => [
797 [
798 'name' => 'grault',
799 'label' => 'grault-label',
800 'description' => 'grault-description',
801 'cssClass' => null,
802 'priority' => -2,
803 'conflicts' => [],
804 'subset' => [],
805 'defaultHighlightColor' => null
806 ],
807 [
808 'name' => 'garply',
809 'label' => 'garply-label',
810 'description' => 'garply-description',
811 'cssClass' => null,
812 'priority' => -3,
813 'conflicts' => [],
814 'subset' => [],
815 'defaultHighlightColor' => null
816 ],
817 ],
818 'conflicts' => [],
819 'separator' => ';',
820 'default' => ChangesListStringOptionsFilterGroup::NONE,
821 ],
822 ],
823 'messageKeys' => [
824 'gub-group-title',
825 'bar-label',
826 'bar-description',
827 'foo-label',
828 'foo-description',
829 'des-group-title',
830 'grault-label',
831 'grault-description',
832 'garply-label',
833 'garply-description',
834 ],
835 ],
836 $this->changesListSpecialPage->getStructuredFilterJsData(),
837 /** ordered= */ false,
838 /** named= */ true
839 );
840 }
841
842 public function provideParseParameters() {
843 return [
844 [ 'hidebots', [ 'hidebots' => true ] ],
845
846 [ 'bots', [ 'hidebots' => false ] ],
847
848 [ 'hideminor', [ 'hideminor' => true ] ],
849
850 [ 'minor', [ 'hideminor' => false ] ],
851
852 [ 'hidemajor', [ 'hidemajor' => true ] ],
853
854 [ 'hideliu', [ 'hideliu' => true ] ],
855
856 [ 'hidepatrolled', [ 'hidepatrolled' => true ] ],
857
858 [ 'hideunpatrolled', [ 'hideunpatrolled' => true ] ],
859
860 [ 'hideanons', [ 'hideanons' => true ] ],
861
862 [ 'hidemyself', [ 'hidemyself' => true ] ],
863
864 [ 'hidebyothers', [ 'hidebyothers' => true ] ],
865
866 [ 'hidehumans', [ 'hidehumans' => true ] ],
867
868 [ 'hidepageedits', [ 'hidepageedits' => true ] ],
869
870 [ 'pagedits', [ 'hidepageedits' => false ] ],
871
872 [ 'hidenewpages', [ 'hidenewpages' => true ] ],
873
874 [ 'hidecategorization', [ 'hidecategorization' => true ] ],
875
876 [ 'hidelog', [ 'hidelog' => true ] ],
877
878 [
879 'userExpLevel=learner;experienced',
880 [
881 'userExpLevel' => 'learner;experienced'
882 ],
883 ],
884
885 // A few random combos
886 [
887 'bots,hideliu,hidemyself',
888 [
889 'hidebots' => false,
890 'hideliu' => true,
891 'hidemyself' => true,
892 ],
893 ],
894
895 [
896 'minor,hideanons,categorization',
897 [
898 'hideminor' => false,
899 'hideanons' => true,
900 'hidecategorization' => false,
901 ]
902 ],
903
904 [
905 'hidehumans,bots,hidecategorization',
906 [
907 'hidehumans' => true,
908 'hidebots' => false,
909 'hidecategorization' => true,
910 ],
911 ],
912
913 [
914 'hidemyself,userExpLevel=newcomer;learner,hideminor',
915 [
916 'hidemyself' => true,
917 'hideminor' => true,
918 'userExpLevel' => 'newcomer;learner',
919 ],
920 ],
921 ];
922 }
923
924 public function provideGetFilterConflicts() {
925 return [
926 [
927 "parameters" => [],
928 "expectedConflicts" => false,
929 ],
930 [
931 "parameters" => [
932 "hideliu" => true,
933 "userExpLevel" => "newcomer",
934 ],
935 "expectedConflicts" => false,
936 ],
937 [
938 "parameters" => [
939 "hideanons" => true,
940 "userExpLevel" => "learner",
941 ],
942 "expectedConflicts" => false,
943 ],
944 [
945 "parameters" => [
946 "hidemajor" => true,
947 "hidenewpages" => true,
948 "hidepageedits" => true,
949 "hidecategorization" => false,
950 "hidelog" => true,
951 "hideWikidata" => true,
952 ],
953 "expectedConflicts" => true,
954 ],
955 [
956 "parameters" => [
957 "hidemajor" => true,
958 "hidenewpages" => false,
959 "hidepageedits" => true,
960 "hidecategorization" => false,
961 "hidelog" => false,
962 "hideWikidata" => true,
963 ],
964 "expectedConflicts" => true,
965 ],
966 [
967 "parameters" => [
968 "hidemajor" => true,
969 "hidenewpages" => false,
970 "hidepageedits" => false,
971 "hidecategorization" => true,
972 "hidelog" => true,
973 "hideWikidata" => true,
974 ],
975 "expectedConflicts" => false,
976 ],
977 [
978 "parameters" => [
979 "hideminor" => true,
980 "hidenewpages" => true,
981 "hidepageedits" => true,
982 "hidecategorization" => false,
983 "hidelog" => true,
984 "hideWikidata" => true,
985 ],
986 "expectedConflicts" => false,
987 ],
988 ];
989 }
990
991 /**
992 * @dataProvider provideGetFilterConflicts
993 */
994 public function testGetFilterConflicts( $parameters, $expectedConflicts ) {
995 $context = new RequestContext;
996 $context->setRequest( new FauxRequest( $parameters ) );
997 $this->changesListSpecialPage->setContext( $context );
998
999 $this->assertEquals(
1000 $expectedConflicts,
1001 $this->changesListSpecialPage->areFiltersInConflict()
1002 );
1003 }
1004
1005 public function validateOptionsProvider() {
1006 return [
1007 [
1008 [ 'hideanons' => 1, 'hideliu' => 1, 'hidebots' => 1 ],
1009 true,
1010 [ 'userExpLevel' => 'unregistered', 'hidebots' => 1, ],
1011 true,
1012 ],
1013 [
1014 [ 'hideanons' => 1, 'hideliu' => 1, 'hidebots' => 0 ],
1015 true,
1016 [ 'hidebots' => 0, 'hidehumans' => 1 ],
1017 true,
1018 ],
1019 [
1020 [ 'hideanons' => 1 ],
1021 true,
1022 [ 'userExpLevel' => 'registered' ],
1023 true,
1024 ],
1025 [
1026 [ 'hideliu' => 1 ],
1027 true,
1028 [ 'userExpLevel' => 'unregistered' ],
1029 true,
1030 ],
1031 [
1032 [ 'hideanons' => 1, 'hidebots' => 1 ],
1033 true,
1034 [ 'userExpLevel' => 'registered', 'hidebots' => 1 ],
1035 true,
1036 ],
1037 [
1038 [ 'hideliu' => 1, 'hidebots' => 0 ],
1039 true,
1040 [ 'userExpLevel' => 'unregistered', 'hidebots' => 0 ],
1041 true,
1042 ],
1043 [
1044 [ 'hidemyself' => 1, 'hidebyothers' => 1 ],
1045 true,
1046 [],
1047 true,
1048 ],
1049 [
1050 [ 'hidebots' => 1, 'hidehumans' => 1 ],
1051 true,
1052 [],
1053 true,
1054 ],
1055 [
1056 [ 'hidepatrolled' => 1, 'hideunpatrolled' => 1 ],
1057 true,
1058 [],
1059 true,
1060 ],
1061 [
1062 [ 'hideminor' => 1, 'hidemajor' => 1 ],
1063 true,
1064 [],
1065 true,
1066 ],
1067 [
1068 // changeType
1069 [ 'hidepageedits' => 1, 'hidenewpages' => 1, 'hidecategorization' => 1, 'hidelog' => 1, ],
1070 true,
1071 [],
1072 true,
1073 ],
1074 ];
1075 }
1076 }