4 * This class is not directly tested. Instead it is extended by SearchDbTest.
8 class SearchEngineTest
extends MediaWikiTestCase
{
9 protected $search, $pageList;
12 unset( $this->search
);
16 * Checks for database type & version.
17 * Will skip current test if DB does not support search.
21 // Search tests require MySQL or SQLite with FTS
22 # Get database type and version
23 $dbType = $this->db
->getType();
26 ||
( $dbType === 'sqlite' && $this->db
->getFulltextSearchModule() == 'FTS3' );
29 $this->markTestSkipped( "MySQL or SQLite with FTS3 only" );
32 $searchType = $this->db
->getSearchEngine();
33 $this->search
= new $searchType( $this->db
);
36 function pageExists( $title ) {
40 function addDBData() {
41 if ( $this->pageExists( 'Not_Main_Page' ) ) {
44 $this->insertPage( "Not_Main_Page", "This is not a main page", 0 );
45 $this->insertPage( 'Talk:Not_Main_Page', 'This is not a talk page to the main page, see [[smithee]]', 1 );
46 $this->insertPage( 'Smithee', 'A smithee is one who smiths. See also [[Alan Smithee]]', 0 );
47 $this->insertPage( 'Talk:Smithee', 'This article sucks.', 1 );
48 $this->insertPage( 'Unrelated_page', 'Nothing in this page is about the S word.', 0 );
49 $this->insertPage( 'Another_page', 'This page also is unrelated.', 0 );
50 $this->insertPage( 'Help:Help', 'Help me!', 4 );
51 $this->insertPage( 'Thppt', 'Blah blah', 0 );
52 $this->insertPage( 'Alan_Smithee', 'yum', 0 );
53 $this->insertPage( 'Pages', 'are\'food', 0 );
54 $this->insertPage( 'HalfOneUp', 'AZ', 0 );
55 $this->insertPage( 'FullOneUp', 'AZ', 0 );
56 $this->insertPage( 'HalfTwoLow', 'az', 0 );
57 $this->insertPage( 'FullTwoLow', 'az', 0 );
58 $this->insertPage( 'HalfNumbers', '1234567890', 0 );
59 $this->insertPage( 'FullNumbers', '1234567890', 0 );
60 $this->insertPage( 'DomainName', 'example.com', 0 );
63 function fetchIds( $results ) {
64 $this->assertTrue( is_object( $results ) );
67 $row = $results->next();
69 $matches[] = $row->getTitle()->getPrefixedText();
70 $row = $results->next();
73 # Search is not guaranteed to return results in a certain order;
74 # sort them numerically so we will compare simply that we received
75 # the expected matches.
83 * @param $pageName String: page name
84 * @param $text String: page's content
85 * @param $n Integer: unused
87 function insertPage( $pageName, $text, $ns ) {
88 $title = Title
::newFromText( $pageName );
90 $user = User
::newFromName( 'WikiSysop' );
91 $comment = 'Search Test';
93 // avoid memory leak...?
94 LinkCache
::singleton()->clear();
96 $page = WikiPage
::factory( $title );
97 $page->doEdit( $text, $comment, 0, false, $user );
99 $this->pageList
[] = array( $title, $page->getId() );
104 function testFullWidth() {
106 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
107 $this->fetchIds( $this->search
->searchText( 'AZ' ) ),
108 "Search for normalized from Half-width Upper" );
110 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
111 $this->fetchIds( $this->search
->searchText( 'az' ) ),
112 "Search for normalized from Half-width Lower" );
114 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
115 $this->fetchIds( $this->search
->searchText( 'AZ' ) ),
116 "Search for normalized from Full-width Upper" );
118 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
119 $this->fetchIds( $this->search
->searchText( 'az' ) ),
120 "Search for normalized from Full-width Lower" );
123 function testTextSearch() {
126 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
127 "Plain search failed" );
130 function testTextPowerSearch() {
131 $this->search
->setNamespaces( array( 0, 1, 4 ) );
135 'Talk:Not Main Page',
137 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
138 "Power search failed" );
141 function testTitleSearch() {
147 $this->fetchIds( $this->search
->searchTitle( 'smithee' ) ),
148 "Title search failed" );
151 function testTextTitlePowerSearch() {
152 $this->search
->setNamespaces( array( 0, 1, 4 ) );
159 $this->fetchIds( $this->search
->searchTitle( 'smithee' ) ),
160 "Title power search failed" );