From 2aaa799ed2da45432d5d88d9180aa342f576d60a Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 20 Oct 2021 18:01:42 -0300 Subject: [PATCH] Bug 29288: Unit tests Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Koha/Biblio.t | 38 +++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index f294606f30..710ab3ba15 100755 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -17,9 +17,10 @@ use Modern::Perl; -use Test::More tests => 16; +use Test::More tests => 17; use C4::Biblio qw( AddBiblio ModBiblio ); +use C4::Circulation qw( AddIssue AddReturn ); use Koha::Database; use Koha::Caches; use Koha::Acquisition::Orders; @@ -736,3 +737,38 @@ subtest 'article_requests() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'current_checkouts() and old_checkouts() tests' => sub { + + plan tests => 4; + + $schema->storage->txn_begin; + + my $library = $builder->build_object({ class => 'Koha::Libraries' }); + + my $patron_1 = $builder->build_object({ class => 'Koha::Patrons' })->unblessed; + my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' })->unblessed; + + my $item_1 = $builder->build_sample_item; + my $item_2 = $builder->build_sample_item({ biblionumber => $item_1->biblionumber }); + + t::lib::Mocks::mock_userenv({ branchcode => $library->id }); + + AddIssue( $patron_1, $item_1->barcode ); + AddIssue( $patron_1, $item_2->barcode ); + + AddReturn( $item_1->barcode ); + AddIssue( $patron_2, $item_1->barcode ); + + my $biblio = $item_1->biblio; + my $current_checkouts = $biblio->current_checkouts; + my $old_checkouts = $biblio->old_checkouts; + + is( ref($current_checkouts), 'Koha::Checkouts', 'Type is correct' ); + is( ref($old_checkouts), 'Koha::Old::Checkouts', 'Type is correct' ); + + is( $current_checkouts->count, 2, 'Count is correct for current checkouts' ); + is( $old_checkouts->count, 1, 'Count is correct for old checkouts' ); + + $schema->storage->txn_rollback; +}; \ No newline at end of file -- 2.32.0