Bug 25261: (QA follow-up) Add unit tests
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Wed, 6 May 2020 09:33:35 +0000 (10:33 +0100)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 1 Oct 2020 08:33:10 +0000 (10:33 +0200)
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
t/db_dependent/Circulation.t

index 8ea7ac5..154e543 100755 (executable)
@@ -18,7 +18,7 @@
 use Modern::Perl;
 use utf8;
 
-use Test::More tests => 48;
+use Test::More tests => 51;
 use Test::Exception;
 use Test::MockModule;
 use Test::Deep qw( cmp_deeply );
@@ -3544,6 +3544,57 @@ subtest 'CanBookBeIssued & RentalFeesCheckoutConfirmation' => sub {
     $itemtype->rentalcharge_daily('0')->store;
 };
 
+subtest 'CanBookBeIssued & CircConfirmItemParts' => sub {
+    plan tests => 1;
+
+    t::lib::Mocks::mock_preference('CircConfirmItemParts', 1);
+
+    my $library =
+      $builder->build_object( { class => 'Koha::Libraries' } )->store;
+    my $patron = $builder->build_object(
+        {
+            class => 'Koha::Patrons',
+            value => { categorycode => $patron_category->{categorycode} }
+        }
+    )->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(
+        {
+            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',
+            }
+        }
+    )->store;
+
+    my ( $issuingimpossible, $needsconfirmation );
+    my $dt_from = dt_from_string();
+    my $dt_due = $dt_from->clone->add( days => 3 );
+
+    ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->barcode, $dt_due, undef, undef, undef );
+    is_deeply( $needsconfirmation, { additional_materials => 'includes DVD' }, 'Item needs confirmation of additional parts' );
+};
+
 subtest 'Do not return on renewal (LOST charge)' => sub {
     plan tests => 1;