Destroy session after running api tests
[lhc/web/wiklou.git] / tests / phpunit / includes / PrefixSearchTest.php
index 411d406..e737056 100644 (file)
@@ -42,12 +42,12 @@ class PrefixSearchTest extends MediaWikiLangTestCase {
                $this->insertPage( 'Example Foo/Bar' );
                $this->insertPage( 'Example/Baz' );
                $this->insertPage( 'Redirect test', '#REDIRECT [[Redirect Test]]' );
-               $this->insertPage( 'Redirect Test');
-               $this->insertPage( 'Redirect Test Worse Result');
+               $this->insertPage( 'Redirect Test' );
+               $this->insertPage( 'Redirect Test Worse Result' );
                $this->insertPage( 'Redirect test2', '#REDIRECT [[Redirect Test2]]' );
                $this->insertPage( 'Redirect TEST2', '#REDIRECT [[Redirect Test2]]' );
-               $this->insertPage( 'Redirect Test2');
-               $this->insertPage( 'Redirect Test2 Worse Result');
+               $this->insertPage( 'Redirect Test2' );
+               $this->insertPage( 'Redirect Test2 Worse Result' );
 
                $this->insertPage( 'Talk:Sandbox' );
                $this->insertPage( 'Talk:Example' );
@@ -70,6 +70,10 @@ class PrefixSearchTest extends MediaWikiLangTestCase {
                                        'Example/Baz',
                                        'Example Bar',
                                ),
+                               // Third result when testing offset
+                               'offsetresult' => array(
+                                       'Example Foo',
+                               ),
                        ) ),
                        array( array(
                                'Talk namespace prefix',
@@ -94,6 +98,10 @@ class PrefixSearchTest extends MediaWikiLangTestCase {
                                        'Special:AllMessages',
                                        'Special:AllMyFiles',
                                ),
+                               // Third result when testing offset
+                               'offsetresult' => array(
+                                       'Special:AllMyUploads',
+                               ),
                        ) ),
                        array( array(
                                'Special namespace with prefix',
@@ -103,6 +111,10 @@ class PrefixSearchTest extends MediaWikiLangTestCase {
                                        'Special:UncategorizedCategories',
                                        'Special:UncategorizedFiles',
                                ),
+                               // Third result when testing offset
+                               'offsetresult' => array(
+                                       'Special:UncategorizedImages',
+                               ),
                        ) ),
                        array( array(
                                'Special page name',
@@ -145,6 +157,30 @@ class PrefixSearchTest extends MediaWikiLangTestCase {
                );
        }
 
+       /**
+        * @dataProvider provideSearch
+        * @covers PrefixSearch::search
+        * @covers PrefixSearch::searchBackend
+        */
+       public function testSearchWithOffset( Array $case ) {
+               $this->searchProvision( null );
+               $searcher = new StringPrefixSearch;
+               $results = $searcher->search( $case['query'], 3, array(), 1 );
+
+               // We don't expect the first result when offsetting
+               array_shift( $case['results'] );
+               // And sometimes we expect a different last result
+               $expected = isset( $case['offsetresult'] ) ?
+                       array_merge( $case['results'], $case['offsetresult'] ) :
+                       $case['results'];
+
+               $this->assertEquals(
+                       $expected,
+                       $results,
+                       $case[0]
+               );
+       }
+
        public static function provideSearchBackend() {
                return array(
                        array( array(