Lines 40-45
subtest 'General Add, Get and Del tests' => sub {
Link Here
|
40 |
$dbh->{RaiseError} = 1; |
40 |
$dbh->{RaiseError} = 1; |
41 |
|
41 |
|
42 |
# Create a biblio instance for testing |
42 |
# Create a biblio instance for testing |
|
|
43 |
diag("Creating biblio instance for testing."); |
44 |
C4::Context->set_preference('marcflavour', 'MARC21'); |
43 |
my ($bibnum, $bibitemnum) = get_biblio(); |
45 |
my ($bibnum, $bibitemnum) = get_biblio(); |
44 |
|
46 |
|
45 |
# Add an item. |
47 |
# Add an item. |
Lines 76-83
subtest 'GetHiddenItemnumbers tests' => sub {
Link Here
|
76 |
$dbh->{RaiseError} = 1; |
78 |
$dbh->{RaiseError} = 1; |
77 |
|
79 |
|
78 |
# Create a new biblio |
80 |
# Create a new biblio |
|
|
81 |
C4::Context->set_preference('marcflavour', 'MARC21'); |
79 |
my ($biblionumber, $biblioitemnumber) = get_biblio(); |
82 |
my ($biblionumber, $biblioitemnumber) = get_biblio(); |
80 |
|
83 |
|
|
|
84 |
# Add branches if they don't exist |
85 |
if (not defined GetBranchDetail('CPL')) { |
86 |
ModBranch({add => 1, branchcode => 'CPL', branchname => 'Centerville'}); |
87 |
} |
88 |
if (not defined GetBranchDetail('MPL')) { |
89 |
ModBranch({add => 1, branchcode => 'MPL', branchname => 'Midway'}); |
90 |
} |
91 |
|
81 |
# Add two items |
92 |
# Add two items |
82 |
my ($item1_bibnum, $item1_bibitemnum, $item1_itemnumber) = AddItem( |
93 |
my ($item1_bibnum, $item1_bibitemnum, $item1_itemnumber) = AddItem( |
83 |
{ homebranch => 'CPL', |
94 |
{ homebranch => 'CPL', |
Lines 213-218
subtest q{Test Koha::Database->schema()->resultset('Item')->itemtype()} => sub {
Link Here
|
213 |
C4::Context->set_preference( 'item-level_itypes', 1 ); |
224 |
C4::Context->set_preference( 'item-level_itypes', 1 ); |
214 |
ok( $item->effective_itemtype() eq 'ITEM_LEVEL', '$item->itemtype() returns items.itype when item-level_itypes is disabled' ); |
225 |
ok( $item->effective_itemtype() eq 'ITEM_LEVEL', '$item->itemtype() returns items.itype when item-level_itypes is disabled' ); |
215 |
|
226 |
|
|
|
227 |
$dbh->rollback; |
228 |
}; |
229 |
|
230 |
subtest 'SearchItems test' => sub { |
231 |
plan tests => 10; |
232 |
|
233 |
# Start transaction |
234 |
$dbh->{AutoCommit} = 0; |
235 |
$dbh->{RaiseError} = 1; |
236 |
|
237 |
C4::Context->set_preference('marcflavour', 'MARC21'); |
238 |
my ($biblionumber) = get_biblio(); |
239 |
|
240 |
# Add branches if they don't exist |
241 |
if (not defined GetBranchDetail('CPL')) { |
242 |
ModBranch({add => 1, branchcode => 'CPL', branchname => 'Centerville'}); |
243 |
} |
244 |
if (not defined GetBranchDetail('MPL')) { |
245 |
ModBranch({add => 1, branchcode => 'MPL', branchname => 'Midway'}); |
246 |
} |
247 |
|
248 |
my (undef, $initial_items_count) = SearchItems(undef, {rows => 1}); |
249 |
|
250 |
# Add two items |
251 |
my (undef, undef, $item1_itemnumber) = AddItem({ |
252 |
homebranch => 'CPL', |
253 |
holdingbranch => 'CPL', |
254 |
}, $biblionumber); |
255 |
my (undef, undef, $item2_itemnumber) = AddItem({ |
256 |
homebranch => 'MPL', |
257 |
holdingbranch => 'MPL', |
258 |
}, $biblionumber); |
259 |
|
260 |
my ($items, $total_results); |
261 |
|
262 |
($items, $total_results) = SearchItems(); |
263 |
is($total_results, $initial_items_count + 2, "Created 2 new items"); |
264 |
is(scalar @$items, $total_results, "SearchItems() returns all items"); |
265 |
|
266 |
($items, $total_results) = SearchItems(undef, {rows => 1}); |
267 |
is($total_results, $initial_items_count + 2); |
268 |
is(scalar @$items, 1, "SearchItems(undef, {rows => 1}) returns only 1 item"); |
269 |
|
270 |
# Search all items where homebranch = 'CPL' |
271 |
my $filter = { |
272 |
field => 'homebranch', |
273 |
query => 'CPL', |
274 |
operator => '=', |
275 |
}; |
276 |
($items, $total_results) = SearchItems($filter); |
277 |
ok($total_results > 0, "There is at least one CPL item"); |
278 |
my $all_items_are_CPL = 1; |
279 |
foreach my $item (@$items) { |
280 |
if ($item->{homebranch} ne 'CPL') { |
281 |
$all_items_are_CPL = 0; |
282 |
last; |
283 |
} |
284 |
} |
285 |
ok($all_items_are_CPL, "All items returned by SearchItems are from CPL"); |
286 |
|
287 |
# Search all items where homebranch != 'CPL' |
288 |
$filter = { |
289 |
field => 'homebranch', |
290 |
query => 'CPL', |
291 |
operator => '!=', |
292 |
}; |
293 |
($items, $total_results) = SearchItems($filter); |
294 |
ok($total_results > 0, "There is at least one non-CPL item"); |
295 |
my $all_items_are_not_CPL = 1; |
296 |
foreach my $item (@$items) { |
297 |
if ($item->{homebranch} eq 'CPL') { |
298 |
$all_items_are_not_CPL = 0; |
299 |
last; |
300 |
} |
301 |
} |
302 |
ok($all_items_are_not_CPL, "All items returned by SearchItems are not from CPL"); |
303 |
|
304 |
# Search all items where biblio title (245$a) is like 'Silence in the %' |
305 |
$filter = { |
306 |
field => 'marc:245$a', |
307 |
query => 'Silence in the %', |
308 |
operator => 'like', |
309 |
}; |
310 |
($items, $total_results) = SearchItems($filter); |
311 |
ok($total_results >= 2, "There is at least 2 items with a biblio title like 'Silence in the %'"); |
312 |
|
313 |
# Search all items where biblio title is 'Silence in the library' |
314 |
# and homebranch is 'CPL' |
315 |
$filter = { |
316 |
conjunction => 'AND', |
317 |
filters => [ |
318 |
{ |
319 |
field => 'marc:245$a', |
320 |
query => 'Silence in the %', |
321 |
operator => 'like', |
322 |
}, |
323 |
{ |
324 |
field => 'homebranch', |
325 |
query => 'CPL', |
326 |
operator => '=', |
327 |
}, |
328 |
], |
329 |
}; |
330 |
($items, $total_results) = SearchItems($filter); |
331 |
my $found = 0; |
332 |
foreach my $item (@$items) { |
333 |
if ($item->{itemnumber} == $item1_itemnumber) { |
334 |
$found = 1; |
335 |
last; |
336 |
} |
337 |
} |
338 |
ok($found, "item1 found"); |
216 |
|
339 |
|
217 |
$dbh->rollback; |
340 |
$dbh->rollback; |
218 |
}; |
341 |
}; |