7 * @covers SearchEngine<extended>
8 * @note Coverage will only ever show one of on of the Search* classes
10 class SearchEngineTest
extends MediaWikiLangTestCase
{
18 * Checks for database type & version.
19 * Will skip current test if DB does not support search.
21 protected function setUp() {
24 // Search tests require MySQL or SQLite with FTS
25 $dbType = $this->db
->getType();
26 $dbSupported = ( $dbType === 'mysql' )
27 ||
( $dbType === 'sqlite' && $this->db
->getFulltextSearchModule() == 'FTS3' );
29 if ( !$dbSupported ) {
30 $this->markTestSkipped( "MySQL or SQLite with FTS3 only" );
33 $searchType = $this->db
->getSearchEngine();
34 $this->setMwGlobals( array(
35 'wgSearchType' => $searchType
38 $this->search
= new $searchType( $this->db
);
41 protected function tearDown() {
42 unset( $this->search
);
47 public function addDBData() {
48 if ( !$this->isWikitextNS( NS_MAIN
) ) {
49 // @todo cover the case of non-wikitext content in the main namespace
53 $this->insertPage( 'Not_Main_Page', 'This is not a main page' );
56 'This is not a talk page to the main page, see [[smithee]]'
58 $this->insertPage( 'Smithee', 'A smithee is one who smiths. See also [[Alan Smithee]]' );
59 $this->insertPage( 'Talk:Smithee', 'This article sucks.' );
60 $this->insertPage( 'Unrelated_page', 'Nothing in this page is about the S word.' );
61 $this->insertPage( 'Another_page', 'This page also is unrelated.' );
62 $this->insertPage( 'Help:Help', 'Help me!' );
63 $this->insertPage( 'Thppt', 'Blah blah' );
64 $this->insertPage( 'Alan_Smithee', 'yum' );
65 $this->insertPage( 'Pages', 'are\'food' );
66 $this->insertPage( 'HalfOneUp', 'AZ' );
67 $this->insertPage( 'FullOneUp', 'AZ' );
68 $this->insertPage( 'HalfTwoLow', 'az' );
69 $this->insertPage( 'FullTwoLow', 'az' );
70 $this->insertPage( 'HalfNumbers', '1234567890' );
71 $this->insertPage( 'FullNumbers', '1234567890' );
72 $this->insertPage( 'DomainName', 'example.com' );
75 protected function fetchIds( $results ) {
76 if ( !$this->isWikitextNS( NS_MAIN
) ) {
77 $this->markTestIncomplete( __CLASS__
. " does no yet support non-wikitext content "
78 . "in the main namespace" );
80 $this->assertTrue( is_object( $results ) );
83 $row = $results->next();
85 $matches[] = $row->getTitle()->getPrefixedText();
86 $row = $results->next();
89 # Search is not guaranteed to return results in a certain order;
90 # sort them numerically so we will compare simply that we received
91 # the expected matches.
97 public function testFullWidth() {
99 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
100 $this->fetchIds( $this->search
->searchText( 'AZ' ) ),
101 "Search for normalized from Half-width Upper" );
103 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
104 $this->fetchIds( $this->search
->searchText( 'az' ) ),
105 "Search for normalized from Half-width Lower" );
107 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
108 $this->fetchIds( $this->search
->searchText( 'AZ' ) ),
109 "Search for normalized from Full-width Upper" );
111 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
112 $this->fetchIds( $this->search
->searchText( 'az' ) ),
113 "Search for normalized from Full-width Lower" );
116 public function testTextSearch() {
119 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
120 "Plain search failed" );
123 public function testTextPowerSearch() {
124 $this->search
->setNamespaces( array( 0, 1, 4 ) );
128 'Talk:Not Main Page',
130 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
131 "Power search failed" );
134 public function testTitleSearch() {
140 $this->fetchIds( $this->search
->searchTitle( 'smithee' ) ),
141 "Title search failed" );
144 public function testTextTitlePowerSearch() {
145 $this->search
->setNamespaces( array( 0, 1, 4 ) );
152 $this->fetchIds( $this->search
->searchTitle( 'smithee' ) ),
153 "Title power search failed" );