From 41589686e8b9aba7123540ff8ad9f186f5726c89 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 Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- 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 9f4a2faa65..23415ead8e 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 58a5e8462b..986a9939eb 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -295,17 +295,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 154e543459..60320aac32 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 ); @@ -3549,8 +3549,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', @@ -3558,40 +3556,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.39.5