25 $expectedProfile, $expectedNS, $message =
'Profile name and namespaces mismatches!'
49 'ProfileName' => $expectedProfile,
50 'Namespaces' => $expectedNS,
53 'ProfileName' => $search->getProfile(),
54 'Namespaces' => $search->getNamespaces(),
61 $defaultNS = MediaWikiServices::getInstance()->getSearchEngineConfig()->defaultNamespaces();
74 $EMPTY_REQUEST, $NO_USER_PREF,
75 'default', $defaultNS,
76 'T35270: No request nor user preferences should give default profile'
79 [
'ns5' => 1 ], $NO_USER_PREF,
81 'Web request with specific NS should override user preference'
87 ] + array_fill_keys( array_map(
function ( $ns ) {
90 'advanced', [ 2, 14 ],
91 'T35583: search with no option should honor User search preferences'
92 .
' and have all other namespace disabled'
103 $u = User::newFromId( 0 );
104 if (
$opt ===
null ) {
108 $u->setOption( $name,
$value );
120 'wgSearchType' =>
null,
123 # Initialize [[Special::Search]]
125 $term =
'{{SITENAME}}';
126 $ctx->setRequest(
new FauxRequest( [
'search' =>
$term,
'fulltext' => 1 ] ) );
127 $ctx->setTitle( Title::newFromText(
'Special:Search' ) );
129 $search->setContext( $ctx );
131 # Simulate a user searching for a given term
132 $search->execute(
'' );
134 # Lookup the HTML page title set for that page
142 '/' . preg_quote(
$term,
'/' ) .
'/',
144 "Search term '{$term}' should not be expanded in Special:Search <title>"
151 'With suggestion and no rewritten query shows did you mean',
152 '/Did you mean: <a[^>]+>first suggestion/',
155 [ Title::newMainPage() ]
159 'With rewritten query informs user of change',
160 '/Showing results for <a[^>]+>first suggestion/',
163 [ Title::newMainPage() ]
167 'When both queries have no results user gets no results',
168 '/There were no results matching the query/',
186 $results = array_map(
function ( $title ) {
187 return SearchResult::newFromTitle( $title );
197 $search = $this->getMockBuilder(
'SpecialSearch' )
198 ->setMethods( [
'getSearchEngine' ] )
200 $search->expects( $this->
any() )
201 ->method(
'getSearchEngine' )
202 ->will( $this->returnValue( $mockSearchEngine ) );
204 $search->getContext()->setTitle( Title::makeTitle(
NS_SPECIAL,
'Search' ) );
205 $search->getContext()->setLanguage( Language::factory(
'en' ) );
207 $search->showResults(
'this is a fake search' );
209 $html = $search->getContext()->getOutput()->getHTML();
210 foreach ( (array)$expectRegex as $regex ) {
211 $this->assertRegExp( $regex,
$html, $message );
216 $mock = $this->getMockBuilder(
'SearchEngine' )
217 ->setMethods( [
'searchText',
'searchTitle' ] )
220 $mock->expects( $this->
any() )
221 ->method(
'searchText' )
222 ->will( $this->returnValue( $results ) );
229 'wgScript' =>
'/w/index.php',
233 $sp = Title::newFromText(
'Special:Search/foo_bar' );
235 $url = $ctx->getOutput()->getRedirect();
241 $parts = parse_url( $url );
242 $this->assertEquals(
'/w/index.php', $parts[
'path'] );
243 parse_str( $parts[
'query'],
$query );
244 $this->assertEquals(
'Special:Search',
$query[
'title'] );
245 $this->assertEquals(
'foo bar',
$query[
'search'] );
255 $rewrittenQuery =
null,
260 $this->rewrittenQuery = $rewrittenQuery;
266 return count( $this->results );
274 return $this->suggestion !==
null;
286 return $this->rewrittenQuery !==
null;
290 return $this->rewrittenQuery;
294 return htmlspecialchars( $this->rewrittenQuery );
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
WebRequest clone which takes values from a provided array.
Group all the pieces relevant to the context of a request into one instance.
$containedSyntax
Types of interwiki results.
static executePath(Title &$title, IContextSource &$context, $including=false, LinkRenderer $linkRenderer=null)
Execute a special page path.
hasRewrittenQuery()
Some search modes will run an alternative query that it thinks gives a better result than the provide...
getTotalHits()
Some search modes return a total hit count for the query in the entire article database.
__construct( $suggestion=null, $rewrittenQuery=null, array $results=[], $containedSyntax=false)
hasSuggestion()
Some search modes return a suggested alternate term if there are no exact hits.
getQueryAfterRewriteSnippet()
Test class for SpecialSearch class Copyright © 2012, Antoine Musso.
testSearchTermIsNotExpanded()
Verify we do not expand search term in <title> on search result page https://gerrit....
mockSearchEngine( $results)
testProfileAndNamespaceLoading( $requested, $userOptions, $expectedProfile, $expectedNS, $message='Profile name and namespaces mismatches!')
SpecialSearch::load provideSearchOptionsTests.
newUserWithSearchNS( $opt=null)
Helper to create a new User object with given options User remains anonymous though.
testRewriteQueryWithSuggestion( $message, $expectRegex, $suggestion, $rewrittenQuery, array $resultTitles)
provideRewriteQueryWithSuggestion
static provideSearchOptionsTests()
provideRewriteQueryWithSuggestion()
implements Special:Search - Run text & title search and display the output
external whereas SearchGetNearMatch runs after $term
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query