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