3 * Test class for SpecialRecentchanges class
5 * Copyright © 2011, Antoine Musso
7 * @author Antoine Musso
10 class SpecialRecentchangesTest
extends MediaWikiTestCase
{
13 * @var SpecialRecentChanges
20 /** helper to test SpecialRecentchanges::buildMainQueryConds() */
21 private function assertConditions( $expected, $requestOptions = null, $message = '' ) {
22 $context = new RequestContext
;
23 $context->setRequest( new FauxRequest( $requestOptions ) );
26 $this->rc
= new SpecialRecentChanges();
27 $this->rc
->setContext( $context );
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 # @todo FIXME: Find a way to generate the correct rc_timestamp
33 $queryConditions = array_filter(
34 $this->rc
->buildMainQueryConds( $formOptions ),
35 'SpecialRecentchangesTest::filterOutRcTimestampCondition'
45 /** return false if condition begin with 'rc_timestamp ' */
46 private static function filterOutRcTimestampCondition( $var ) {
47 return (false === strpos( $var, 'rc_timestamp ' ));
51 public function testRcNsFilter() {
52 $this->assertConditions(
55 #0 => "rc_timestamp >= '20110223000000'",
56 1 => "rc_namespace = '0'",
59 'namespace' => NS_MAIN
,
61 "rc conditions with no options (aka default setting)"
65 public function testRcNsFilterInversion() {
66 $this->assertConditions(
68 #0 => "rc_timestamp >= '20110223000000'",
70 1 => sprintf( "rc_namespace != '%s'", NS_MAIN
),
73 'namespace' => NS_MAIN
,
76 "rc conditions with namespace inverted"
82 * @dataProvider provideNamespacesAssociations
84 public function testRcNsFilterAssociation( $ns1, $ns2 ) {
85 $this->assertConditions(
87 #0 => "rc_timestamp >= '20110223000000'",
89 1 => sprintf( "(rc_namespace = '%s' OR rc_namespace = '%s')", $ns1, $ns2 ),
95 "rc conditions with namespace inverted"
101 * @dataProvider provideNamespacesAssociations
103 public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
104 $this->assertConditions(
106 #0 => "rc_timestamp >= '20110223000000'",
108 1 => sprintf( "(rc_namespace != '%s' AND rc_namespace != '%s')", $ns1, $ns2 ),
115 "rc conditions with namespace inverted"
120 * Provides associated namespaces to test recent changes
121 * namespaces association filtering.
123 public function provideNamespacesAssociations() {
124 return array( # (NS => Associated_NS)
125 array( NS_MAIN
, NS_TALK
),
126 array( NS_TALK
, NS_MAIN
),