Bug 20724: Add tests for ReservesNeedReturns
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 10 May 2018 14:40:33 +0000 (11:40 -0300)
committerFridolin Somers <fridolin.somers@biblibre.com>
Mon, 24 Sep 2018 13:08:58 +0000 (15:08 +0200)
Signed-off-by: Victor Grousset <victor.grousset@biblibre.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
(cherry picked from commit 8b6dc6b23ccb26e18c437a578b4e20174ee1ea58)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
(cherry picked from commit b9dbce17b4c1121a9c46273f6e43cc3b91ff4cbb)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>

t/db_dependent/Reserves.t

index e462276..8d464ee 100755 (executable)
@@ -17,7 +17,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 72;
+use Test::More tests => 73;
 use Test::MockModule;
 use Test::Warn;
 
@@ -53,6 +53,9 @@ my $builder = t::lib::TestBuilder->new;
 
 my $frameworkcode = q||;
 
+
+t::lib::Mocks::mock_preference('ReservesNeedReturns', 1);
+
 # Somewhat arbitrary field chosen for age restriction unit tests. Must be added to db before the framework is cached
 $dbh->do("update marc_subfield_structure set kohafield='biblioitems.agerestriction' where tagfield='521' and tagsubfield='a' and frameworkcode=?", undef, $frameworkcode);
 my $cache = Koha::Caches->get_instance;
@@ -786,6 +789,57 @@ subtest '_koha_notify_reserve() tests' => sub {
 
 };
 
+subtest 'ReservesNeedReturns' => sub {
+    plan tests => 4;
+
+    my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems' } );
+    my $library    = $builder->build_object( { class => 'Koha::Libraries' } );
+    my $itemtype   = $builder->build_object( { class => 'Koha::ItemTypes', value => { rentalcharge => 0 } } );
+    my $item_info  = {
+        biblionumber     => $biblioitem->biblionumber,
+        biblioitemnumber => $biblioitem->biblioitemnumber,
+        homebranch       => $library->branchcode,
+        holdingbranch    => $library->branchcode,
+        itype            => $itemtype->itemtype,
+    };
+    my $item = $builder->build_object( { class => 'Koha::Items', value => $item_info } );
+    my $patron   = $builder->build_object(
+        {
+            class => 'Koha::Patrons',
+            value => { branchcode => $library->branchcode, }
+        }
+    );
+
+    my $priority = 1;
+    my ( $hold_id, $hold );
+
+    t::lib::Mocks::mock_preference('ReservesNeedReturns', 0); # '0' means 'Automatically mark a hold as found and waiting'
+    $hold_id = C4::Reserves::AddReserve(
+        $library->branchcode, $patron->borrowernumber,
+        $item->biblionumber,  '',
+        $priority,            undef,
+        undef,                '',
+        "title for fee",      $item->itemnumber,
+    );
+    $hold = Koha::Holds->find($hold_id);
+    is( $hold->priority, 0, 'If ReservesNeedReturns is 0, priority must have been set to 0' );
+    is( $hold->found, 'W', 'If ReservesNeedReturns is 0, found must have been set waiting' );
+
+    $hold->delete; # cleanup
+
+    t::lib::Mocks::mock_preference('ReservesNeedReturns', 1); # '0' means "Don't automatically mark a hold as found and waiting"
+    $hold_id = C4::Reserves::AddReserve(
+        $library->branchcode, $patron->borrowernumber,
+        $item->biblionumber,  '',
+        $priority,            undef,
+        undef,                '',
+        "title for fee",      $item->itemnumber,
+    );
+    $hold = Koha::Holds->find($hold_id);
+    is( $hold->priority, $priority, 'If ReservesNeedReturns is 1, priority must not have been set to changed' );
+    is( $hold->found, undef, 'If ReservesNeedReturns is 1, found must not have been set waiting' );
+};
+
 sub count_hold_print_messages {
     my $message_count = $dbh->selectall_arrayref(q{
         SELECT COUNT(*)