Remove unused messages
[lhc/web/wiklou.git] / tests / phpunit / includes / specials / SpecialRecentchangesTest.php
1 <?php
2 /**
3 * Test class for SpecialRecentchanges class
4 *
5 * Copyright © 2011, Antoine Musso
6 *
7 * @author Antoine Musso
8 * @group Database
9 *
10 * @covers SpecialRecentChanges
11 */
12 class SpecialRecentchangesTest extends MediaWikiTestCase {
13
14 protected function setUp() {
15 parent::setUp();
16 $this->setMwGlobals( 'wgRCWatchCategoryMembership', true );
17 }
18
19 /**
20 * @var SpecialRecentChanges
21 */
22 protected $rc;
23
24 /** helper to test SpecialRecentchanges::buildMainQueryConds() */
25 private function assertConditions( $expected, $requestOptions = null, $message = '' ) {
26 $context = new RequestContext;
27 $context->setRequest( new FauxRequest( $requestOptions ) );
28
29 # setup the rc object
30 $this->rc = new SpecialRecentChanges();
31 $this->rc->setContext( $context );
32 $formOptions = $this->rc->setup( null );
33
34 #  Filter out rc_timestamp conditions which depends on the test runtime
35 # This condition is not needed as of march 2, 2011 -- hashar
36 # @todo FIXME: Find a way to generate the correct rc_timestamp
37 $queryConditions = array_filter(
38 $this->rc->buildMainQueryConds( $formOptions ),
39 'SpecialRecentchangesTest::filterOutRcTimestampCondition'
40 );
41
42 $this->assertEquals(
43 $expected,
44 $queryConditions,
45 $message
46 );
47 }
48
49 /** return false if condition begin with 'rc_timestamp ' */
50 private static function filterOutRcTimestampCondition( $var ) {
51 return ( false === strpos( $var, 'rc_timestamp ' ) );
52 }
53
54 public function testRcNsFilter() {
55 $this->assertConditions(
56 [ # expected
57 'rc_bot' => 0,
58 0 => "rc_type != '6'",
59 1 => "rc_namespace = '0'",
60 ],
61 [
62 'namespace' => NS_MAIN,
63 ],
64 "rc conditions with no options (aka default setting)"
65 );
66 }
67
68 public function testRcNsFilterInversion() {
69 $this->assertConditions(
70 [ # expected
71 'rc_bot' => 0,
72 0 => "rc_type != '6'",
73 1 => sprintf( "rc_namespace != '%s'", NS_MAIN ),
74 ],
75 [
76 'namespace' => NS_MAIN,
77 'invert' => 1,
78 ],
79 "rc conditions with namespace inverted"
80 );
81 }
82
83 /**
84 * @bug 2429
85 * @dataProvider provideNamespacesAssociations
86 */
87 public function testRcNsFilterAssociation( $ns1, $ns2 ) {
88 $this->assertConditions(
89 [ # expected
90 'rc_bot' => 0,
91 0 => "rc_type != '6'",
92 1 => sprintf( "(rc_namespace = '%s' OR rc_namespace = '%s')", $ns1, $ns2 ),
93 ],
94 [
95 'namespace' => $ns1,
96 'associated' => 1,
97 ],
98 "rc conditions with namespace inverted"
99 );
100 }
101
102 /**
103 * @bug 2429
104 * @dataProvider provideNamespacesAssociations
105 */
106 public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
107 $this->assertConditions(
108 [ # expected
109 'rc_bot' => 0,
110 0 => "rc_type != '6'",
111 1 => sprintf( "(rc_namespace != '%s' AND rc_namespace != '%s')", $ns1, $ns2 ),
112 ],
113 [
114 'namespace' => $ns1,
115 'associated' => 1,
116 'invert' => 1,
117 ],
118 "rc conditions with namespace inverted"
119 );
120 }
121
122 /**
123 * Provides associated namespaces to test recent changes
124 * namespaces association filtering.
125 */
126 public static function provideNamespacesAssociations() {
127 return [ # (NS => Associated_NS)
128 [ NS_MAIN, NS_TALK ],
129 [ NS_TALK, NS_MAIN ],
130 ];
131 }
132 }