1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
<?php
/**
* @group Search
* @group Database
*
* @covers SearchEngine<extended>
* @note Coverage will only ever show one of on of the Search* classes
*/
class SearchEngineTest extends MediaWikiLangTestCase {
/**
* @var SearchEngine
*/
protected $search;
/**
* Checks for database type & version.
* Will skip current test if DB does not support search.
*/
protected function setUp() {
parent::setUp();
// Search tests require MySQL or SQLite with FTS
$dbType = $this->db->getType();
$dbSupported = ( $dbType === 'mysql' )
|| ( $dbType === 'sqlite' && $this->db->getFulltextSearchModule() == 'FTS3' );
if ( !$dbSupported ) {
$this->markTestSkipped( "MySQL or SQLite with FTS3 only" );
}
$searchType = $this->db->getSearchEngine();
$this->setMwGlobals( array(
'wgSearchType' => $searchType
) );
$this->search = new $searchType( $this->db );
}
protected function tearDown() {
unset( $this->search );
parent::tearDown();
}
public function addDBData() {
if ( !$this->isWikitextNS( NS_MAIN ) ) {
// @todo cover the case of non-wikitext content in the main namespace
return;
}
$this->insertPage( 'Not_Main_Page', 'This is not a main page' );
$this->insertPage(
'Talk:Not_Main_Page',
'This is not a talk page to the main page, see [[smithee]]'
);
$this->insertPage( 'Smithee', 'A smithee is one who smiths. See also [[Alan Smithee]]' );
$this->insertPage( 'Talk:Smithee', 'This article sucks.' );
$this->insertPage( 'Unrelated_page', 'Nothing in this page is about the S word.' );
$this->insertPage( 'Another_page', 'This page also is unrelated.' );
$this->insertPage( 'Help:Help', 'Help me!' );
$this->insertPage( 'Thppt', 'Blah blah' );
$this->insertPage( 'Alan_Smithee', 'yum' );
$this->insertPage( 'Pages', 'are\'food' );
$this->insertPage( 'HalfOneUp', 'AZ' );
$this->insertPage( 'FullOneUp', 'AZ' );
$this->insertPage( 'HalfTwoLow', 'az' );
$this->insertPage( 'FullTwoLow', 'az' );
$this->insertPage( 'HalfNumbers', '1234567890' );
$this->insertPage( 'FullNumbers', '1234567890' );
$this->insertPage( 'DomainName', 'example.com' );
}
protected function fetchIds( $results ) {
if ( !$this->isWikitextNS( NS_MAIN ) ) {
$this->markTestIncomplete( __CLASS__ . " does no yet support non-wikitext content "
. "in the main namespace" );
}
$this->assertTrue( is_object( $results ) );
$matches = array();
$row = $results->next();
while ( $row ) {
$matches[] = $row->getTitle()->getPrefixedText();
$row = $results->next();
}
$results->free();
# Search is not guaranteed to return results in a certain order;
# sort them numerically so we will compare simply that we received
# the expected matches.
sort( $matches );
return $matches;
}
public function testFullWidth() {
$this->assertEquals(
array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
$this->fetchIds( $this->search->searchText( 'AZ' ) ),
"Search for normalized from Half-width Upper" );
$this->assertEquals(
array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
$this->fetchIds( $this->search->searchText( 'az' ) ),
"Search for normalized from Half-width Lower" );
$this->assertEquals(
array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
$this->fetchIds( $this->search->searchText( 'AZ' ) ),
"Search for normalized from Full-width Upper" );
$this->assertEquals(
array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
$this->fetchIds( $this->search->searchText( 'az' ) ),
"Search for normalized from Full-width Lower" );
}
public function testTextSearch() {
$this->assertEquals(
array( 'Smithee' ),
$this->fetchIds( $this->search->searchText( 'smithee' ) ),
"Plain search failed" );
}
public function testTextPowerSearch() {
$this->search->setNamespaces( array( 0, 1, 4 ) );
$this->assertEquals(
array(
'Smithee',
'Talk:Not Main Page',
),
$this->fetchIds( $this->search->searchText( 'smithee' ) ),
"Power search failed" );
}
public function testTitleSearch() {
$this->assertEquals(
array(
'Alan Smithee',
'Smithee',
),
$this->fetchIds( $this->search->searchTitle( 'smithee' ) ),
"Title search failed" );
}
public function testTextTitlePowerSearch() {
$this->search->setNamespaces( array( 0, 1, 4 ) );
$this->assertEquals(
array(
'Alan Smithee',
'Smithee',
'Talk:Smithee',
),
$this->fetchIds( $this->search->searchTitle( 'smithee' ) ),
"Title power search failed" );
}
}
|