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' );
45 $this->insertPage( 'Talk:Sandbox' );
46 $this->insertPage( 'Talk:Example' );
48 $this->insertPage( 'User:Example' );
51 public static function provideSearch() {
59 'Main namespace with title prefix',
68 'Talk namespace prefix',
76 'User namespace prefix',
83 'Special namespace prefix',
84 'query' => 'Special:',
86 'Special:ActiveUsers',
87 'Special:AllMessages',
92 'Special namespace with prefix',
93 'query' => 'Special:Un',
96 'Special:UncategorizedCategories',
97 'Special:UncategorizedFiles',
102 'query' => 'Special:EditWatchlist',
104 'Special:EditWatchlist',
108 'Special page subpages',
109 'query' => 'Special:EditWatchlist/',
111 'Special:EditWatchlist/clear',
112 'Special:EditWatchlist/raw',
116 'Special page subpages with prefix',
117 'query' => 'Special:EditWatchlist/cl',
119 'Special:EditWatchlist/clear',
126 * @dataProvider provideSearch
127 * @covers PrefixSearch::search
128 * @covers PrefixSearch::searchBackend
130 public function testSearch( Array $case ) {
131 $this->searchProvision( null );
132 $searcher = new StringPrefixSearch
;
133 $results = $searcher->search( $case['query'], 3 );
141 public static function provideSearchBackend() {
145 'provision' => array(
158 'Exact match not on top (bug 70958)',
159 'provision' => array(
172 'Exact match missing (bug 70958)',
173 'provision' => array(
186 'Exact match missing and not existing',
187 'provision' => array(
203 * @dataProvider provideSearchBackend
204 * @covers PrefixSearch::searchBackend
206 public function testSearchBackend( Array $case ) {
207 $this->searchProvision( $case['provision'] );
208 $searcher = new StringPrefixSearch
;
209 $results = $searcher->search( $case['query'], 3 );