MediaWiki
REL1_21
|
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 00048 public function testRcNsFilter() { 00049 $this->assertConditions( 00050 array( # expected 00051 'rc_bot' => 0, 00052 #0 => "rc_timestamp >= '20110223000000'", 00053 1 => "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 #0 => "rc_timestamp >= '20110223000000'", 00066 'rc_bot' => 0, 00067 1 => sprintf( "rc_namespace != '%s'", NS_MAIN ), 00068 ), 00069 array( 00070 'namespace' => NS_MAIN, 00071 'invert' => 1, 00072 ), 00073 "rc conditions with namespace inverted" 00074 ); 00075 } 00076 00081 public function testRcNsFilterAssociation( $ns1, $ns2 ) { 00082 $this->assertConditions( 00083 array( # expected 00084 #0 => "rc_timestamp >= '20110223000000'", 00085 'rc_bot' => 0, 00086 1 => sprintf( "(rc_namespace = '%s' OR rc_namespace = '%s')", $ns1, $ns2 ), 00087 ), 00088 array( 00089 'namespace' => $ns1, 00090 'associated' => 1, 00091 ), 00092 "rc conditions with namespace inverted" 00093 ); 00094 } 00095 00100 public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) { 00101 $this->assertConditions( 00102 array( # expected 00103 #0 => "rc_timestamp >= '20110223000000'", 00104 'rc_bot' => 0, 00105 1 => sprintf( "(rc_namespace != '%s' AND rc_namespace != '%s')", $ns1, $ns2 ), 00106 ), 00107 array( 00108 'namespace' => $ns1, 00109 'associated' => 1, 00110 'invert' => 1, 00111 ), 00112 "rc conditions with namespace inverted" 00113 ); 00114 } 00115 00120 public static function provideNamespacesAssociations() { 00121 return array( # (NS => Associated_NS) 00122 array( NS_MAIN, NS_TALK ), 00123 array( NS_TALK, NS_MAIN ), 00124 ); 00125 } 00126 00127 }