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 0 => "rc_user != '{$user->getId()}'",
157 1 => "rc_type != '6'",
162 "rc conditions: hidemyself=1 (logged in)",
166 $user = User
::newFromName( '10.11.12.13', false );
167 $this->assertConditions(
170 0 => "rc_user_text != '10.11.12.13'",
171 1 => "rc_type != '6'",
176 "rc conditions: hidemyself=1 (anon)",
181 public function testRcHidebyothersFilter() {
182 $user = $this->getTestUser()->getUser();
183 $this->assertConditions(
186 0 => "rc_user = '{$user->getId()}'",
187 1 => "rc_type != '6'",
192 "rc conditions: hidebyothers=1 (logged in)",
196 $user = User
::newFromName( '10.11.12.13', false );
197 $this->assertConditions(
200 0 => "rc_user_text = '10.11.12.13'",
201 1 => "rc_type != '6'",
206 "rc conditions: hidebyothers=1 (anon)",
211 public function testRcHidemyselfHidebyothersFilter() {
212 $user = $this->getTestUser()->getUser();
213 $this->assertConditions(
216 0 => "rc_user != '{$user->getId()}'",
217 1 => "rc_user = '{$user->getId()}'",
218 2 => "rc_type != '6'",
224 "rc conditions: hidemyself=1 hidebyothers=1 (logged in)",