411d40618d5496c2efd256a4f953250f3da601b9
6 class PrefixSearchTest
extends MediaWikiLangTestCase
{
8 protected function setUp() {
11 if ( !$this->isWikitextNS( NS_MAIN
) ) {
12 $this->markTestSkipped( 'Main namespace does not support wikitext.' );
17 // Avoid special pages from extensions interferring with the tests
18 $this->setMwGlobals( 'wgSpecialPages', array() );
21 protected function searchProvision( Array $results = null ) {
22 if ( $results === null ) {
23 $this->setMwGlobals( 'wgHooks', array() );
25 $this->setMwGlobals( 'wgHooks', array(
26 'PrefixSearchBackend' => array(
27 function ( $namespaces, $search, $limit, &$srchres ) use ( $results ) {
36 public function insertPages() {
37 $this->insertPage( 'Sandbox' );
38 $this->insertPage( 'Bar' );
39 $this->insertPage( 'Example' );
40 $this->insertPage( 'Example Bar' );
41 $this->insertPage( 'Example Foo' );
42 $this->insertPage( 'Example Foo/Bar' );
43 $this->insertPage( 'Example/Baz' );
44 $this->insertPage( 'Redirect test', '#REDIRECT [[Redirect Test]]' );
45 $this->insertPage( 'Redirect Test');
46 $this->insertPage( 'Redirect Test Worse Result');
47 $this->insertPage( 'Redirect test2', '#REDIRECT [[Redirect Test2]]' );
48 $this->insertPage( 'Redirect TEST2', '#REDIRECT [[Redirect Test2]]' );
49 $this->insertPage( 'Redirect Test2');
50 $this->insertPage( 'Redirect Test2 Worse Result');
52 $this->insertPage( 'Talk:Sandbox' );
53 $this->insertPage( 'Talk:Example' );
55 $this->insertPage( 'User:Example' );
58 public static function provideSearch() {
66 'Main namespace with title prefix',
75 'Talk namespace prefix',
83 'User namespace prefix',
90 'Special namespace prefix',
91 'query' => 'Special:',
93 'Special:ActiveUsers',
94 'Special:AllMessages',
99 'Special namespace with prefix',
100 'query' => 'Special:Un',
103 'Special:UncategorizedCategories',
104 'Special:UncategorizedFiles',
109 'query' => 'Special:EditWatchlist',
111 'Special:EditWatchlist',
115 'Special page subpages',
116 'query' => 'Special:EditWatchlist/',
118 'Special:EditWatchlist/clear',
119 'Special:EditWatchlist/raw',
123 'Special page subpages with prefix',
124 'query' => 'Special:EditWatchlist/cl',
126 'Special:EditWatchlist/clear',
133 * @dataProvider provideSearch
134 * @covers PrefixSearch::search
135 * @covers PrefixSearch::searchBackend
137 public function testSearch( Array $case ) {
138 $this->searchProvision( null );
139 $searcher = new StringPrefixSearch
;
140 $results = $searcher->search( $case['query'], 3 );
148 public static function provideSearchBackend() {
152 'provision' => array(
165 'Exact match not on top (bug 70958)',
166 'provision' => array(
179 'Exact match missing (bug 70958)',
180 'provision' => array(
193 'Exact match missing and not existing',
194 'provision' => array(
207 "Exact match shouldn't override already found match if " .
208 "exact is redirect and found isn't",
209 'provision' => array(
210 // Target of the exact match is low in the list
211 'Redirect Test Worse Result',
214 'query' => 'redirect test',
216 // Redirect target is pulled up and exact match isn't added
218 'Redirect Test Worse Result',
222 "Exact match shouldn't override already found match if " .
223 "both exact match and found match are redirect",
224 'provision' => array(
225 // Another redirect to the same target as the exact match
226 // is low in the list
227 'Redirect Test2 Worse Result',
230 'query' => 'redirect TEST2',
232 // Found redirect is pulled to the top and exact match isn't
235 'Redirect Test2 Worse Result',
239 "Exact match should override any already found matches that " .
240 "are redirects to it",
241 'provision' => array(
242 // Another redirect to the same target as the exact match
243 // is low in the list
244 'Redirect Test Worse Result',
247 'query' => 'Redirect Test',
249 // Found redirect is pulled to the top and exact match isn't
252 'Redirect Test Worse Result',
259 * @dataProvider provideSearchBackend
260 * @covers PrefixSearch::searchBackend
262 public function testSearchBackend( Array $case ) {
263 $this->searchProvision( $case['provision'] );
264 $searcher = new StringPrefixSearch
;
265 $results = $searcher->search( $case['query'], 3 );