From 51242c5237e6ffa0e8441ee6abf0b1f9d412b81f 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 | 35 ++++------------------------------- 3 files changed, 13 insertions(+), 42 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 0501bc2021..53504116d8 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -880,10 +880,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 e8c28ca7ad..78ad56953b 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -3986,8 +3986,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', @@ -3995,40 +3993,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