|
Lines 21-26
use Data::Dumper;
Link Here
|
| 21 |
use MARC::Record; |
21 |
use MARC::Record; |
| 22 |
use C4::Items qw( ModItemTransfer GetHiddenItemnumbers GetItemsInfo SearchItems AddItemFromMarc ModItemFromMarc get_hostitemnumbers_of Item2Marc ); |
22 |
use C4::Items qw( ModItemTransfer GetHiddenItemnumbers GetItemsInfo SearchItems AddItemFromMarc ModItemFromMarc get_hostitemnumbers_of Item2Marc ); |
| 23 |
use C4::Biblio qw( GetMarcFromKohaField EmbedItemsInMarcBiblio GetMarcBiblio AddBiblio ); |
23 |
use C4::Biblio qw( GetMarcFromKohaField EmbedItemsInMarcBiblio GetMarcBiblio AddBiblio ); |
|
|
24 |
use C4::Circulation qw( AddIssue ); |
| 24 |
use Koha::Items; |
25 |
use Koha::Items; |
| 25 |
use Koha::Database; |
26 |
use Koha::Database; |
| 26 |
use Koha::DateUtils qw( dt_from_string ); |
27 |
use Koha::DateUtils qw( dt_from_string ); |
|
Lines 407-413
subtest q{Test Koha::Database->schema()->resultset('Item')->itemtype()} => sub {
Link Here
|
| 407 |
}; |
408 |
}; |
| 408 |
|
409 |
|
| 409 |
subtest 'SearchItems test' => sub { |
410 |
subtest 'SearchItems test' => sub { |
| 410 |
plan tests => 17; |
411 |
plan tests => 19; |
| 411 |
|
412 |
|
| 412 |
$schema->storage->txn_begin; |
413 |
$schema->storage->txn_begin; |
| 413 |
my $dbh = C4::Context->dbh; |
414 |
my $dbh = C4::Context->dbh; |
|
Lines 432-444
subtest 'SearchItems test' => sub {
Link Here
|
| 432 |
my (undef, $initial_items_count) = SearchItems(undef, {rows => 1}); |
433 |
my (undef, $initial_items_count) = SearchItems(undef, {rows => 1}); |
| 433 |
|
434 |
|
| 434 |
# Add two items |
435 |
# Add two items |
| 435 |
my $item1_itemnumber = $builder->build_sample_item( |
436 |
my $item1 = $builder->build_sample_item( |
| 436 |
{ |
437 |
{ |
| 437 |
biblionumber => $biblio->biblionumber, |
438 |
biblionumber => $biblio->biblionumber, |
| 438 |
library => $library1->{branchcode}, |
439 |
library => $library1->{branchcode}, |
| 439 |
itype => $itemtype->{itemtype} |
440 |
itype => $itemtype->{itemtype} |
| 440 |
} |
441 |
} |
| 441 |
)->itemnumber; |
442 |
); |
|
|
443 |
my $item1_itemnumber = $item1->itemnumber; |
| 442 |
my $item2_itemnumber = $builder->build_sample_item( |
444 |
my $item2_itemnumber = $builder->build_sample_item( |
| 443 |
{ |
445 |
{ |
| 444 |
biblionumber => $biblio->biblionumber, |
446 |
biblionumber => $biblio->biblionumber, |
|
Lines 450-455
subtest 'SearchItems test' => sub {
Link Here
|
| 450 |
my ($items, $total_results); |
452 |
my ($items, $total_results); |
| 451 |
|
453 |
|
| 452 |
($items, $total_results) = SearchItems(); |
454 |
($items, $total_results) = SearchItems(); |
|
|
455 |
|
| 453 |
is($total_results, $initial_items_count + 2, "Created 2 new items"); |
456 |
is($total_results, $initial_items_count + 2, "Created 2 new items"); |
| 454 |
is(scalar @$items, $total_results, "SearchItems() returns all items"); |
457 |
is(scalar @$items, $total_results, "SearchItems() returns all items"); |
| 455 |
|
458 |
|
|
Lines 628-633
subtest 'SearchItems test' => sub {
Link Here
|
| 628 |
($items, $total_results) = SearchItems($filter); |
631 |
($items, $total_results) = SearchItems($filter); |
| 629 |
is($total_results, 1, 'found all items of library1 with new_status=0 with ifnull = 0'); |
632 |
is($total_results, 1, 'found all items of library1 with new_status=0 with ifnull = 0'); |
| 630 |
|
633 |
|
|
|
634 |
t::lib::Mocks::mock_userenv({ branchcode => $item1->homebranch }); |
| 635 |
my $patron_borrower = $builder->build_object({ class => 'Koha::Patrons' })->unblessed; |
| 636 |
AddIssue( $patron_borrower, $item1->barcode ); |
| 637 |
# Search item where item is checked out |
| 638 |
$filter = { |
| 639 |
field => 'onloan', |
| 640 |
query => 'not null', |
| 641 |
operator => 'is', |
| 642 |
}; |
| 643 |
($items, $total_results) = SearchItems($filter); |
| 644 |
ok(scalar @$items == 1, 'found 1 checked out item'); |
| 645 |
|
| 646 |
# When sorting by descending availability, checked out item should show first |
| 647 |
my $params = { |
| 648 |
sortby => 'availability', |
| 649 |
sortorder => 'DESC', |
| 650 |
}; |
| 651 |
($items, $total_results) = SearchItems(undef,$params); |
| 652 |
is($items->[0]->{barcode}, $item1->barcode, 'Items sorted as expected by availability'); |
| 653 |
|
| 631 |
$schema->storage->txn_rollback; |
654 |
$schema->storage->txn_rollback; |
| 632 |
}; |
655 |
}; |
| 633 |
|
656 |
|
| 634 |
- |
|
|