48e31f3abc1e5434dd4609314164ab6df35ba2be
3 * Test class for SpecialRecentchanges class
5 * Copyright © 2011, Ashar Voultoiz
7 * @author Ashar Voultoiz
9 class SpecialRecentchangesTest
extends MediaWikiTestCase
{
12 * @var SpecialRecentChanges
19 /** helper to test SpecialRecentchanges::buildMainQueryConds() */
20 private function assertConditions( $expected, $requestOptions = null, $message = '' ) {
22 $savedGlobal = $wgRequest;
24 # Initialize a WebRequest object ...
25 $wgRequest = new FauxRequest( $requestOptions );
26 # ... then setup the rc object (which use wgRequest internally)
27 $this->rc
= new SpecialRecentChanges();
28 $formOptions = $this->rc
->setup( null );
30 # Filter out rc_timestamp conditions which depends on the test runtime
31 # This condition is not needed as of march 2, 2011 -- hashar
32 # FIXME: find a way to generate the correct rc_timestamp
33 $queryConditions = array_filter(
34 $this->rc
->buildMainQueryConds( $formOptions ),
35 'SpecialRecentchangesTest::filterOutRcTimestampCondition'
44 $wgRequest = $savedGlobal;
47 /** return false if condition begin with 'rc_timestamp ' */
48 private static function filterOutRcTimestampCondition( $var ) {
49 return (false === strpos( $var, 'rc_timestamp ' ));
53 public function testRcNsFilter() {
54 $this->assertConditions(
57 #0 => "rc_timestamp >= '20110223000000'",
58 1 => "rc_namespace = '0'",
61 'namespace' => NS_MAIN
,
63 "rc conditions with no options (aka default setting)"
67 public function testRcNsFilterInversion() {
68 $this->assertConditions(
70 #0 => "rc_timestamp >= '20110223000000'",
72 1 => sprintf( "rc_namespace != '%s'", NS_MAIN
),
75 'namespace' => NS_MAIN
,
78 "rc conditions with namespace inverted"
84 * @dataProvider provideNamespacesAssociations
86 public function testRcNsFilterAssociation( $ns1, $ns2 ) {
87 $this->assertConditions(
89 #0 => "rc_timestamp >= '20110223000000'",
91 1 => sprintf( "(rc_namespace = '%s' OR rc_namespace = '%s')", $ns1, $ns2 ),
97 "rc conditions with namespace inverted"
103 * @dataProvider provideNamespacesAssociations
105 public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
106 $this->assertConditions(
108 #0 => "rc_timestamp >= '20110223000000'",
110 1 => sprintf( "(rc_namespace != '%s' AND rc_namespace != '%s')", $ns1, $ns2 ),
117 "rc conditions with namespace inverted"
122 * Provides associated namespaces to test recent changes
123 * namespaces association filtering.
125 public function provideNamespacesAssociations() {
126 return array( # (NS => Associated_NS)
127 array( NS_MAIN
, NS_TALK
),
128 array( NS_TALK
, NS_MAIN
),