From f518e0b34b7e65801749cd9ebd2b7aa21c9d0153 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 Signed-off-by: Emmi Takkinen --- t/db_dependent/Koha/Items.t | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Items.t b/t/db_dependent/Koha/Items.t index 03b26550eb4..b79db3ea3c4 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,35 @@ 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.5