3 require_once 'MediaWiki_TestCase.php';
9 class SearchEngineTest
extends MediaWiki_TestCase
{
12 function insertSearchData() {
13 $this->db
->safeQuery( <<<SQL
14 INSERT INTO ! (page_id,page_namespace,page_title,page_latest)
15 VALUES (1, 0, 'Main_Page', 1),
16 (2, 1, 'Main_Page', 2),
19 (5, 0, 'Unrelated_page', 5),
20 (6, 0, 'Another_page', 6),
23 (9, 0, 'Alan_Smithee', 9),
26 , $this->db
->tableName( 'page' ) );
27 $this->db
->safeQuery( <<<SQL
28 INSERT INTO ! (rev_id,rev_page)
40 , $this->db
->tableName( 'revision' ) );
41 $this->db
->safeQuery( <<<SQL
42 INSERT INTO ! (old_id,old_text)
43 VALUES (1, 'This is a main page'),
44 (2, 'This is a talk page to the main page, see [[smithee]]'),
45 (3, 'A smithee is one who smiths. See also [[Alan Smithee]]'),
46 (4, 'This article sucks.'),
47 (5, 'Nothing in this page is about the S word.'),
48 (6, 'This page also is unrelated.'),
54 , $this->db
->tableName( 'text' ) );
55 $this->db
->safeQuery( <<<SQL
56 INSERT INTO ! (si_page,si_title,si_text)
57 VALUES (1, 'main page', 'this is a main page'),
58 (2, 'main page', 'this is a talk page to the main page, see smithee'),
59 (3, 'smithee', 'a smithee is one who smiths see also alan smithee'),
60 (4, 'smithee', 'this article sucks'),
61 (5, 'unrelated page', 'nothing in this page is about the s word'),
62 (6, 'another page', 'this page also is unrelated'),
63 (7, 'help', 'help me'),
64 (8, 'thppt', 'blah blah'),
65 (9, 'alan smithee', 'yum'),
66 (10, 'pages', 'are food')
68 , $this->db
->tableName( 'searchindex' ) );
71 function fetchIds( $results ) {
73 while( $row = $results->next() ) {
74 $matches[] = $row->getTitle()->getPrefixedText();
77 # Search is not guaranteed to return results in a certain order;
78 # sort them numerically so we will compare simply that we received
79 # the expected matches.
84 function testTextSearch() {
85 $this->assertFalse( is_null( $this->db
), "Can't find a database to test with." );
86 if( !is_null( $this->db
) ) {
89 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
90 "Plain search failed" );
94 function testTextPowerSearch() {
95 $this->assertFalse( is_null( $this->db
), "Can't find a database to test with." );
96 if( !is_null( $this->db
) ) {
97 $this->search
->setNamespaces( array( 0, 1, 4 ) );
103 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
104 "Power search failed" );
108 function testTitleSearch() {
109 $this->assertFalse( is_null( $this->db
), "Can't find a database to test with." );
110 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 ) );
131 $this->fetchIds( $this->search
->searchTitle( 'smithee' ) ),
132 "Title power search failed" );