a0b6e0d4b5cb026fa31edcbbb9eed77dae79a994
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 = '' ) {
21 $context = new RequestContext
;
22 $context->setRequest( new FauxRequest( $requestOptions ) );
25 $this->rc
= new SpecialRecentChanges();
26 $this->rc
->setContext( $context );
27 $formOptions = $this->rc
->setup( null );
29 # Filter out rc_timestamp conditions which depends on the test runtime
30 # This condition is not needed as of march 2, 2011 -- hashar
31 # @todo FIXME: Find a way to generate the correct rc_timestamp
32 $queryConditions = array_filter(
33 $this->rc
->buildMainQueryConds( $formOptions ),
34 'SpecialRecentchangesTest::filterOutRcTimestampCondition'
44 /** return false if condition begin with 'rc_timestamp ' */
45 private static function filterOutRcTimestampCondition( $var ) {
46 return (false === strpos( $var, 'rc_timestamp ' ));
50 public function testRcNsFilter() {
51 $this->assertConditions(
54 #0 => "rc_timestamp >= '20110223000000'",
55 1 => "rc_namespace = '0'",
58 'namespace' => NS_MAIN
,
60 "rc conditions with no options (aka default setting)"
64 public function testRcNsFilterInversion() {
65 $this->assertConditions(
67 #0 => "rc_timestamp >= '20110223000000'",
69 1 => sprintf( "rc_namespace != '%s'", NS_MAIN
),
72 'namespace' => NS_MAIN
,
75 "rc conditions with namespace inverted"
81 * @dataProvider provideNamespacesAssociations
83 public function testRcNsFilterAssociation( $ns1, $ns2 ) {
84 $this->assertConditions(
86 #0 => "rc_timestamp >= '20110223000000'",
88 1 => sprintf( "rc_namespace IN ('%s','%s')", $ns1, $ns2 ),
94 "rc conditions with namespace inverted"
100 * @dataProvider provideNamespacesAssociations
102 public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
103 $this->assertConditions(
105 #0 => "rc_timestamp >= '20110223000000'",
107 1 => sprintf( "rc_namespace NOT IN ('%s','%s')", $ns1, $ns2 ),
114 "rc conditions with namespace inverted"
119 * Provides associated namespaces to test recent changes
120 * namespaces association filtering.
122 public function provideNamespacesAssociations() {
123 return array( # (NS => Associated_NS)
124 array( NS_MAIN
, NS_TALK
),
125 array( NS_TALK
, NS_MAIN
),