3 require_once dirname(dirname(dirname(__FILE__
))). '/bootstrap.php';
6 * This class is not directly tested. Instead it is extended by SearchDbTest.
11 class SearchEngineTest
extends MediaWikiTestSetup
{
12 var $db, $search, $pageList;
15 * Checks for database type & version.
16 * Will skip current test if DB does not support search.
19 // Search tests require MySQL or SQLite with FTS
20 # Get database type and version
21 $dbType = $this->db
->getType();
24 ||
( $dbType === 'sqlite' && $this->db
->getFulltextSearchModule() == 'FTS3' );
27 $this->markTestSkipped( "MySQL or SQLite with FTS3 only" );
31 function pageExists( $title ) {
35 function insertSearchData() {
36 if ( $this->pageExists( 'Not_Main_Page' ) ) {
39 $this->insertPage( "Not_Main_Page", "This is not a main page", 0 );
40 $this->insertPage( 'Talk:Not_Main_Page', 'This is not a talk page to the main page, see [[smithee]]', 1 );
41 $this->insertPage( 'Smithee', 'A smithee is one who smiths. See also [[Alan Smithee]]', 0 );
42 $this->insertPage( 'Talk:Smithee', 'This article sucks.', 1 );
43 $this->insertPage( 'Unrelated_page', 'Nothing in this page is about the S word.', 0 );
44 $this->insertPage( 'Another_page', 'This page also is unrelated.', 0 );
45 $this->insertPage( 'Help:Help', 'Help me!', 4 );
46 $this->insertPage( 'Thppt', 'Blah blah', 0 );
47 $this->insertPage( 'Alan_Smithee', 'yum', 0 );
48 $this->insertPage( 'Pages', 'are\'food', 0 );
49 $this->insertPage( 'HalfOneUp', 'AZ', 0 );
50 $this->insertPage( 'FullOneUp', 'AZ', 0 );
51 $this->insertPage( 'HalfTwoLow', 'az', 0 );
52 $this->insertPage( 'FullTwoLow', 'az', 0 );
53 $this->insertPage( 'HalfNumbers', '1234567890', 0 );
54 $this->insertPage( 'FullNumbers', '1234567890', 0 );
55 $this->insertPage( 'DomainName', 'example.com', 0 );
58 function removeSearchData() {
60 /*while ( count( $this->pageList ) ) {
61 list( $title, $id ) = array_pop( $this->pageList );
62 $article = new Article( $title, $id );
63 $article->doDeleteArticle( "Search Test" );
67 function fetchIds( $results ) {
68 $this->assertTrue( is_object( $results ) );
71 while ( $row = $results->next() ) {
72 $matches[] = $row->getTitle()->getPrefixedText();
75 # Search is not guaranteed to return results in a certain order;
76 # sort them numerically so we will compare simply that we received
77 # the expected matches.
82 // Modified version of WikiRevision::importOldRevision()
83 function insertPage( $pageName, $text, $ns ) {
85 $title = Title
::newFromText( $pageName );
88 $userText = 'WikiSysop';
89 $comment = 'Search Test';
91 // avoid memory leak...?
92 $linkCache = LinkCache
::singleton();
95 $article = new Article( $title );
96 $pageId = $article->getId();
99 # must create the page...
100 $pageId = $article->insertOn( $dbw );
104 # FIXME: Use original rev_id optionally (better for backups)
106 $revision = new Revision( array(
109 'comment' => $comment,
111 'user_text' => $userText,
113 'minor_edit' => false,
115 $revId = $revision->insertOn( $dbw );
116 $changed = $article->updateIfNewerOn( $dbw, $revision );
118 $GLOBALS['wgTitle'] = $title;
120 Article
::onArticleCreate( $title );
121 $article->createUpdates( $revision );
122 } elseif ( $changed ) {
123 Article
::onArticleEdit( $title );
124 $article->editUpdates(
125 $text, $comment, false, 0, $revId );
128 $su = new SearchUpdate( $article->getId(), $pageName, $text );
131 $this->pageList
[] = array( $title, $article->getId() );
136 function testFullWidth() {
138 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
139 $this->fetchIds( $this->search
->searchText( 'AZ' ) ),
140 "Search for normalized from Half-width Upper" );
142 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
143 $this->fetchIds( $this->search
->searchText( 'az' ) ),
144 "Search for normalized from Half-width Lower" );
146 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
147 $this->fetchIds( $this->search
->searchText( 'AZ' ) ),
148 "Search for normalized from Full-width Upper" );
150 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
151 $this->fetchIds( $this->search
->searchText( 'az' ) ),
152 "Search for normalized from Full-width Lower" );
155 function testTextSearch() {
158 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
159 "Plain search failed" );
162 function testTextPowerSearch() {
163 $this->search
->setNamespaces( array( 0, 1, 4 ) );
167 'Talk:Not Main Page',
169 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
170 "Power search failed" );
173 function testTitleSearch() {
179 $this->fetchIds( $this->search
->searchTitle( 'smithee' ) ),
180 "Title search failed" );
183 function testTextTitlePowerSearch() {
184 $this->search
->setNamespaces( array( 0, 1, 4 ) );
191 $this->fetchIds( $this->search
->searchTitle( 'smithee' ) ),
192 "Title power search failed" );