6 class SearchEngineTest
extends MediaWikiTestSetup
{
7 var $db, $search, $pageList;
9 function pageExists( $title ) {
13 function insertSearchData() {
14 if ( $this->pageExists( 'Not_Main_Page' ) ) {
17 $this->insertPage( "Not_Main_Page", "This is not a main page", 0 );
18 $this->insertPage( 'Talk:Not_Main_Page', 'This is not a talk page to the main page, see [[smithee]]', 1 );
19 $this->insertPage( 'Smithee', 'A smithee is one who smiths. See also [[Alan Smithee]]', 0 );
20 $this->insertPage( 'Talk:Smithee', 'This article sucks.', 1 );
21 $this->insertPage( 'Unrelated_page', 'Nothing in this page is about the S word.', 0 );
22 $this->insertPage( 'Another_page', 'This page also is unrelated.', 0 );
23 $this->insertPage( 'Help:Help', 'Help me!', 4 );
24 $this->insertPage( 'Thppt', 'Blah blah', 0 );
25 $this->insertPage( 'Alan_Smithee', 'yum', 0 );
26 $this->insertPage( 'Pages', 'are\'food', 0 );
27 $this->insertPage( 'HalfOneUp', 'AZ', 0 );
28 $this->insertPage( 'FullOneUp', 'AZ', 0 );
29 $this->insertPage( 'HalfTwoLow', 'az', 0 );
30 $this->insertPage( 'FullTwoLow', 'az', 0 );
31 $this->insertPage( 'HalfNumbers', '1234567890', 0 );
32 $this->insertPage( 'FullNumbers', '1234567890', 0 );
33 $this->insertPage( 'DomainName', 'example.com', 0 );
36 function removeSearchData() {
38 while ( count( $this->pageList
) ) {
39 list( $title, $id ) = array_pop( $this->pageList
);
40 $article = new Article( $title, $id );
41 $article->doDeleteArticle( "Search Test" );
45 function fetchIds( $results ) {
46 $this->assertTrue( is_object( $results ) );
48 if ( $this->db
->getType() !== 'mysql' && $this->db
->getType() !== 'sqlite' ) {
49 $this->markTestSkipped( "MySQL or SQLite only" );
52 while ( $row = $results->next() ) {
53 $matches[] = $row->getTitle()->getPrefixedText();
56 # Search is not guaranteed to return results in a certain order;
57 # sort them numerically so we will compare simply that we received
58 # the expected matches.
63 // Modified version of WikiRevision::importOldRevision()
64 function insertPage( $pageName, $text, $ns ) {
66 $title = Title
::newFromText( $pageName );
69 $userText = 'WikiSysop';
70 $comment = 'Search Test';
72 // avoid memory leak...?
73 $linkCache = LinkCache
::singleton();
76 $article = new Article( $title );
77 $pageId = $article->getId();
80 # must create the page...
81 $pageId = $article->insertOn( $dbw );
85 # FIXME: Use original rev_id optionally (better for backups)
87 $revision = new Revision( array(
90 'comment' => $comment,
92 'user_text' => $userText,
94 'minor_edit' => false,
96 $revId = $revision->insertOn( $dbw );
97 $changed = $article->updateIfNewerOn( $dbw, $revision );
99 $GLOBALS['wgTitle'] = $title;
101 Article
::onArticleCreate( $title );
102 $article->createUpdates( $revision );
103 } elseif ( $changed ) {
104 Article
::onArticleEdit( $title );
105 $article->editUpdates(
106 $text, $comment, false, 0, $revId );
109 $su = new SearchUpdate( $article->getId(), $pageName, $text );
112 $this->pageList
[] = array( $title, $article->getId() );
117 function testFullWidth() {
119 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
120 $this->fetchIds( $this->search
->searchText( 'AZ' ) ),
121 "Search for normalized from Half-width Upper" );
123 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
124 $this->fetchIds( $this->search
->searchText( 'az' ) ),
125 "Search for normalized from Half-width Lower" );
127 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
128 $this->fetchIds( $this->search
->searchText( 'AZ' ) ),
129 "Search for normalized from Full-width Upper" );
131 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
132 $this->fetchIds( $this->search
->searchText( 'az' ) ),
133 "Search for normalized from Full-width Lower" );
136 function testTextSearch() {
139 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
140 "Plain search failed" );
143 function testTextPowerSearch() {
144 $this->search
->setNamespaces( array( 0, 1, 4 ) );
148 'Talk:Not Main Page',
150 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
151 "Power search failed" );
154 function testTitleSearch() {
160 $this->fetchIds( $this->search
->searchTitle( 'smithee' ) ),
161 "Title search failed" );
164 function testTextTitlePowerSearch() {
165 $this->search
->setNamespaces( array( 0, 1, 4 ) );
172 $this->fetchIds( $this->search
->searchTitle( 'smithee' ) ),
173 "Title power search failed" );