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