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'
57 /** return false if condition begin with 'rc_timestamp ' */
58 private static function filterOutRcTimestampCondition( $var ) {
59 return ( false === strpos( $var, 'rc_timestamp ' ) );
62 public function testRcNsFilter() {
63 $this->assertConditions(
66 0 => "rc_type != '6'",
67 1 => "rc_namespace = '0'",
70 'namespace' => NS_MAIN
,
72 "rc conditions with no options (aka default setting)"
76 public function testRcNsFilterInversion() {
77 $this->assertConditions(
80 0 => "rc_type != '6'",
81 1 => sprintf( "rc_namespace != '%s'", NS_MAIN
),
84 'namespace' => NS_MAIN
,
87 "rc conditions with namespace inverted"
93 * @dataProvider provideNamespacesAssociations
95 public function testRcNsFilterAssociation( $ns1, $ns2 ) {
96 $this->assertConditions(
99 0 => "rc_type != '6'",
100 1 => sprintf( "(rc_namespace = '%s' OR rc_namespace = '%s')", $ns1, $ns2 ),
106 "rc conditions with namespace inverted"
112 * @dataProvider provideNamespacesAssociations
114 public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
115 $this->assertConditions(
118 0 => "rc_type != '6'",
119 1 => sprintf( "(rc_namespace != '%s' AND rc_namespace != '%s')", $ns1, $ns2 ),
126 "rc conditions with namespace inverted"
131 * Provides associated namespaces to test recent changes
132 * namespaces association filtering.
134 public static function provideNamespacesAssociations() {
135 return [ # (NS => Associated_NS)
136 [ NS_MAIN
, NS_TALK
],
137 [ NS_TALK
, NS_MAIN
],
141 public function testRcHidemyselfFilter() {
142 $user = $this->getTestUser()->getUser();
143 $this->assertConditions(
146 0 => "rc_user != '{$user->getId()}'",
147 1 => "rc_type != '6'",
152 "rc conditions: hidemyself=1 (logged in)",
156 $user = User
::newFromName( '10.11.12.13', false );
157 $this->assertConditions(
160 0 => "rc_user_text != '10.11.12.13'",
161 1 => "rc_type != '6'",
166 "rc conditions: hidemyself=1 (anon)",
171 public function testRcHidebyothersFilter() {
172 $user = $this->getTestUser()->getUser();
173 $this->assertConditions(
176 0 => "rc_user = '{$user->getId()}'",
177 1 => "rc_type != '6'",
182 "rc conditions: hidebyothers=1 (logged in)",
186 $user = User
::newFromName( '10.11.12.13', false );
187 $this->assertConditions(
190 0 => "rc_user_text = '10.11.12.13'",
191 1 => "rc_type != '6'",
196 "rc conditions: hidebyothers=1 (anon)",
201 public function testRcHidemyselfHidebyothersFilter() {
202 $user = $this->getTestUser()->getUser();
203 $this->assertConditions(
206 0 => "rc_user != '{$user->getId()}'",
207 1 => "rc_user = '{$user->getId()}'",
208 2 => "rc_type != '6'",
214 "rc conditions: hidemyself=1 hidebyothers=1 (logged in)",