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/Hooks.php' );
9 require_once( '../includes/MagicWord.php' );
10 require_once( '../languages/Language.php' );
12 require_once( '../includes/SearchEngine.php' );
15 class SearchEngine_TestCase
extends PHPUnit_TestCase
{
18 function insertSearchData() {
19 $this->db
->safeQuery( <<<END
20 INSERT INTO ! (page_id,page_namespace,page_title,page_latest)
21 VALUES (1, 0, 'Main_Page', 1),
22 (2, 1, 'Main_Page', 2),
25 (5, 0, 'Unrelated_page', 5),
26 (6, 0, 'Another_page', 6),
29 (9, 0, 'Alan_Smithee', 9),
32 , $this->db
->tableName( 'page' ) );
33 $this->db
->safeQuery( <<<END
34 INSERT INTO ! (rev_id,rev_page)
46 , $this->db
->tableName( 'revision' ) );
47 $this->db
->safeQuery( <<<END
48 INSERT INTO ! (old_id,old_text)
49 VALUES (1, 'This is a main page'),
50 (2, 'This is a talk page to the main page, see [[smithee]]'),
51 (3, 'A smithee is one who smiths. See also [[Alan Smithee]]'),
52 (4, 'This article sucks.'),
53 (5, 'Nothing in this page is about the S word.'),
54 (6, 'This page also is unrelated.'),
60 , $this->db
->tableName( 'text' ) );
61 $this->db
->safeQuery( <<<END
62 INSERT INTO ! (si_page,si_title,si_text)
63 VALUES (1, 'main page', 'this is a main page'),
64 (2, 'main page', 'this is a talk page to the main page, see smithee'),
65 (3, 'smithee', 'a smithee is one who smiths see also alan smithee'),
66 (4, 'smithee', 'this article sucks'),
67 (5, 'unrelated page', 'nothing in this page is about the s word'),
68 (6, 'another page', 'this page also is unrelated'),
69 (7, 'help', 'help me'),
70 (8, 'thppt', 'blah blah'),
71 (9, 'alan smithee', 'yum'),
72 (10, 'pages', 'are food')
74 , $this->db
->tableName( 'searchindex' ) );
77 function fetchIds( &$results ) {
79 while( $row = $results->fetchObject() ) {
80 $matches[] = intval( $row->page_id
);
83 # Search is not guaranteed to return results in a certain order;
84 # sort them numerically so we will compare simply that we received
85 # the expected matches.
90 function testTextSearch() {
91 $this->assertFalse( is_null( $this->db
), "Can't find a database to test with." );
92 if( !is_null( $this->db
) ) {
95 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
96 "Plain search failed" );
100 function testTextPowerSearch() {
101 $this->assertFalse( is_null( $this->db
), "Can't find a database to test with." );
102 if( !is_null( $this->db
) ) {
103 $this->search
->setNamespaces( array( 0, 1, 4 ) );
106 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
107 "Power search failed" );
111 function testTitleSearch() {
112 $this->assertFalse( is_null( $this->db
), "Can't find a database to test with." );
113 if( !is_null( $this->db
) ) {
116 $this->fetchIds( $this->search
->searchTitle( 'smithee' ) ),
117 "Title search failed" );
121 function testTextTitlePowerSearch() {
122 $this->assertFalse( is_null( $this->db
), "Can't find a database to test with." );
123 if( !is_null( $this->db
) ) {
124 $this->search
->setNamespaces( array( 0, 1, 4 ) );
127 $this->fetchIds( $this->search
->searchTitle( 'smithee' ) ),
128 "Title power search failed" );