From 2164a1aedeaadf05fe4bf951bbd1cc527f227222 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 24 Jul 2020 10:33:26 +0200 Subject: [PATCH] Bug 25261: (QA follow-up) Simplify tests and conditions Use build_sample_item in tests Simplify tests for the confirmation Signed-off-by: Martin Renvoize --- C4/Circulation.pm | 8 ++++---- circ/returns.pl | 12 +++++------- t/db_dependent/Circulation.t | 37 +++++------------------------------- 3 files changed, 14 insertions(+), 43 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 61873656b3..14fa80c45d 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -898,10 +898,10 @@ sub CanBookBeIssued { } # Additional Materials Check - if ( C4::Context->preference("CircConfirmItemParts") ) { - if ( $item_object->materials ) { - $needsconfirmation{additional_materials} = $item_object->materials; - } + if ( C4::Context->preference("CircConfirmItemParts") + && $item_object->materials ) + { + $needsconfirmation{additional_materials} = $item_object->materials; } # diff --git a/circ/returns.pl b/circ/returns.pl index 7c7db6b166..0a2288aac3 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -296,17 +296,15 @@ if ($barcode) { my $return_date = $dropboxmode ? $dropboxdate : $return_date_override_dt; # Block return if multi-part and confirm has not been received - my $needs_confirm = 0; - if ( C4::Context->preference("CircConfirmItemParts") ) { - if ( $item->materials && !$query->param('multiple_confirm') ) { - $needs_confirm = 1; - } - } + my $needs_confirm = + C4::Context->preference("CircConfirmItemParts") + && $item->materials + && !$query->param('multiple_confirm'); # do the return ( $returned, $messages, $issue, $borrower ) = AddReturn( $barcode, $userenv_branch, $exemptfine, $return_date ) - unless $needs_confirm; + unless $needs_confirm; if ($returned) { my $time_now = dt_from_string()->truncate( to => 'minute'); diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 8486caaa69..66eae24082 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -18,7 +18,7 @@ use Modern::Perl; use utf8; -use Test::More tests => 51; +use Test::More tests => 49; use Test::Exception; use Test::MockModule; use Test::Deep qw( cmp_deeply ); @@ -3543,8 +3543,6 @@ subtest 'CanBookBeIssued & CircConfirmItemParts' => sub { t::lib::Mocks::mock_preference('CircConfirmItemParts', 1); - my $library = - $builder->build_object( { class => 'Koha::Libraries' } )->store; my $patron = $builder->build_object( { class => 'Koha::Patrons', @@ -3552,40 +3550,15 @@ subtest 'CanBookBeIssued & CircConfirmItemParts' => sub { } )->store; - my $itemtype = $builder->build_object( - { - class => 'Koha::ItemTypes', - value => { - notforloan => 0, - rentalcharge => 0, - rentalcharge_daily => 0 - } - } - ); - - my $biblioitem = $builder->build( { source => 'Biblioitem' } ); - my $item = $builder->build_object( + my $item = $builder->build_sample_item( { - class => 'Koha::Items', - value => { - homebranch => $library->id, - holdingbranch => $library->id, - notforloan => 0, - itemlost => 0, - withdrawn => 0, - itype => $itemtype->id, - biblionumber => $biblioitem->{biblionumber}, - biblioitemnumber => $biblioitem->{biblioitemnumber}, - materials => 'includes DVD', - } + materials => 'includes DVD', } )->store; - my ( $issuingimpossible, $needsconfirmation ); - my $dt_from = dt_from_string(); - my $dt_due = $dt_from->clone->add( days => 3 ); + my $dt_due = dt_from_string->add( days => 3 ); - ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->barcode, $dt_due, undef, undef, undef ); + my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->barcode, $dt_due, undef, undef, undef ); is_deeply( $needsconfirmation, { additional_materials => 'includes DVD' }, 'Item needs confirmation of additional parts' ); }; -- 2.20.1