3 require_once dirname(dirname(dirname(__FILE__
))). '/bootstrap.php';
8 class SearchEngineTest
extends MediaWikiTestSetup
{
9 var $db, $search, $pageList;
12 * Checks for database type & version.
13 * Will skip current test if DB does not support search.
16 // Get database type and version
17 $dbType = $this->db
->getType();
19 // will skip unless mysql or sqlite with FTS
22 ||
( $dbType === 'sqlite' && $this->db
->getFulltextSearchModule() == 'FTS3' );
25 $this->markTestIgnored( "MySQL or SQLite with FTS3 only" );
29 function pageExists( $title ) {
33 function insertSearchData() {
34 if ( $this->pageExists( 'Not_Main_Page' ) ) {
37 $this->insertPage( "Not_Main_Page", "This is not a main page", 0 );
38 $this->insertPage( 'Talk:Not_Main_Page', 'This is not a talk page to the main page, see [[smithee]]', 1 );
39 $this->insertPage( 'Smithee', 'A smithee is one who smiths. See also [[Alan Smithee]]', 0 );
40 $this->insertPage( 'Talk:Smithee', 'This article sucks.', 1 );
41 $this->insertPage( 'Unrelated_page', 'Nothing in this page is about the S word.', 0 );
42 $this->insertPage( 'Another_page', 'This page also is unrelated.', 0 );
43 $this->insertPage( 'Help:Help', 'Help me!', 4 );
44 $this->insertPage( 'Thppt', 'Blah blah', 0 );
45 $this->insertPage( 'Alan_Smithee', 'yum', 0 );
46 $this->insertPage( 'Pages', 'are\'food', 0 );
47 $this->insertPage( 'HalfOneUp', 'AZ', 0 );
48 $this->insertPage( 'FullOneUp', 'AZ', 0 );
49 $this->insertPage( 'HalfTwoLow', 'az', 0 );
50 $this->insertPage( 'FullTwoLow', 'az', 0 );
51 $this->insertPage( 'HalfNumbers', '1234567890', 0 );
52 $this->insertPage( 'FullNumbers', '1234567890', 0 );
53 $this->insertPage( 'DomainName', 'example.com', 0 );
56 function removeSearchData() {
58 /*while ( count( $this->pageList ) ) {
59 list( $title, $id ) = array_pop( $this->pageList );
60 $article = new Article( $title, $id );
61 $article->doDeleteArticle( "Search Test" );
65 function fetchIds( $results ) {
66 $this->assertTrue( is_object( $results ) );
69 while ( $row = $results->next() ) {
70 $matches[] = $row->getTitle()->getPrefixedText();
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.
80 // Modified version of WikiRevision::importOldRevision()
81 function insertPage( $pageName, $text, $ns ) {
83 $title = Title
::newFromText( $pageName );
86 $userText = 'WikiSysop';
87 $comment = 'Search Test';
89 // avoid memory leak...?
90 $linkCache = LinkCache
::singleton();
93 $article = new Article( $title );
94 $pageId = $article->getId();
97 # must create the page...
98 $pageId = $article->insertOn( $dbw );
102 # FIXME: Use original rev_id optionally (better for backups)
104 $revision = new Revision( array(
107 'comment' => $comment,
109 'user_text' => $userText,
111 'minor_edit' => false,
113 $revId = $revision->insertOn( $dbw );
114 $changed = $article->updateIfNewerOn( $dbw, $revision );
116 $GLOBALS['wgTitle'] = $title;
118 Article
::onArticleCreate( $title );
119 $article->createUpdates( $revision );
120 } elseif ( $changed ) {
121 Article
::onArticleEdit( $title );
122 $article->editUpdates(
123 $text, $comment, false, 0, $revId );
126 $su = new SearchUpdate( $article->getId(), $pageName, $text );
129 $this->pageList
[] = array( $title, $article->getId() );
134 function testFullWidth() {
136 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
137 $this->fetchIds( $this->search
->searchText( 'AZ' ) ),
138 "Search for normalized from Half-width Upper" );
140 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
141 $this->fetchIds( $this->search
->searchText( 'az' ) ),
142 "Search for normalized from Half-width Lower" );
144 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
145 $this->fetchIds( $this->search
->searchText( 'AZ' ) ),
146 "Search for normalized from Full-width Upper" );
148 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
149 $this->fetchIds( $this->search
->searchText( 'az' ) ),
150 "Search for normalized from Full-width Lower" );
153 function testTextSearch() {
156 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
157 "Plain search failed" );
160 function testTextPowerSearch() {
161 $this->search
->setNamespaces( array( 0, 1, 4 ) );
165 'Talk:Not Main Page',
167 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
168 "Power search failed" );
171 function testTitleSearch() {
177 $this->fetchIds( $this->search
->searchTitle( 'smithee' ) ),
178 "Title search failed" );
181 function testTextTitlePowerSearch() {
182 $this->search
->setNamespaces( array( 0, 1, 4 ) );
189 $this->fetchIds( $this->search
->searchTitle( 'smithee' ) ),
190 "Title power search failed" );