4use Wikimedia\TestingAccessWrapper;
36 $this->
insertPage(
'Redirect test',
'#REDIRECT [[Redirect Test]]' );
38 $this->
insertPage(
'Redirect Test Worse Result' );
39 $this->
insertPage(
'Redirect test2',
'#REDIRECT [[Redirect Test2]]' );
40 $this->
insertPage(
'Redirect TEST2',
'#REDIRECT [[Redirect Test2]]' );
42 $this->
insertPage(
'Redirect Test2 Worse Result' );
57 $this->markTestSkipped(
'Main namespace does not support wikitext.' );
62 'wgSpecialPages' => [],
66 $this->search = MediaWikiServices::getInstance()->newSearchEngine();
67 $this->search->setNamespaces( [] );
69 $this->originalHandlers = TestingAccessWrapper::newFromClass( Hooks::class )->handlers;
70 TestingAccessWrapper::newFromClass( Hooks::class )->handlers = [];
82 if ( $results ===
null ) {
86 'PrefixSearchBackend' => [
104 'Main namespace with title prefix',
117 'Talk namespace prefix',
125 'User namespace prefix',
132 'Special namespace prefix',
133 'query' =>
'Special:',
135 'Special:ActiveUsers',
136 'Special:AllMessages',
137 'Special:AllMyUploads',
145 'Special namespace with prefix',
146 'query' =>
'Special:Un',
149 'Special:UncategorizedCategories',
150 'Special:UncategorizedFiles',
154 'Special:UncategorizedPages',
159 'query' =>
'Special:EditWatchlist',
161 'Special:EditWatchlist',
165 'Special page subpages',
166 'query' =>
'Special:EditWatchlist/',
168 'Special:EditWatchlist/clear',
169 'Special:EditWatchlist/raw',
173 'Special page subpages with prefix',
174 'query' =>
'Special:EditWatchlist/cl',
176 'Special:EditWatchlist/clear',
187 $this->search->setLimitOffset( 3 );
188 $results = $this->search->defaultPrefixSearch( $case[
'query'] );
189 $results = array_map(
function (
Title $t ) {
190 return $t->getPrefixedText();
205 $this->search->setLimitOffset( 3, 1 );
206 $results = $this->search->defaultPrefixSearch( $case[
'query'] );
207 $results = array_map(
function (
Title $t ) {
208 return $t->getPrefixedText();
212 array_shift( $case[
'results'] );
214 $expected = isset( $case[
'offsetresult'] ) ?
215 array_merge( $case[
'results'], $case[
'offsetresult'] ) :
242 'Exact match not in first result should be moved to the first result (T72958)',
256 'Exact match missing from results should be added as first result (T72958)',
270 'Exact match missing and not existing pages should be dropped',
282 "Exact match shouldn't override already found match if " .
283 "exact is redirect and found isn't",
286 'Redirect Test Worse Result',
289 'query' =>
'redirect test',
293 'Redirect Test Worse Result',
297 "Exact match shouldn't override already found match if " .
298 "both exact match and found match are redirect",
302 'Redirect Test2 Worse Result',
305 'query' =>
'redirect TEST2',
310 'Redirect Test2 Worse Result',
314 "Exact match should override any already found matches that " .
315 "are redirects to it",
319 'Redirect Test Worse Result',
322 'query' =>
'Redirect Test',
327 'Redirect Test Worse Result',
332 "Extra results must not be returned",
358 return $s->getText();
369 $res = [
'Example',
'Example Bar',
'Example Foo',
'Example Foo/Bar' ];
371 'With less than requested results no pagination' => [
372 false, array_slice(
$res, 0, 2 ),
374 'With same as requested results no pagination' => [
375 false, array_slice(
$res, 0, 3 ),
377 'With extra result returned offer pagination' => [
390 $this->assertEquals( $hasMoreResults, $results->hasMoreResults() );
394 $search = $stub = $this->getMockBuilder( SearchEngine::class )
395 ->setMethods( [
'completionSearchBackend' ] )->getMock();
400 ->method(
'completionSearchBackend' )
401 ->will( $this->returnValue( $return ) );
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
mockSearchWithResults( $titleStrings, $limit=3)
testSearchBackend(array $case)
provideSearchBackend PrefixSearch::searchBackend
testSearchWithOffset(array $case)
provideSearch SearchEngine::defaultPrefixSearch
static provideSearchBackend()
testSearch(array $case)
provideSearch SearchEngine::defaultPrefixSearch
searchProvision(array $results=null)
testPagination( $hasMoreResults, $provision)
paginationProvider
Contain a class for special pages.
completionSearch( $search)
Perform a completion search.
setLimitOffset( $limit, $offset=0)
Set the maximum number of results to return and how many to skip before returning the first.
static fromStrings(array $titles, $hasMoreResults=false)
Builds a new set of suggestion based on a string array.
Represents a title within MediaWiki.
namespace and then decline to actually register it & $namespaces
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))