MediaWiki
REL1_22
|
00001 <?php 00010 class SpecialSearchTest extends MediaWikiTestCase { 00011 private $search; 00012 00021 public function testProfileAndNamespaceLoading( 00022 $requested, $userOptions, $expectedProfile, $expectedNS, 00023 $message = 'Profile name and namespaces mismatches!' 00024 ) { 00025 $context = new RequestContext; 00026 $context->setUser( 00027 $this->newUserWithSearchNS( $userOptions ) 00028 ); 00029 /* 00030 $context->setRequest( new FauxRequest( array( 00031 'ns5'=>true, 00032 'ns6'=>true, 00033 ) )); 00034 */ 00035 $context->setRequest( new FauxRequest( $requested ) ); 00036 $search = new SpecialSearch(); 00037 $search->setContext( $context ); 00038 $search->load(); 00039 00045 $this->assertEquals( 00046 array( 00047 'ProfileName' => $expectedProfile, 00048 'Namespaces' => $expectedNS, 00049 ) 00050 , array( 00051 'ProfileName' => $search->getProfile(), 00052 'Namespaces' => $search->getNamespaces(), 00053 ) 00054 , $message 00055 ); 00056 } 00057 00058 public static function provideSearchOptionsTests() { 00059 $defaultNS = SearchEngine::defaultNamespaces(); 00060 $EMPTY_REQUEST = array(); 00061 $NO_USER_PREF = null; 00062 00063 return array( 00071 array( 00072 $EMPTY_REQUEST, $NO_USER_PREF, 00073 'default', $defaultNS, 00074 'Bug 33270: No request nor user preferences should give default profile' 00075 ), 00076 array( 00077 array( 'ns5' => 1 ), $NO_USER_PREF, 00078 'advanced', array( 5 ), 00079 'Web request with specific NS should override user preference' 00080 ), 00081 array( 00082 $EMPTY_REQUEST, array( 00083 'searchNs2' => 1, 00084 'searchNs14' => 1, 00085 ) + array_fill_keys( array_map( function ( $ns ) { 00086 return "searchNs$ns"; 00087 }, $defaultNS ), 0 ), 00088 'advanced', array( 2, 14 ), 00089 'Bug 33583: search with no option should honor User search preferences' 00090 . ' and have all other namespace disabled' 00091 ), 00092 ); 00093 } 00094 00099 function newUserWithSearchNS( $opt = null ) { 00100 $u = User::newFromId( 0 ); 00101 if ( $opt === null ) { 00102 return $u; 00103 } 00104 foreach ( $opt as $name => $value ) { 00105 $u->setOption( $name, $value ); 00106 } 00107 00108 return $u; 00109 } 00110 00115 public function testSearchTermIsNotExpanded() { 00116 00117 # Initialize [[Special::Search]] 00118 $search = new SpecialSearch(); 00119 $search->getContext()->setTitle( Title::newFromText( 'Special:Search' ) ); 00120 $search->load(); 00121 00122 # Simulate a user searching for a given term 00123 $term = '{{SITENAME}}'; 00124 $search->showResults( $term ); 00125 00126 # Lookup the HTML page title set for that page 00127 $pageTitle = $search 00128 ->getContext() 00129 ->getOutput() 00130 ->getHTMLTitle(); 00131 00132 # Compare :-] 00133 $this->assertRegExp( 00134 '/' . preg_quote( $term ) . '/', 00135 $pageTitle, 00136 "Search term '{$term}' should not be expanded in Special:Search <title>" 00137 ); 00138 } 00139 }