3 require_once 'MediaWiki_TestCase.php';
6 class SearchEngineTest
extends MediaWiki_TestCase
{
9 function insertSearchData() {
10 $this->db
->safeQuery( <<<END
11 INSERT INTO ! (page_id,page_namespace,page_title,page_latest)
12 VALUES (1, 0, 'Main_Page', 1),
13 (2, 1, 'Main_Page', 2),
16 (5, 0, 'Unrelated_page', 5),
17 (6, 0, 'Another_page', 6),
20 (9, 0, 'Alan_Smithee', 9),
23 , $this->db
->tableName( 'page' ) );
24 $this->db
->safeQuery( <<<END
25 INSERT INTO ! (rev_id,rev_page)
37 , $this->db
->tableName( 'revision' ) );
38 $this->db
->safeQuery( <<<END
39 INSERT INTO ! (old_id,old_text)
40 VALUES (1, 'This is a main page'),
41 (2, 'This is a talk page to the main page, see [[smithee]]'),
42 (3, 'A smithee is one who smiths. See also [[Alan Smithee]]'),
43 (4, 'This article sucks.'),
44 (5, 'Nothing in this page is about the S word.'),
45 (6, 'This page also is unrelated.'),
51 , $this->db
->tableName( 'text' ) );
52 $this->db
->safeQuery( <<<END
53 INSERT INTO ! (si_page,si_title,si_text)
54 VALUES (1, 'main page', 'this is a main page'),
55 (2, 'main page', 'this is a talk page to the main page, see smithee'),
56 (3, 'smithee', 'a smithee is one who smiths see also alan smithee'),
57 (4, 'smithee', 'this article sucks'),
58 (5, 'unrelated page', 'nothing in this page is about the s word'),
59 (6, 'another page', 'this page also is unrelated'),
60 (7, 'help', 'help me'),
61 (8, 'thppt', 'blah blah'),
62 (9, 'alan smithee', 'yum'),
63 (10, 'pages', 'are food')
65 , $this->db
->tableName( 'searchindex' ) );
68 function fetchIds( &$results ) {
70 while( $row = $results->next() ) {
71 $matches[] = $row->getTitle()->getPrefixedText();
74 # Search is not guaranteed to return results in a certain order;
75 # sort them numerically so we will compare simply that we received
76 # the expected matches.
81 function testTextSearch() {
82 $this->assertFalse( is_null( $this->db
), "Can't find a database to test with." );
83 if( !is_null( $this->db
) ) {
86 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
87 "Plain search failed" );
91 function testTextPowerSearch() {
92 $this->assertFalse( is_null( $this->db
), "Can't find a database to test with." );
93 if( !is_null( $this->db
) ) {
94 $this->search
->setNamespaces( array( 0, 1, 4 ) );
100 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
101 "Power search failed" );
105 function testTitleSearch() {
106 $this->assertFalse( is_null( $this->db
), "Can't find a database to test with." );
107 if( !is_null( $this->db
) ) {
113 $this->fetchIds( $this->search
->searchTitle( 'smithee' ) ),
114 "Title search failed" );
118 function testTextTitlePowerSearch() {
119 $this->assertFalse( is_null( $this->db
), "Can't find a database to test with." );
120 if( !is_null( $this->db
) ) {
121 $this->search
->setNamespaces( array( 0, 1, 4 ) );
128 $this->fetchIds( $this->search
->searchTitle( 'smithee' ) ),
129 "Title power search failed" );