3 * Test class for SpecialRecentchanges class
5 * Copyright © 2011, Antoine Musso
7 * @author Antoine Musso
10 class SpecialRecentchangesTest
extends MediaWikiTestCase
{
13 * @var SpecialRecentChanges
17 /** helper to test SpecialRecentchanges::buildMainQueryConds() */
18 private function assertConditions( $expected, $requestOptions = null, $message = '' ) {
19 $context = new RequestContext
;
20 $context->setRequest( new FauxRequest( $requestOptions ) );
23 $this->rc
= new SpecialRecentChanges();
24 $this->rc
->setContext( $context );
25 $formOptions = $this->rc
->setup( null );
27 # Filter out rc_timestamp conditions which depends on the test runtime
28 # This condition is not needed as of march 2, 2011 -- hashar
29 # @todo FIXME: Find a way to generate the correct rc_timestamp
30 $queryConditions = array_filter(
31 $this->rc
->buildMainQueryConds( $formOptions ),
32 'SpecialRecentchangesTest::filterOutRcTimestampCondition'
42 /** return false if condition begin with 'rc_timestamp ' */
43 private static function filterOutRcTimestampCondition( $var ) {
44 return ( false === strpos( $var, 'rc_timestamp ' ) );
47 public function testRcNsFilter() {
48 $this->assertConditions(
51 #0 => "rc_timestamp >= '20110223000000'",
52 1 => "rc_namespace = '0'",
55 'namespace' => NS_MAIN
,
57 "rc conditions with no options (aka default setting)"
61 public function testRcNsFilterInversion() {
62 $this->assertConditions(
64 #0 => "rc_timestamp >= '20110223000000'",
66 1 => 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(
83 #0 => "rc_timestamp >= '20110223000000'",
85 1 => sprintf( "(rc_namespace = '%s' OR rc_namespace = '%s')", $ns1, $ns2 ),
91 "rc conditions with namespace inverted"
97 * @dataProvider provideNamespacesAssociations
99 public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
100 $this->assertConditions(
102 #0 => "rc_timestamp >= '20110223000000'",
104 1 => sprintf( "(rc_namespace != '%s' AND rc_namespace != '%s')", $ns1, $ns2 ),
111 "rc conditions with namespace inverted"
116 * Provides associated namespaces to test recent changes
117 * namespaces association filtering.
119 public static function provideNamespacesAssociations() {
120 return array( # (NS => Associated_NS)
121 array( NS_MAIN
, NS_TALK
),
122 array( NS_TALK
, NS_MAIN
),