forked from ding2/ting_search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ting_search.test
231 lines (211 loc) · 8.2 KB
/
ting_search.test
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
class TingSearchTestCase extends DrupalWebTestCase {
static function getInfo() {
return array(
'name' => 'Ting search',
'description' => 'Check if we got any searchresults back from the well',
'group' => 'Ding! - Ting search',
);
}
public function setUp() {
$this->profile = 'minimal';
parent::setUp('ting', 'ding_entity', 'search', 'ting_search', 'nanosoap');
variable_set('ting_agency', '100200');
variable_set('ting_search_url', 'http://opensearch.addi.dk/next_2.0/');
variable_set('ting_scan_url', 'http://openscan.addi.dk/1.5/');
variable_set('ting_spell_url', 'http://openspell.addi.dk/1.2/');
variable_set('ting_recommendation_url', 'http://openadhl.addi.dk/1.1/');
variable_set('search_active_modules', array('ting_search' => 'ting_search'));
variable_set('ting_search_profile', 'opac');
// Default settings for teaser viewmode hides all the fields. We unset
// custom settings here, instead of trying to configure the viewmode.
variable_set('field_bundle_settings', array(
'ting_collection' => array(
'ting_collection' => array(
'view_modes' => array(
'full' => array(
'custom_settings' => FALSE,
),
'teaser' => array(
'custom_settings' => FALSE,
),
'search_result' => array(
'custom_settings' => FALSE,
),
),
'extra_fields' => array(
'form' => array(
),
'display' => array(
),
),
),
),
'ting_object' => array(
'ting_object' => array(
'view_modes' => array(
'full' => array(
'custom_settings' => FALSE,
),
'teaser' => array(
'custom_settings' => FALSE,
),
'search_result' => array(
'custom_settings' => FALSE,
),
),
'extra_fields' => array(
'form' => array(
),
'display' => array(
),
),
),
),
));
variable_set('search_default_module', 'ting_search');
// enable search_block_form in the bartik theme (which the test will run
// against).
db_update('block')
->fields(array('status' => 1, 'region' => 'content'))
->condition('module', 'search')
->condition('delta', 'form')
->condition('theme', 'bartik')
->execute();
menu_rebuild();
$this->web_user = $this->drupalCreateUser(array('administer search', 'administer blocks', 'search content'));
$this->drupalLogin($this->web_user);
}
public function testTingSearch() {
// Check if search module is installed
$exists = module_exists('search');
$this->assertTrue($exists, 'Search is enabled');
// Check if ding_facetbrowser module is installed
$exists = module_exists('ting_search');
$this->assertTrue($exists, 'Ting Search is enabled');
$this->drupalGet('search/ting/jussi adler olsen journal 64');
$this->assertFieldByXPath("//li[@class='search-result']/h3[@class='title']/a", 'Journal 64', 'We have a search result title = "Journal 64".');
$this->assertFieldByXPath("//li[@class='search-result']//div[contains(@class, 'field-type-ting-author')]//a[@class='author']", "Jussi Adler-Olsen", 'We have a By-line = "Jussi Adler-Olsen".');
$this->assertFieldByXPath("//li[@class='search-result']//div[contains(@class, 'field-type-ting-abstract')]//div[contains(@class, 'field-item')]", 'Krimi. Carl Mørck, leder af politiets afdeling Q, får hænderne fulde, da han efterforsker en sag om fem menneskers forsvinden i 1987. Sagen fører tilbage til kvindeanstalten på Sprogø, der virkede fra 1923-1961, og datidens racehygiejne og pludselig bliver Carl Mørck og hans kolleger udsat for mordforsøg, da sagen antager politiske dimensioner', 'We have a teaser text = "Krimi. Carl Mørck, leder af politiets afdeling Q, får hænderne fulde"');
}
public function testTingExtended() {
$this->drupalGet('search/ting/water AND (dc.title=chemistry)');
$this->assertFieldByName("search_block_form", 'water', "Search field contains 'water'.");
// advanced search is disabled in ting_search.module - so assert below is
// also disabled.
//$this->assertFieldById("edit-title", 'chemistry', "Title field contains 'chemestry'.");
$this->drupalGet('search/node/water AND (dc.title=chemistry)');
$this->assertFieldByName("search_block_form", 'water chemistry', "Search field contains 'water chemistry'.");
// advanced search is disabled in ting_search.module - so assert below is
// also disabled.
//$this->assertFieldById("edit-title", '', "The title field is empty.");
}
}
class TingSearchParsingTestCase extends DrupalUnitTestCase {
static function getInfo() {
return array(
'name' => 'Ting search parsing',
'description' => 'Test search query string parsing.',
'group' => 'Ding! - Ting search',
);
}
function testParsing() {
drupal_load('module', 'ting_search');
$testCases = array(
array(
'string' => 'water AND (dc.title=chemestry)',
'keys' => array('dc.title'),
'expected' => array(
'q' => 'water',
'dc.title' => 'chemestry',
),
),
/* array( */
/* 'string' => 'water and one=one aNd (dc.title=test) and two="two double" And three=' . "'three 3'", */
/* 'keys' => array('one', 'two', 'three'), */
/* 'expected' => array( */
/* 'q' => 'water aNd (dc.title=test)', */
/* 'one' => 'one', */
/* 'two' => '"two double"', */
/* 'three' => "'three 3'", */
/* ), */
/* ), */
array(
'string' => 'harry AND (dc.creator=rowling AND dc.title="flammernes pokal")',
'keys' => array('dc.creator', 'dc.title'),
'expected' => array(
'q' => 'harry',
'dc.creator' => 'rowling',
'dc.title' => 'flammernes pokal',
),
),
array(
'string' => '(dc.creator=rowling)',
'keys' => array('dc.creator', 'dc.title'),
'expected' => array(
'q' => '',
'dc.creator' => 'rowling',
),
),
array(
'string' => '(dc.creator=rowling AND dc.title="flammernes pokal")',
'keys' => array('dc.creator', 'dc.title'),
'expected' => array(
'q' => '',
'dc.creator' => 'rowling',
'dc.title' => 'flammernes pokal',
),
),
);
foreach ($testCases as $test) {
drupal_static_reset('ting_search_extract_indexes');
$res = ting_search_extract_keys($test['string'], $test['keys']);
$this->assertEqual($res, $test['expected'], 'Could parse: ' . $test['string']);
if ($res != $test['expected']) {
debug($res);
}
}
}
function testQuoting() {
drupal_load('module', 'ting_search');
$testCases = array(
array(
'string' => 'anders and',
'expected' => 'anders "and"',
),
array(
'string' => 'anders aNd',
'expected' => 'anders "aNd"',
),
array(
// This might seem like a pretty simple case, but this is actually a
// regression test for an issue not caught by the more advanced tests.
'string' => 'anders AND',
'expected' => 'anders AND',
),
array(
'string' => 'anders and AND (dc.title=historie)',
'expected' => 'anders "and" AND (dc.title=historie)',
),
array(
'string' => 'anders AND (dc.title=historie)',
'expected' => 'anders AND (dc.title=historie)',
),
array(
'string' => '"anders and" (dc.title=historie)',
'expected' => '"anders and" (dc.title=historie)',
),
array(
'string' => '"anders \"and\"" (dc.title=historie)',
'expected' => '"anders \"and\"" (dc.title=historie)',
),
);
foreach ($testCases as $test) {
$res = _ting_search_quote($test['string']);
$this->assertEqual($res, $test['expected'], 'Properly quoted: ' . $test['string']);
if ($res != $test['expected']) {
debug($res);
}
}
}
}