3 * Test class for SpecialRecentchanges class
5 * Copyright © 2011, Antoine Musso
7 * @author Antoine Musso
10 * @covers SpecialRecentChanges
12 class SpecialRecentchangesTest
extends MediaWikiTestCase
{
15 * @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 ' ) );
49 public function testRcNsFilter() {
50 $this->assertConditions(
53 0 => "rc_namespace = '0'",
56 'namespace' => NS_MAIN
,
58 "rc conditions with no options (aka default setting)"
62 public function testRcNsFilterInversion() {
63 $this->assertConditions(
66 0 => sprintf( "rc_namespace != '%s'", NS_MAIN
),
69 'namespace' => NS_MAIN
,
72 "rc conditions with namespace inverted"
78 * @dataProvider provideNamespacesAssociations
80 public function testRcNsFilterAssociation( $ns1, $ns2 ) {
81 $this->assertConditions(
84 0 => sprintf( "(rc_namespace = '%s' OR rc_namespace = '%s')", $ns1, $ns2 ),
90 "rc conditions with namespace inverted"
96 * @dataProvider provideNamespacesAssociations
98 public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
99 $this->assertConditions(
102 0 => sprintf( "(rc_namespace != '%s' AND rc_namespace != '%s')", $ns1, $ns2 ),
109 "rc conditions with namespace inverted"
114 * Provides associated namespaces to test recent changes
115 * namespaces association filtering.
117 public static function provideNamespacesAssociations() {
118 return array( # (NS => Associated_NS)
119 array( NS_MAIN
, NS_TALK
),
120 array( NS_TALK
, NS_MAIN
),