From 3336806b05442e761f3d8a763fc8bcb6806c7e1e Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Tue, 19 Nov 2024 23:23:14 +0000 Subject: [PATCH] Bug 37334: Add filter_by_checked_out tests --- t/db_dependent/Koha/Items.t | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Items.t b/t/db_dependent/Koha/Items.t index 03b26550eb..c984c00260 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 => 20; +use Test::More tests => 21; use Test::MockModule; use Test::Exception; @@ -2222,3 +2222,36 @@ subtest 'filter_by_bookable' => sub { $schema->storage->txn_rollback; }; + +subtest 'filter_by_checked_out' => sub { + plan tests => 4; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + t::lib::Mocks::mock_userenv( { branchcode => $patron->branchcode } ); + + 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_checked_out->count, 0, "Filtered 0 checked out items" ); + + C4::Circulation::AddIssue( $patron, $item_1->barcode ); + + is( $biblio->items->filter_by_checked_out->count, 1, "Filtered 1 checked out items" ); + + C4::Circulation::AddIssue( $patron, $item_2->barcode ); + + is( $biblio->items->filter_by_checked_out->count, 2, "Filtered 2 checked out items" ); + + # Do the returns + C4::Circulation::AddReturn( $item_1->barcode ); + C4::Circulation::AddReturn( $item_2->barcode ); + + is( $biblio->items->filter_by_checked_out->count, 0, "Filtered 0 checked out items" ); + + $schema->storage->txn_rollback; + +}; + -- 2.39.2