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_timestamp >= '20110223000000'",
54 1 => "rc_namespace = '0'",
57 'namespace' => NS_MAIN
,
59 "rc conditions with no options (aka default setting)"
63 public function testRcNsFilterInversion() {
64 $this->assertConditions(
66 #0 => "rc_timestamp >= '20110223000000'",
68 1 => sprintf( "rc_namespace != '%s'", NS_MAIN
),
71 'namespace' => NS_MAIN
,
74 "rc conditions with namespace inverted"
80 * @dataProvider provideNamespacesAssociations
82 public function testRcNsFilterAssociation( $ns1, $ns2 ) {
83 $this->assertConditions(
85 #0 => "rc_timestamp >= '20110223000000'",
87 1 => sprintf( "(rc_namespace = '%s' OR rc_namespace = '%s')", $ns1, $ns2 ),
93 "rc conditions with namespace inverted"
99 * @dataProvider provideNamespacesAssociations
101 public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
102 $this->assertConditions(
104 #0 => "rc_timestamp >= '20110223000000'",
106 1 => sprintf( "(rc_namespace != '%s' AND rc_namespace != '%s')", $ns1, $ns2 ),
113 "rc conditions with namespace inverted"
118 * Provides associated namespaces to test recent changes
119 * namespaces association filtering.
121 public static function provideNamespacesAssociations() {
122 return array( # (NS => Associated_NS)
123 array( NS_MAIN
, NS_TALK
),
124 array( NS_TALK
, NS_MAIN
),