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