Merge "(bug 37755) Set robot meta tags for 'view source' pages"
[lhc/web/wiklou.git] / tests / phpunit / includes / search / SearchEngineTest.php
index 86ef3a9..511166a 100644 (file)
@@ -1,41 +1,52 @@
 <?php
 
-require_once dirname(dirname(dirname(__FILE__))). '/bootstrap.php';
-
 /**
- * This class is not directly tested. Instead it is extended by SearchDbTest.
  * @group Search
- * @group Stub
- * @group Destructive
+ * @group Database
  */
-class SearchEngineTest extends MediaWikiTestCase {
-       var $db, $search, $pageList;
+class SearchEngineTest extends MediaWikiLangTestCase {
+       protected $search, $pageList;
 
-       /*
+       /**
         * Checks for database type & version.
         * Will skip current test if DB does not support search.
         */
-       function setUp() {
+       protected function setUp() {
+               parent::setUp();
+
                // Search tests require MySQL or SQLite with FTS
                # Get database type and version
-               $dbType    = $this->db->getType();
+               $dbType = $this->db->getType();
                $dbSupported =
                        ($dbType === 'mysql')
-                       || (   $dbType === 'sqlite' && $this->db->getFulltextSearchModule() == 'FTS3' );
+                       || ( $dbType === 'sqlite' && $this->db->getFulltextSearchModule() == 'FTS3' );
 
                if( !$dbSupported ) {
                        $this->markTestSkipped( "MySQL or SQLite with FTS3 only" );
                }
+
+               $searchType = $this->db->getSearchEngine();
+               $this->search = new $searchType( $this->db );
+       }
+
+       protected function tearDown() {
+               unset( $this->search );
        }
 
        function pageExists( $title ) {
                return false;
        }
 
-       function insertSearchData() {
+       function addDBData() {
                if ( $this->pageExists( 'Not_Main_Page' ) ) {
                        return;
                }
+
+               if ( !$this->isWikitextNS( NS_MAIN ) ) {
+                       //@todo: cover the case of non-wikitext content in the main namespace
+                       return;
+               }
+
                $this->insertPage( "Not_Main_Page",     "This is not a main page", 0 );
                $this->insertPage( 'Talk:Not_Main_Page',        'This is not a talk page to the main page, see [[smithee]]', 1 );
                $this->insertPage( 'Smithee',   'A smithee is one who smiths. See also [[Alan Smithee]]', 0 );
@@ -55,21 +66,19 @@ class SearchEngineTest extends MediaWikiTestCase {
                $this->insertPage( 'DomainName',        'example.com', 0 );
        }
 
-       function removeSearchData() {
-               return;
-               /*while ( count( $this->pageList ) ) {
-                       list( $title, $id ) = array_pop( $this->pageList );
-                       $article = new Article( $title, $id );
-                       $article->doDeleteArticle( "Search Test" );
-               }*/
-       }
-
        function fetchIds( $results ) {
+               if ( !$this->isWikitextNS( NS_MAIN ) ) {
+                       $this->markTestIncomplete( __CLASS__ . " does no yet support non-wikitext content "
+                               . "in the main namespace");
+               }
+
                $this->assertTrue( is_object( $results ) );
 
                $matches = array();
-               while ( $row = $results->next() ) {
+               $row = $results->next();
+               while ( $row ) {
                        $matches[] = $row->getTitle()->getPrefixedText();
+                       $row = $results->next();
                }
                $results->free();
                # Search is not guaranteed to return results in a certain order;
@@ -79,43 +88,47 @@ class SearchEngineTest extends MediaWikiTestCase {
                return $matches;
        }
 
-       // Modified version of WikiRevision::importOldRevision()
+       /**
+        * Insert a new page
+        *
+        * @param $pageName String: page name
+        * @param $text String: page's content
+        * @param $n Integer: unused
+        */
        function insertPage( $pageName, $text, $ns ) {
-                       $dbw = $this->db;
-                       $title = Title::newFromText( $pageName );
+               $title = Title::newFromText( $pageName, $ns );
 
-                       $user = User::newFromName( 'WikiSysop' );
-                       $comment = 'Search Test';
+               $user = User::newFromName( 'WikiSysop' );
+               $comment = 'Search Test';
 
-                       // avoid memory leak...?
-                       $linkCache = LinkCache::singleton();
-                       $linkCache->clear();
+               // avoid memory leak...?
+               LinkCache::singleton()->clear();
 
-                       $article = new Article( $title );
-                       $article->doEdit( $text, $comment, 0, false, $user );
+               $page = WikiPage::factory( $title );
+               $page->doEditContent( ContentHandler::makeContent( $text, $title ), $comment, 0, false, $user );
 
-                       $this->pageList[] = array( $title, $article->getId() );
+               $this->pageList[] = array( $title, $page->getId() );
 
-                       return true;
-               }
+               return true;
+       }
 
        function testFullWidth() {
-                       $this->assertEquals(
-                               array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
-                               $this->fetchIds( $this->search->searchText( 'AZ' ) ),
-                               "Search for normalized from Half-width Upper" );
-                       $this->assertEquals(
-                               array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
-                               $this->fetchIds( $this->search->searchText( 'az' ) ),
-                               "Search for normalized from Half-width Lower" );
-                       $this->assertEquals(
-                               array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
-                               $this->fetchIds( $this->search->searchText( 'AZ' ) ),
-                               "Search for normalized from Full-width Upper" );
-                       $this->assertEquals(
-                               array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
-                               $this->fetchIds( $this->search->searchText( 'az' ) ),
-                               "Search for normalized from Full-width Lower" );
+               $this->assertEquals(
+                       array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
+                       $this->fetchIds( $this->search->searchText( 'AZ' ) ),
+                       "Search for normalized from Half-width Upper" );
+               $this->assertEquals(
+                       array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
+                       $this->fetchIds( $this->search->searchText( 'az' ) ),
+                       "Search for normalized from Half-width Lower" );
+               $this->assertEquals(
+                       array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
+                       $this->fetchIds( $this->search->searchText( 'AZ' ) ),
+                       "Search for normalized from Full-width Upper" );
+               $this->assertEquals(
+                       array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
+                       $this->fetchIds( $this->search->searchText( 'az' ) ),
+                       "Search for normalized from Full-width Lower" );
        }
 
        function testTextSearch() {