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' );
13 require_once( '../includes/SearchMySQL.php' );
14 require_once( '../includes/SearchMySQL4.php' );
17 class SearchEngine_TestCase
extends PHPUnit_TestCase
{
20 function insertSearchData() {
21 $this->db
->safeQuery( <<<END
22 INSERT INTO ! (page_id,page_namespace,page_title,page_latest)
23 VALUES (1, 0, 'Main_Page', 1),
24 (2, 1, 'Main_Page', 2),
27 (5, 0, 'Unrelated_page', 5),
28 (6, 0, 'Another_page', 6),
31 (9, 0, 'Alan_Smithee', 9),
34 , $this->db
->tableName( 'page' ) );
35 $this->db
->safeQuery( <<<END
36 INSERT INTO ! (rev_id,rev_page)
48 , $this->db
->tableName( 'revision' ) );
49 $this->db
->safeQuery( <<<END
50 INSERT INTO ! (old_id,old_text)
51 VALUES (1, 'This is a main page'),
52 (2, 'This is a talk page to the main page, see [[smithee]]'),
53 (3, 'A smithee is one who smiths. See also [[Alan Smithee]]'),
54 (4, 'This article sucks.'),
55 (5, 'Nothing in this page is about the S word.'),
56 (6, 'This page also is unrelated.'),
62 , $this->db
->tableName( 'text' ) );
63 $this->db
->safeQuery( <<<END
64 INSERT INTO ! (si_page,si_title,si_text)
65 VALUES (1, 'main page', 'this is a main page'),
66 (2, 'main page', 'this is a talk page to the main page, see smithee'),
67 (3, 'smithee', 'a smithee is one who smiths see also alan smithee'),
68 (4, 'smithee', 'this article sucks'),
69 (5, 'unrelated page', 'nothing in this page is about the s word'),
70 (6, 'another page', 'this page also is unrelated'),
71 (7, 'help', 'help me'),
72 (8, 'thppt', 'blah blah'),
73 (9, 'alan smithee', 'yum'),
74 (10, 'pages', 'are food')
76 , $this->db
->tableName( 'searchindex' ) );
79 function fetchIds( &$results ) {
81 while( $row = $results->fetchObject() ) {
82 $matches[] = intval( $row->page_id
);
85 # Search is not guaranteed to return results in a certain order;
86 # sort them numerically so we will compare simply that we received
87 # the expected matches.
92 function testTextSearch() {
93 $this->assertFalse( is_null( $this->db
), "Can't find a database to test with." );
94 if( !is_null( $this->db
) ) {
97 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
98 "Plain search failed" );
102 function testTextPowerSearch() {
103 $this->assertFalse( is_null( $this->db
), "Can't find a database to test with." );
104 if( !is_null( $this->db
) ) {
105 $this->search
->setNamespaces( array( 0, 1, 4 ) );
108 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
109 "Power search failed" );
113 function testTitleSearch() {
114 $this->assertFalse( is_null( $this->db
), "Can't find a database to test with." );
115 if( !is_null( $this->db
) ) {
118 $this->fetchIds( $this->search
->searchTitle( 'smithee' ) ),
119 "Title search failed" );
123 function testTextTitlePowerSearch() {
124 $this->assertFalse( is_null( $this->db
), "Can't find a database to test with." );
125 if( !is_null( $this->db
) ) {
126 $this->search
->setNamespaces( array( 0, 1, 4 ) );
129 $this->fetchIds( $this->search
->searchTitle( 'smithee' ) ),
130 "Title power search failed" );