From 531ed0ec51716300bf774788918648ec921c4331 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 16 Jan 2020 15:58:15 -0300 Subject: [PATCH] Bug 24440: Unit tests Signed-off-by: Tomas Cohen Arazi Signed-off-by: David Nind Signed-off-by: David Nind --- t/db_dependent/Koha/Acquisition/Order.t | 62 ++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Acquisition/Order.t b/t/db_dependent/Koha/Acquisition/Order.t index 3b7b68a533..6d2797bf35 100644 --- a/t/db_dependent/Koha/Acquisition/Order.t +++ b/t/db_dependent/Koha/Acquisition/Order.t @@ -19,12 +19,13 @@ use Modern::Perl; -use Test::More tests => 6; +use Test::More tests => 7; use t::lib::TestBuilder; use t::lib::Mocks; use Koha::Database; +use Koha::DateUtils qw(dt_from_string); my $schema = Koha::Database->schema; my $builder = t::lib::TestBuilder->new; @@ -250,3 +251,62 @@ subtest 'duplicate_to | add_item' => sub { $schema->storage->txn_rollback; }; + +subtest 'current_holds() tests' => sub { + + plan tests => 3; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + 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 } ); + my $item_3 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); + + C4::Reserves::AddReserve( + $patron->branchcode, $patron->borrowernumber, + $biblio->biblionumber, undef, + undef, dt_from_string->add( days => -2 ), + undef, undef, + undef, $item_1->itemnumber + ); + C4::Reserves::AddReserve( + $patron->branchcode, $patron->borrowernumber, + $biblio->biblionumber, undef, + undef, dt_from_string->add( days => -2 ), + undef, undef, + undef, $item_2->itemnumber + ); + # Add a hold in the future + C4::Reserves::AddReserve( + $patron->branchcode, $patron->borrowernumber, + $biblio->biblionumber, undef, + undef, dt_from_string->add( days => 2 ), + undef, undef, + undef, $item_3->itemnumber + ); + + # Add an order with no biblionumber + my $order = $builder->build_object( + { + class => 'Koha::Acquisition::Orders', + value => { + biblionumber => undef + } + } + ); + + is( $order->current_holds, undef, 'Returns undef if no linked biblio'); + + $order->set({ biblionumber => $biblio->biblionumber })->store->discard_changes; + + is( $order->current_holds, undef, 'Returns undef if no linked items'); + + $order->add_item( $item_2->itemnumber ); + $order->add_item( $item_3->itemnumber ); + + is( $order->current_holds->count, 1, 'Only current (not future) holds are returned'); + + $schema->storage->txn_rollback; +}; -- 2.11.0