PHPUnit tests:
[lhc/web/wiklou.git] / tests / SearchEngineTest.php
index 1c732b3..dc5023f 100644 (file)
@@ -1,22 +1,15 @@
 <?php
 
-$IP = '..';
-require_once( 'PHPUnit.php' );
-require_once( '../includes/Defines.php' );
-require_once( '../includes/DefaultSettings.php' );
-require_once( '../includes/Profiling.php' );
-require_once( '../includes/MagicWord.php' );
-require_once( '../languages/Language.php' );
-require_once( '../languages/LanguageUtf8.php' );
+require_once( 'MediaWiki_TestCase.php' );
 
-require_once( '../includes/SearchEngine.php' );
+/** @todo document
+ */
 
-/** @todo document */
-class SearchEngine_TestCase extends PHPUnit_TestCase {
+class SearchEngineTest extends MediaWiki_TestCase {
        var $db, $search;
-       
+
        function insertSearchData() {
-               $this->db->safeQuery( <<<END
+               $this->db->safeQuery( <<<SQL
                INSERT INTO ! (page_id,page_namespace,page_title,page_latest)
                VALUES (1, 0, 'Main_Page', 1),
                           (2, 1, 'Main_Page', 2),
@@ -28,9 +21,9 @@ class SearchEngine_TestCase extends PHPUnit_TestCase {
                           (8, 0, 'Thppt', 8),
                           (9, 0, 'Alan_Smithee', 9),
                           (10, 0, 'Pages', 10)
-END
+SQL
                        , $this->db->tableName( 'page' ) );
-               $this->db->safeQuery( <<<END
+               $this->db->safeQuery( <<<SQL
                INSERT INTO ! (rev_id,rev_page)
                VALUES (1, 1),
                       (2, 2),
@@ -42,9 +35,9 @@ END
                       (8, 8),
                       (9, 9),
                       (10, 10)
-END
+SQL
                        , $this->db->tableName( 'revision' ) );
-               $this->db->safeQuery( <<<END
+               $this->db->safeQuery( <<<SQL
                INSERT INTO ! (old_id,old_text)
                VALUES (1, 'This is a main page'),
                           (2, 'This is a talk page to the main page, see [[smithee]]'),
@@ -56,9 +49,9 @@ END
                           (8, 'Blah blah'),
                           (9, 'yum'),
                           (10,'are food')
-END
+SQL
                        , $this->db->tableName( 'text' ) );
-               $this->db->safeQuery( <<<END
+               $this->db->safeQuery( <<<SQL
                INSERT INTO ! (si_page,si_title,si_text)
                VALUES (1, 'main page', 'this is a main page'),
                           (2, 'main page', 'this is a talk page to the main page, see smithee'),
@@ -70,14 +63,14 @@ END
                           (8, 'thppt', 'blah blah'),
                           (9, 'alan smithee', 'yum'),
                           (10, 'pages', 'are food')
-END
+SQL
                        , $this->db->tableName( 'searchindex' ) );
        }
-       
-       function fetchIds( &$results ) {
+
+       function fetchIds( $results ) {
                $matches = array();
-               while( $row = $results->fetchObject() ) {
-                       $matches[] = intval( $row->page_id );
+               while( $row = $results->next() ) {
+                       $matches[] = $row->getTitle()->getPrefixedText();
                }
                $results->free();
                # Search is not guaranteed to return results in a certain order;
@@ -86,50 +79,60 @@ END
                sort( $matches );
                return $matches;
        }
-       
+
        function testTextSearch() {
-               $this->assertFalse( is_null( $this->db ), "Can't find a database to test with." );
-               if( !is_null( $this->db ) ) {
-                       $this->assertEquals(
-                               array( 3 ),
-                               $this->fetchIds( $this->search->searchText( 'smithee' ) ),
-                               "Plain search failed" );
+               if( is_null( $this->db ) ) {
+                       $this->markTestIncomplete( "Can't find a database to test with." );
                }
+               $this->assertEquals(
+                       array( 'Smithee' ),
+                       $this->fetchIds( $this->search->searchText( 'smithee' ) ),
+                       "Plain search failed" );
        }
-       
+
        function testTextPowerSearch() {
-               $this->assertFalse( is_null( $this->db ), "Can't find a database to test with." );
-               if( !is_null( $this->db ) ) {
-                       $this->search->setNamespaces( array( 0, 1, 4 ) );
-                       $this->assertEquals(
-                               array( 2, 3 ),
-                               $this->fetchIds( $this->search->searchText( 'smithee' ) ),
-                               "Power search failed" );
+               if( is_null( $this->db ) ) {
+                       $this->markTestIncomplete( "Can't find a database to test with." );
                }
+               $this->search->setNamespaces( array( 0, 1, 4 ) );
+               $this->assertEquals(
+                       array(
+                               'Smithee',
+                               'Talk:Main Page',
+                       ),
+                       $this->fetchIds( $this->search->searchText( 'smithee' ) ),
+                       "Power search failed" );
        }
-       
+
        function testTitleSearch() {
-               $this->assertFalse( is_null( $this->db ), "Can't find a database to test with." );
-               if( !is_null( $this->db ) ) {
-                       $this->assertEquals(
-                               array( 3, 9 ),
-                               $this->fetchIds( $this->search->searchTitle( 'smithee' ) ),
-                               "Title search failed" );
+               if( is_null( $this->db ) ) {
+                       $this->markTestIncomplete( "Can't find a database to test with." );
                }
+               $this->assertEquals(
+                       array(
+                               'Alan Smithee',
+                               'Smithee',
+                       ),
+                       $this->fetchIds( $this->search->searchTitle( 'smithee' ) ),
+                       "Title search failed" );
        }
-       
+
        function testTextTitlePowerSearch() {
-               $this->assertFalse( is_null( $this->db ), "Can't find a database to test with." );
-               if( !is_null( $this->db ) ) {
-                       $this->search->setNamespaces( array( 0, 1, 4 ) );
-                       $this->assertEquals(
-                               array( 3, 4, 9 ),
-                               $this->fetchIds( $this->search->searchTitle( 'smithee' ) ),
-                               "Title power search failed" );
+               if( is_null( $this->db ) ) {
+                       $this->markTestIncomplete( "Can't find a database to test with." );
                }
+               $this->search->setNamespaces( array( 0, 1, 4 ) );
+               $this->assertEquals(
+                       array(
+                               'Alan Smithee',
+                               'Smithee',
+                               'Talk:Smithee',
+                       ),
+                       $this->fetchIds( $this->search->searchTitle( 'smithee' ) ),
+                       "Title power search failed" );
        }
-       
+
 }
 
 
-?>
+