03e9c8fee0b3963fce27fa491a71858d4714c88b
3 * Test class for SpecialRecentchanges class
5 * Copyright © 2011, Antoine Musso
7 * @author Antoine Musso
10 * @covers SpecialRecentChanges
12 class SpecialRecentchangesTest
extends MediaWikiTestCase
{
14 protected function setUp() {
16 $this->setMwGlobals( 'wgRCWatchCategoryMembership', true );
20 * @var SpecialRecentChanges
24 /** helper to test SpecialRecentchanges::buildMainQueryConds() */
25 private function assertConditions(
27 $requestOptions = null,
31 $context = new RequestContext
;
32 $context->setRequest( new FauxRequest( $requestOptions ) );
34 $context->setUser( $user );
38 $this->rc
= new SpecialRecentChanges();
39 $this->rc
->setContext( $context );
40 $formOptions = $this->rc
->setup( null );
42 # Filter out rc_timestamp conditions which depends on the test runtime
43 # This condition is not needed as of march 2, 2011 -- hashar
44 # @todo FIXME: Find a way to generate the correct rc_timestamp
45 $queryConditions = array_filter(
46 $this->rc
->buildMainQueryConds( $formOptions ),
47 'SpecialRecentchangesTest::filterOutRcTimestampCondition'
51 self
::normalizeCondition( $expected ),
52 self
::normalizeCondition( $queryConditions ),
57 private static function normalizeCondition( $conds ) {
60 return is_numeric( $k ) ?
$v : "$k = $v";
67 /** return false if condition begin with 'rc_timestamp ' */
68 private static function filterOutRcTimestampCondition( $var ) {
69 return ( false === strpos( $var, 'rc_timestamp ' ) );
72 public function testRcNsFilter() {
73 $this->assertConditions(
80 'namespace' => NS_MAIN
,
82 "rc conditions with no options (aka default setting)"
86 public function testRcNsFilterInversion() {
87 $this->assertConditions(
91 "rc_namespace != '0'",
94 'namespace' => NS_MAIN
,
97 "rc conditions with namespace inverted"
103 * @dataProvider provideNamespacesAssociations
105 public function testRcNsFilterAssociation( $ns1, $ns2 ) {
106 $this->assertConditions(
110 "(rc_namespace = '$ns1' OR rc_namespace = '$ns2')",
116 "rc conditions with namespace inverted"
122 * @dataProvider provideNamespacesAssociations
124 public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
125 $this->assertConditions(
129 "(rc_namespace != '$ns1' AND rc_namespace != '$ns2')",
136 "rc conditions with namespace inverted"
141 * Provides associated namespaces to test recent changes
142 * namespaces association filtering.
144 public static function provideNamespacesAssociations() {
145 return [ # (NS => Associated_NS)
146 [ NS_MAIN
, NS_TALK
],
147 [ NS_TALK
, NS_MAIN
],
151 public function testRcHidemyselfFilter() {
152 $user = $this->getTestUser()->getUser();
153 $this->assertConditions(
156 "rc_user != '{$user->getId()}'",
162 "rc conditions: hidemyself=1 (logged in)",
166 $user = User
::newFromName( '10.11.12.13', false );
167 $this->assertConditions(
170 "rc_user_text != '10.11.12.13'",
176 "rc conditions: hidemyself=1 (anon)",
181 public function testRcHidebyothersFilter() {
182 $user = $this->getTestUser()->getUser();
183 $this->assertConditions(
186 "rc_user = '{$user->getId()}'",
192 "rc conditions: hidebyothers=1 (logged in)",
196 $user = User
::newFromName( '10.11.12.13', false );
197 $this->assertConditions(
200 "rc_user_text = '10.11.12.13'",
206 "rc conditions: hidebyothers=1 (anon)",
211 public function testRcHidemyselfHidebyothersFilter() {
212 $user = $this->getTestUser()->getUser();
213 $this->assertConditions(
216 "rc_user != '{$user->getId()}'",
217 "rc_user = '{$user->getId()}'",
224 "rc conditions: hidemyself=1 hidebyothers=1 (logged in)",
229 public function testRcHidepageedits() {
230 $this->assertConditions(
237 'hidepageedits' => 1,
239 "rc conditions: hidepageedits=1"
243 public function testRcHidenewpages() {
244 $this->assertConditions(
253 "rc conditions: hidenewpages=1"
257 public function testRcHidelog() {
258 $this->assertConditions(
267 "rc conditions: hidelog=1"
271 public function testRcHidehumans() {
272 $this->assertConditions(
281 "rc conditions: hidebots=0 hidehumans=1"
285 public function testRcHidepatrolledDisabledFilter() {
286 $user = $this->getTestUser()->getUser();
287 $this->assertConditions(
293 'hidepatrolled' => 1,
295 "rc conditions: hidepatrolled=1 (user not allowed)",
300 public function testRcHideunpatrolledDisabledFilter() {
301 $user = $this->getTestUser()->getUser();
302 $this->assertConditions(
308 'hideunpatrolled' => 1,
310 "rc conditions: hideunpatrolled=1 (user not allowed)",
314 public function testRcHidepatrolledFilter() {
315 $user = $this->getTestSysop()->getUser();
316 $this->assertConditions(
323 'hidepatrolled' => 1,
325 "rc conditions: hidepatrolled=1",
330 public function testRcHideunpatrolledFilter() {
331 $user = $this->getTestSysop()->getUser();
332 $this->assertConditions(
339 'hideunpatrolled' => 1,
341 "rc conditions: hideunpatrolled=1",
346 // This is probably going to change when we do auto-fix of
347 // filters combinations that don't make sense but for now
348 // it's the behavior therefore it's the test.
349 public function testRcHidepatrolledHideunpatrolledFilter() {
350 $user = $this->getTestSysop()->getUser();
351 $this->assertConditions(
359 'hidepatrolled' => 1,
360 'hideunpatrolled' => 1,
362 "rc conditions: hidepatrolled=1 hideunpatrolled=1",