3 require_once( 'MediaWiki_Setup.php' );
8 class SearchEngineTest
extends MediaWiki_Setup
{
9 var $db, $search, $pageList;
11 function pageExists( $title ) {
15 function insertSearchData() {
16 if( $this->pageExists( 'Not_Main_Page' ) ) {
19 $this->insertPage("Not_Main_Page", "This is not a main page", 0);
20 $this->insertPage('Talk:Not_Main_Page', 'This is not a talk page to the main page, see [[smithee]]', 1);
21 $this->insertPage('Smithee', 'A smithee is one who smiths. See also [[Alan Smithee]]', 0);
22 $this->insertPage('Talk:Smithee', 'This article sucks.', 1);
23 $this->insertPage('Unrelated_page', 'Nothing in this page is about the S word.', 0);
24 $this->insertPage('Another_page', 'This page also is unrelated.', 0);
25 $this->insertPage('Help:Help', 'Help me!', 4);
26 $this->insertPage('Thppt', 'Blah blah', 0);
27 $this->insertPage('Alan_Smithee', 'yum', 0);
28 $this->insertPage('Pages', 'are\'food', 0);
29 $this->insertPage('HalfOneUp', 'AZ', 0);
30 $this->insertPage('FullOneUp', 'AZ', 0);
31 $this->insertPage('HalfTwoLow', 'az', 0);
32 $this->insertPage('FullTwoLow', 'az', 0);
33 $this->insertPage('HalfNumbers', '1234567890', 0);
34 $this->insertPage('FullNumbers', '1234567890', 0);
35 $this->insertPage('DomainName', 'example.com', 0);
38 function removeSearchData() {
40 while( count($this->pageList
) ) {
41 list( $title, $id ) = array_pop( $this->pageList
);
42 $article = new Article( $title, $id );
43 $article->doDeleteArticle("Search Test");
47 function fetchIds( $results ) {
49 while( $row = $results->next() ) {
50 $matches[] = $row->getTitle()->getPrefixedText();
53 # Search is not guaranteed to return results in a certain order;
54 # sort them numerically so we will compare simply that we received
55 # the expected matches.
60 // Modified version of WikiRevision::importOldRevision()
61 function insertPage( $pageName, $text, $ns ) {
63 $title = Title
::newFromText( $pageName );
66 $userText = 'WikiSysop';
67 $comment = 'Search Test';
69 // avoid memory leak...?
70 $linkCache = LinkCache
::singleton();
73 $article = new Article( $title );
74 $pageId = $article->getId();
77 # must create the page...
78 $pageId = $article->insertOn( $dbw );
82 # FIXME: Use original rev_id optionally (better for backups)
84 $revision = new Revision( array(
87 'comment' => $comment,
89 'user_text' => $userText,
91 'minor_edit' => false,
93 $revId = $revision->insertOn( $dbw );
94 $changed = $article->updateIfNewerOn( $dbw, $revision );
96 $GLOBALS['wgTitle'] = $title;
98 Article
::onArticleCreate( $title );
99 $article->createUpdates( $revision );
100 } elseif( $changed ) {
101 Article
::onArticleEdit( $title );
102 $article->editUpdates(
103 $text, $comment, false, 0, $revId );
106 $su = new SearchUpdate($article->getId(), $pageName, $text);
109 $this->pageList
[] = array( $title, $article->getId() );
114 function testFullWidth() {
116 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
117 $this->fetchIds( $this->search
->searchText( 'AZ' ) ),
118 "Search for normalized from Half-width Upper" );
120 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
121 $this->fetchIds( $this->search
->searchText( 'az' ) ),
122 "Search for normalized from Half-width Lower" );
124 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
125 $this->fetchIds( $this->search
->searchText( 'AZ' ) ),
126 "Search for normalized from Full-width Upper" );
128 array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
129 $this->fetchIds( $this->search
->searchText( 'az' ) ),
130 "Search for normalized from Full-width Lower" );
133 function testTextSearch() {
136 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
137 "Plain search failed" );
140 function testTextPowerSearch() {
141 $this->search
->setNamespaces( array( 0, 1, 4 ) );
145 'Talk:Not Main Page',
147 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
148 "Power search failed" );
151 function testTitleSearch() {
157 $this->fetchIds( $this->search
->searchTitle( 'smithee' ) ),
158 "Title search failed" );
161 function testTextTitlePowerSearch() {
162 $this->search
->setNamespaces( array( 0, 1, 4 ) );
169 $this->fetchIds( $this->search
->searchTitle( 'smithee' ) ),
170 "Title power search failed" );