From 466f9ec4477867970caf461663b2aafc738f7ed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20=C5=A0iman?= Date: Fri, 5 May 2017 21:04:16 +0200 Subject: [PATCH] Bug 17509: Added tests prove t/db_dependent/Reserves/Notification.t --- C4/Reserves.pm | 1 + t/db_dependent/Reserves/Notification.t | 167 +++++++++++++++++++++++++++++++++ 2 files changed, 168 insertions(+) create mode 100755 t/db_dependent/Reserves/Notification.t diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 876a9db..de1adfe 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -148,6 +148,7 @@ BEGIN { IsItemOnHoldAndFound GetMaxPatronHoldsForRecord + GetBorrowersToSatisfyHold ); @EXPORT_OK = qw( MergeHolds ); } diff --git a/t/db_dependent/Reserves/Notification.t b/t/db_dependent/Reserves/Notification.t new file mode 100755 index 0000000..35ac5dc --- /dev/null +++ b/t/db_dependent/Reserves/Notification.t @@ -0,0 +1,167 @@ +#!/usr/bin/perl + +# Copyright 2017 R-Bit Technology, s.r.o. +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Test::More tests => 5; +use t::lib::TestBuilder; +use t::lib::Mocks; + +use C4::Reserves qw( GetBorrowersToSatisfyHold ); +use Koha::Database; +use Koha::Holds; +use Data::Dumper; + +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; + +my $builder = t::lib::TestBuilder->new(); +my $libraryA = $builder->build( + { + source => 'Branch', + } +); + +my $libraryB = $builder->build( + { + source => 'Branch', + } +); + +my $holdRequestorInA = $builder->build( + { + source => 'Borrower', + value => { + branchcode => $libraryA->{branchcode}, + cardnumber => '001', + }, + } +); + +my $patronInA = $builder->build( + { + source => 'Borrower', + value => { + branchcode => $libraryA->{branchcode}, + cardnumber => '002', + }, + } +); + +my $patronInB = $builder->build( + { + source => 'Borrower', + value => { + branchcode => $libraryB->{branchcode}, + cardnumber => '003', + }, + } +); + +my $biblio = $builder->build( + { + source => 'Biblio', + value => { + title => 'Title 1', + }, + } +); +my $itemType = $builder->build( + { + source => 'Itemtype', + } +); +my $itemInA = $builder->build( + { + source => 'Item', + value => { + biblionumber => $biblio->{biblionumber}, + homebranch => $libraryA->{branchcode}, + holdingbranch => $libraryA->{branchcode}, + itype => $itemType->{itemtype}, + }, + } +); +my $itemInB = $builder->build( + { + source => 'Item', + value => { + biblionumber => $biblio->{biblionumber}, + homebranch => $libraryB->{branchcode}, + holdingbranch => $libraryB->{branchcode}, + itype => $itemType->{itemtype}, + }, + } +); + +my $issueOfItemInA = $builder->build( + { + source => 'Issue', + value => { + borrowernumber => $patronInB->{borrowernumber}, + itemnumber => $itemInA->{itemnumber}, + }, + } +); +my $issueOfItemInB = $builder->build( + { + source => 'Issue', + value => { + borrowernumber => $patronInA->{borrowernumber}, + itemnumber => $itemInB->{itemnumber}, + }, + } +); + +t::lib::Mocks::mock_preference('NotifyToReturnItemWhenHoldIsPlaced', 1); # Assuming the notification is allowed + +my $hold = Koha::Hold->new( + { + borrowernumber => $holdRequestorInA->{borrowernumber}, + biblionumber => $biblio->{biblionumber}, + reservedate => '2017-01-01', + branchcode => $holdRequestorInA->{branchcode}, + priority => 1, + reservenotes => 'dummy text', + #itemnumber => $itemInA->{itemnumber}, + waitingdate => '2099-01-01', + expirationdate => '2099-01-01', + itemtype => $itemInA->{itype}, + } +)->store(); + +my @borrowers; + +t::lib::Mocks::mock_preference('NotifyToReturnItemFromLibrary', 'AnyLibrary'); # Assuming items from any library +@borrowers = GetBorrowersToSatisfyHold($hold); +is(scalar(grep {defined $_} @borrowers), 2, "2 borrowers with requested item found in any library"); + +t::lib::Mocks::mock_preference('NotifyToReturnItemFromLibrary', 'RequestorLibrary'); # Assuming items from requestor library +@borrowers = GetBorrowersToSatisfyHold($hold); +is(scalar(grep {defined $_} @borrowers), 1, "1 item found in requestor library"); +is($borrowers[0]->{cardnumber}, "002", " ...and it is in 002's hands"); + +t::lib::Mocks::mock_preference('NotifyToReturnItemFromLibrary', 'ItemHomeLibrary'); # Assuming items from the same library as requested item +@borrowers = GetBorrowersToSatisfyHold($hold); +is(scalar(grep {defined $_} @borrowers), 1, "1 item found in the same library as the requested item"); +is($borrowers[0]->{cardnumber}, "003", " ...and it is in 003's hands"); + +$schema->storage->txn_rollback; + +1; -- 2.1.4