6 class PrefixSearchTest
extends MediaWikiTestCase
{
8 protected function setUp() {
11 // Avoid special pages from extensions interferring with the tests
12 $this->setMwGlobals( 'wgSpecialPages', array() );
15 protected function searchProvision( Array $results = null ) {
16 if ( $results === null ) {
17 $this->setMwGlobals( 'wgHooks', array() );
19 $this->setMwGlobals( 'wgHooks', array(
20 'PrefixSearchBackend' => array(
21 function ( $namespaces, $search, $limit, &$srchres ) use ( $results ) {
30 public function addDBData() {
31 $this->insertPage( 'Sandbox' );
33 $this->insertPage( 'Example' );
34 $this->insertPage( 'Example Bar' );
35 $this->insertPage( 'Example Foo' );
36 $this->insertPage( 'Example Foo/Bar' );
37 $this->insertPage( 'Example/Baz' );
39 $this->insertPage( 'Talk:Sandbox' );
40 $this->insertPage( 'Talk:Example' );
42 $this->insertPage( 'User:Example' );
45 public static function provideSearch() {
53 'Main namespace with title prefix',
62 'Talk namespace prefix',
70 'User namespace prefix',
77 'Special namespace prefix',
78 'query' => 'Special:',
80 'Special:ActiveUsers',
81 'Special:AllMessages',
86 'Special namespace with prefix',
87 'query' => 'Special:Un',
90 'Special:UncategorizedCategories',
91 'Special:UncategorizedFiles',
96 'query' => 'Special:EditWatchlist',
98 'Special:EditWatchlist',
102 'Special page subpages',
103 'query' => 'Special:EditWatchlist/',
105 'Special:EditWatchlist/clear',
106 'Special:EditWatchlist/raw',
110 'Special page subpages with prefix',
111 'query' => 'Special:EditWatchlist/cl',
113 'Special:EditWatchlist/clear',
120 * @dataProvider provideSearch
121 * @covers PrefixSearch::search
122 * @covers PrefixSearch::searchBackend
124 public function testSearch( Array $case ) {
125 $this->searchProvision( null );
126 $searcher = new StringPrefixSearch
;
127 $results = $searcher->search( $case['query'], 3 );