MediaWiki  REL1_22
SpecialRecentchangesTest.php
Go to the documentation of this file.
00001 <?php
00010 class SpecialRecentchangesTest extends MediaWikiTestCase {
00011 
00015     protected $rc;
00016 
00018     private function assertConditions( $expected, $requestOptions = null, $message = '' ) {
00019         $context = new RequestContext;
00020         $context->setRequest( new FauxRequest( $requestOptions ) );
00021 
00022         # setup the rc object
00023         $this->rc = new SpecialRecentChanges();
00024         $this->rc->setContext( $context );
00025         $formOptions = $this->rc->setup( null );
00026 
00027         # Filter out rc_timestamp conditions which depends on the test runtime
00028         # This condition is not needed as of march 2, 2011 -- hashar
00029         # @todo FIXME: Find a way to generate the correct rc_timestamp
00030         $queryConditions = array_filter(
00031             $this->rc->buildMainQueryConds( $formOptions ),
00032             'SpecialRecentchangesTest::filterOutRcTimestampCondition'
00033         );
00034 
00035         $this->assertEquals(
00036             $expected,
00037             $queryConditions,
00038             $message
00039         );
00040     }
00041 
00043     private static function filterOutRcTimestampCondition( $var ) {
00044         return ( false === strpos( $var, 'rc_timestamp ' ) );
00045     }
00046 
00047     public function testRcNsFilter() {
00048         $this->assertConditions(
00049             array( # expected
00050                 'rc_bot' => 0,
00051                 #0 => "rc_timestamp >= '20110223000000'",
00052                 1 => "rc_namespace = '0'",
00053             ),
00054             array(
00055                 'namespace' => NS_MAIN,
00056             ),
00057             "rc conditions with no options (aka default setting)"
00058         );
00059     }
00060 
00061     public function testRcNsFilterInversion() {
00062         $this->assertConditions(
00063             array( # expected
00064                 #0 => "rc_timestamp >= '20110223000000'",
00065                 'rc_bot' => 0,
00066                 1 => sprintf( "rc_namespace != '%s'", NS_MAIN ),
00067             ),
00068             array(
00069                 'namespace' => NS_MAIN,
00070                 'invert' => 1,
00071             ),
00072             "rc conditions with namespace inverted"
00073         );
00074     }
00075 
00080     public function testRcNsFilterAssociation( $ns1, $ns2 ) {
00081         $this->assertConditions(
00082             array( # expected
00083                 #0 => "rc_timestamp >= '20110223000000'",
00084                 'rc_bot' => 0,
00085                 1 => sprintf( "(rc_namespace = '%s' OR rc_namespace = '%s')", $ns1, $ns2 ),
00086             ),
00087             array(
00088                 'namespace' => $ns1,
00089                 'associated' => 1,
00090             ),
00091             "rc conditions with namespace inverted"
00092         );
00093     }
00094 
00099     public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
00100         $this->assertConditions(
00101             array( # expected
00102                 #0 => "rc_timestamp >= '20110223000000'",
00103                 'rc_bot' => 0,
00104                 1 => sprintf( "(rc_namespace != '%s' AND rc_namespace != '%s')", $ns1, $ns2 ),
00105             ),
00106             array(
00107                 'namespace' => $ns1,
00108                 'associated' => 1,
00109                 'invert' => 1,
00110             ),
00111             "rc conditions with namespace inverted"
00112         );
00113     }
00114 
00119     public static function provideNamespacesAssociations() {
00120         return array( # (NS => Associated_NS)
00121             array( NS_MAIN, NS_TALK ),
00122             array( NS_TALK, NS_MAIN ),
00123         );
00124     }
00125 }