X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=tests%2FSearchEngineTest.php;h=dc5023f456001bad5827c4324ab52084d97600c2;hb=704c16572f41b79a2e49bcd3b767e68ae0a5b703;hp=1c732b3448ca303240a30cbfb6d52ae6f3bccc35;hpb=af2177edfd9b108eca8598f9ace57672f0521942;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/SearchEngineTest.php b/tests/SearchEngineTest.php index 1c732b3448..dc5023f456 100644 --- a/tests/SearchEngineTest.php +++ b/tests/SearchEngineTest.php @@ -1,22 +1,15 @@ db->safeQuery( <<db->safeQuery( <<db->tableName( 'page' ) ); - $this->db->safeQuery( <<db->safeQuery( <<db->tableName( 'revision' ) ); - $this->db->safeQuery( <<db->safeQuery( <<db->tableName( 'text' ) ); - $this->db->safeQuery( <<db->safeQuery( <<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" ); } - + } -?> +