From e85a4432d15ea59499079b77cab7b6f915d316da Mon Sep 17 00:00:00 2001 From: Michal Urban Date: Wed, 15 Jun 2022 04:04:37 -0400 Subject: [PATCH] Added test to ensure that Koha::Holds->get_items_that_can_fill returns items with datecancelled and datearrived https://bugs.koha-community.org/show_bug.cgi?id=30447 --- t/db_dependent/Holds.t | 101 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index 8a19f019bb..6d58be2bbe 100755 --- a/t/db_dependent/Holds.t +++ b/t/db_dependent/Holds.t @@ -7,7 +7,7 @@ use t::lib::TestBuilder; use C4::Context; -use Test::More tests => 74; +use Test::More tests => 75; use Test::Exception; use MARC::Record; @@ -22,13 +22,15 @@ use Koha::Biblios; use Koha::CirculationRules; use Koha::Database; use Koha::DateUtils qw( dt_from_string output_pref ); -use Koha::Holds; +use Koha::Holds qw( search ); use Koha::Checkout; use Koha::Item::Transfer::Limits; use Koha::Items; use Koha::Libraries; use Koha::Library::Groups; use Koha::Patrons; +use Koha::Hold qw( get_items_that_can_fill ); +use Koha::Item::Transfers; BEGIN { use FindBin; @@ -1702,3 +1704,98 @@ subtest 'ModReserve can only update expirationdate for found holds' => sub { $schema->storage->txn_rollback; }; + +subtest 'Koha::Holds->get_items_that_can_fill returns items with datecancelled and datearrived' => sub { + plan tests => 4; + # biblio item with date arrived and date cancelled + my $biblio1 = $builder->build_sample_biblio(); + my $item1 = $builder->build_sample_item({ biblionumber => $biblio1->biblionumber }); + + my $transfer1 = $builder->build_object({ class => "Koha::Item::Transfers", value => { + datecancelled => '2022-06-12', + itemnumber => $item1->itemnumber + }}); + + my $hold1 = $builder->build_object({ class => 'Koha::Holds', value => { + biblionumber => $biblio1->biblionumber, + itemnumber => undef, + itemtype => undef, + found => undef + }}); + + # biblio item with date arrived and NO date cancelled + my $biblio2 = $builder->build_sample_biblio(); + my $item2 = $builder->build_sample_item({ biblionumber => $biblio2->biblionumber }); + + my $transfer2 = $builder->build_object({ class => "Koha::Item::Transfers", value => { + datecancelled => undef, + itemnumber => $item2->itemnumber + }}); + + my $hold2 = $builder->build_object({ class => 'Koha::Holds', value => { + biblionumber => $biblio2->biblionumber, + itemnumber => undef, + itemtype => undef, + found => undef + }}); + + # biblio item with NO date arrived and date cancelled + my $biblio3 = $builder->build_sample_biblio(); + my $item3 = $builder->build_sample_item({ biblionumber => $biblio3->biblionumber }); + + my $transfer3 = $builder->build_object({ class => "Koha::Item::Transfers", value => { + datecancelled => '2022-06-12', + itemnumber => $item3->itemnumber, + datearrived => undef + }}); + + my $hold3 = $builder->build_object({ class => 'Koha::Holds', value => { + biblionumber => $biblio3->biblionumber, + itemnumber => undef, + itemtype => undef, + found => undef + }}); + + + # biblio item with NO date arrived and NO date cancelled + my $biblio4 = $builder->build_sample_biblio(); + my $item4 = $builder->build_sample_item({ biblionumber => $biblio4->biblionumber }); + + my $transfer4 = $builder->build_object({ class => "Koha::Item::Transfers", value => { + datecancelled => undef, + itemnumber => $item4->itemnumber, + datearrived => undef + }}); + + my $hold4 = $builder->build_object({ class => 'Koha::Holds', value => { + biblionumber => $biblio4->biblionumber, + itemnumber => undef, + itemtype => undef, + found => undef + }}); + + # create the holds which get_items_that_can_fill will be ran on + my $holds1 = Koha::Holds->search({reserve_id => $hold1->id}); + my $holds2 = Koha::Holds->search({reserve_id => $hold2->id}); + my $holds3 = Koha::Holds->search({reserve_id => $hold3->id}); + my $holds4 = Koha::Holds->search({reserve_id => $hold4->id}); + + my $items_that_can_fill1 = $holds1->get_items_that_can_fill; + my $items_that_can_fill2 = $holds2->get_items_that_can_fill; + my $items_that_can_fill3 = $holds3->get_items_that_can_fill; + my $items_that_can_fill4 = $holds4->get_items_that_can_fill; + + # get the item number that will be compared to with the items that are called which get_items_that_can_fill returns + my %item_unblessed1 = $item1->unblessed; + # used for first test case + + my %items_that_can_fill_unblessed1 = $items_that_can_fill1->unblessed; + my %items_that_can_fill_unblessed2 = $items_that_can_fill2->unblessed; + my %items_that_can_fill_unblessed3 = $items_that_can_fill3->unblessed; + my %items_that_can_fill_unblessed4 = $items_that_can_fill4->unblessed; + + is($items_that_can_fill_unblessed1{"itemnumber"}, $item_unblessed1{"itemnumber"}, "Koha::Holds->get_items_that_can_fill returns item with defined datearrived and datecancelled"); + is($items_that_can_fill_unblessed2{"itemnumber"}, undef, "Koha::Holds->get_items_that_can_fill doesn't return item with defined datearrived and undefined datecancelled"); + is($items_that_can_fill_unblessed3{"itemnumber"}, undef, "Koha::Holds->get_items_that_can_fill doesn't return item with undefined datearrived and defined datecancelled"); + is($items_that_can_fill_unblessed3{"itemnumber"}, undef, "Koha::Holds->get_items_that_can_fill doesn't return item with undefined datearrived and undefined datecancelled"); +} -- 2.25.1