From d6427769fc620f73e0055c583699eea75cf09ea6 Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Thu, 21 Nov 2024 21:27:49 +0000 Subject: [PATCH 12/13] Bug 37334: Add filter_by_has_holds tests Signed-off-by: Emmi Takkinen --- t/db_dependent/Koha/Items.t | 46 ++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Items.t b/t/db_dependent/Koha/Items.t index 8f6520b31c..aa3e0d4a0a 100755 --- a/t/db_dependent/Koha/Items.t +++ b/t/db_dependent/Koha/Items.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 22; +use Test::More tests => 23; use Test::MockModule; use Test::Exception; @@ -34,6 +34,7 @@ use Koha::Items; use Koha::Database; use Koha::DateUtils qw( dt_from_string ); use Koha::Statistics; +use Koha::Recalls; use t::lib::TestBuilder; use t::lib::Mocks; @@ -2301,3 +2302,46 @@ subtest 'filter_by_in_transit' => sub { $schema->storage->txn_rollback; }; + +subtest 'filter_by_has_holds' => sub { + plan tests => 3; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + t::lib::Mocks::mock_userenv( { branchcode => $patron->branchcode } ); + + my $library_1 = $builder->build( { source => 'Branch' } ); + my $library_2 = $builder->build( { source => 'Branch' } ); + + my $biblio = $builder->build_sample_biblio(); + my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, }); + my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, }); + + is ( $biblio->items->filter_by_has_holds->count, 0, "Filtered to 0 holds" ); + + my $hold_1 = $builder->build( + { + source => 'Reserve', + value => { + itemnumber => $item_1->itemnumber, reservedate => dt_from_string, + } + } + ); + + is ( $biblio->items->filter_by_has_holds->count, 1, "Filtered to 1 hold" ); + + my $hold_2 = $builder->build( + { + source => 'Reserve', + value => { + itemnumber => $item_2->itemnumber, reservedate => dt_from_string, + } + } + ); + + is ( $biblio->items->filter_by_has_holds->count, 2, "Filtered to 2 holds" ); + + $schema->storage->txn_rollback; + +}; -- 2.34.1