|
Lines 228-234
subtest q{Test Koha::Database->schema()->resultset('Item')->itemtype()} => sub {
Link Here
|
| 228 |
}; |
228 |
}; |
| 229 |
|
229 |
|
| 230 |
subtest 'SearchItems test' => sub { |
230 |
subtest 'SearchItems test' => sub { |
| 231 |
plan tests => 10; |
231 |
plan tests => 13; |
| 232 |
|
232 |
|
| 233 |
# Start transaction |
233 |
# Start transaction |
| 234 |
$dbh->{AutoCommit} = 0; |
234 |
$dbh->{AutoCommit} = 0; |
|
Lines 337-342
subtest 'SearchItems test' => sub {
Link Here
|
| 337 |
} |
337 |
} |
| 338 |
ok($found, "item1 found"); |
338 |
ok($found, "item1 found"); |
| 339 |
|
339 |
|
|
|
340 |
my ($itemfield) = GetMarcFromKohaField('items.itemnumber', ''); |
| 341 |
|
| 342 |
# Create item subfield 'z' without link |
| 343 |
$dbh->do('DELETE FROM marc_subfield_structure WHERE tagfield=? AND tagsubfield="z" AND frameworkcode=""', undef, $itemfield); |
| 344 |
$dbh->do('INSERT INTO marc_subfield_structure (tagfield, tagsubfield, frameworkcode) VALUES (?, "z", "")', undef, $itemfield); |
| 345 |
|
| 346 |
# Clear cache |
| 347 |
$C4::Context::context->{marcfromkohafield} = undef; |
| 348 |
$C4::Biblio::inverted_field_map = undef; |
| 349 |
|
| 350 |
my $item3_record = new MARC::Record; |
| 351 |
$item3_record->append_fields( |
| 352 |
new MARC::Field($itemfield, '', '', 'z' => 'foobar') |
| 353 |
); |
| 354 |
my (undef, undef, $item3_itemnumber) = AddItemFromMarc($item3_record, |
| 355 |
$biblionumber); |
| 356 |
|
| 357 |
# Search item where item subfield z is "foobar" |
| 358 |
$filter = { |
| 359 |
field => 'marc:' . $itemfield . '$z', |
| 360 |
query => 'foobar', |
| 361 |
operator => 'like', |
| 362 |
}; |
| 363 |
($items, $total_results) = SearchItems($filter); |
| 364 |
ok(scalar @$items == 1, 'found 1 item with $z = "foobar"'); |
| 365 |
|
| 366 |
# Link $z to items.itemnotes (and make sure there is no other subfields |
| 367 |
# linked to it) |
| 368 |
$dbh->do('DELETE FROM marc_subfield_structure WHERE kohafield="items.itemnotes" AND frameworkcode=""', undef, $itemfield); |
| 369 |
$dbh->do('UPDATE marc_subfield_structure SET kohafield="items.itemnotes" WHERE tagfield=? AND tagsubfield="z" AND frameworkcode=""', undef, $itemfield); |
| 370 |
|
| 371 |
# Clear cache |
| 372 |
$C4::Context::context->{marcfromkohafield} = undef; |
| 373 |
$C4::Biblio::inverted_field_map = undef; |
| 374 |
|
| 375 |
ModItemFromMarc($item3_record, $biblionumber, $item3_itemnumber); |
| 376 |
|
| 377 |
# Make sure the link is used |
| 378 |
my $item3 = GetItem($item3_itemnumber); |
| 379 |
ok($item3->{itemnotes} eq 'foobar', 'itemnotes eq "foobar"'); |
| 380 |
|
| 381 |
# Do the same search again. |
| 382 |
# This time it will search in items.itemnotes |
| 383 |
($items, $total_results) = SearchItems($filter); |
| 384 |
ok(scalar @$items == 1, 'found 1 item with itemnotes = "foobar"'); |
| 385 |
|
| 340 |
$dbh->rollback; |
386 |
$dbh->rollback; |
| 341 |
}; |
387 |
}; |
| 342 |
|
388 |
|
| 343 |
- |
|
|