4 require_once( 'PHPUnit.php' );
5 require_once( '../includes/Defines.php' );
6 require_once( '../includes/DefaultSettings.php' );
7 require_once( '../includes/Profiling.php' );
8 require_once( '../includes/MagicWord.php' );
9 require_once( '../languages/Language.php' );
10 require_once( '../languages/LanguageUtf8.php' );
12 require_once( '../includes/SearchEngine.php' );
14 class SearchEngine_TestCase
extends PHPUnit_TestCase
{
17 function insertSearchData() {
18 $this->db
->safeQuery( <<<END
19 INSERT INTO ! (page_id,page_namespace,page_title,page_latest)
20 VALUES (1, 0, 'Main_Page', 1),
21 (2, 1, 'Main_Page', 2),
24 (5, 0, 'Unrelated_page', 5),
25 (6, 0, 'Another_page', 6),
28 (9, 0, 'Alan_Smithee', 9),
31 , $this->db
->tableName( 'page' ) );
32 $this->db
->safeQuery( <<<END
33 INSERT INTO ! (rev_id,rev_page)
45 , $this->db
->tableName( 'revision' ) );
46 $this->db
->safeQuery( <<<END
47 INSERT INTO ! (old_id,old_text)
48 VALUES (1, 'This is a main page'),
49 (2, 'This is a talk page to the main page, see [[smithee]]'),
50 (3, 'A smithee is one who smiths. See also [[Alan Smithee]]'),
51 (4, 'This article sucks.'),
52 (5, 'Nothing in this page is about the S word.'),
53 (6, 'This page also is unrelated.'),
59 , $this->db
->tableName( 'text' ) );
60 $this->db
->safeQuery( <<<END
61 INSERT INTO ! (si_page,si_title,si_text)
62 VALUES (1, 'main page', 'this is a main page'),
63 (2, 'main page', 'this is a talk page to the main page, see smithee'),
64 (3, 'smithee', 'a smithee is one who smiths see also alan smithee'),
65 (4, 'smithee', 'this article sucks'),
66 (5, 'unrelated page', 'nothing in this page is about the s word'),
67 (6, 'another page', 'this page also is unrelated'),
68 (7, 'help', 'help me'),
69 (8, 'thppt', 'blah blah'),
70 (9, 'alan smithee', 'yum'),
71 (10, 'pages', 'are food')
73 , $this->db
->tableName( 'searchindex' ) );
76 function fetchIds( &$results ) {
78 while( $row = $results->fetchObject() ) {
79 $matches[] = IntVal( $row->page_id
);
82 # Search is not guaranteed to return results in a certain order;
83 # sort them numerically so we will compare simply that we received
84 # the expected matches.
89 function testTextSearch() {
90 $this->assertFalse( is_null( $this->db
), "Can't find a database to test with." );
91 if( !is_null( $this->db
) ) {
94 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
95 "Plain search failed" );
99 function testTextPowerSearch() {
100 $this->assertFalse( is_null( $this->db
), "Can't find a database to test with." );
101 if( !is_null( $this->db
) ) {
102 $this->search
->setNamespaces( array( 0, 1, 4 ) );
105 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
106 "Power search failed" );
110 function testTitleSearch() {
111 $this->assertFalse( is_null( $this->db
), "Can't find a database to test with." );
112 if( !is_null( $this->db
) ) {
115 $this->fetchIds( $this->search
->searchTitle( 'smithee' ) ),
116 "Title search failed" );
120 function testTextTitlePowerSearch() {
121 $this->assertFalse( is_null( $this->db
), "Can't find a database to test with." );
122 if( !is_null( $this->db
) ) {
123 $this->search
->setNamespaces( array( 0, 1, 4 ) );
126 $this->fetchIds( $this->search
->searchTitle( 'smithee' ) ),
127 "Title power search failed" );