From 8c047b7d47e0db839bc51b82014cfb30a5029db4 Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Tue, 12 May 2015 11:40:28 +0300 Subject: [PATCH] Bug 14188 - branchtransfers GetAllTransfers and GetAllPendingTransfers functions to ease testing. Because there is no nice way of getting all branchtransfers and putting SQL into tests is VERY VERY BAD, introducing these branchtransfer API calls to conveniently get all transfers data nicely. Unit tests included. TEST PLAN: Run t/db_dependent/Circulation_transfers.t --- C4/Circulation.pm | 38 ++++++++++++++++++++++++++++++++ t/db_dependent/Circulation_transfers.t | 9 +++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index c6ecd62..e01a6e9 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3143,6 +3143,44 @@ sub GetTransfersFromTo { return (@gettransfers); } +=head2 GetAllPendingTransfers + + C4::Circulation::GetAllPendingTransfers(); + +@RETURNS Reference to ARRAY of HASHes, + All rows in the koha.branchtransfers-table that have not arrived yet. + Warning, the amount of rows returned in production can be in the thousands. +=cut + +sub GetAllPendingTransfers { + my $dbh = C4::Context->dbh; + + my $query = 'SELECT * FROM branchtransfers WHERE datearrived IS NULL'; + my $sth = $dbh->prepare($query); + $sth->execute(); + my $pendingTransfers = $sth->fetchall_arrayref({}); + return $pendingTransfers; +} + +=head2 GetAllTransfers + + C4::Circulation::GetAllTransfers(); + +@RETURNS Reference to ARRAY of HASHes, + All rows in the koha.branchtransfers-table. + Warning, the amount of rows returned in production can be in the millions. +=cut + +sub GetAllTransfers { + my $dbh = C4::Context->dbh; + + my $query = 'SELECT * FROM branchtransfers'; + my $sth = $dbh->prepare($query); + $sth->execute(); + my $transfers = $sth->fetchall_arrayref({}); + return $transfers; +} + =head2 DeleteTransfer &DeleteTransfer($itemnumber); diff --git a/t/db_dependent/Circulation_transfers.t b/t/db_dependent/Circulation_transfers.t index 0c92222..f107854 100644 --- a/t/db_dependent/Circulation_transfers.t +++ b/t/db_dependent/Circulation_transfers.t @@ -9,7 +9,7 @@ use C4::Circulation; use Koha::DateUtils; use DateTime::Duration; -use Test::More tests => 22; +use Test::More tests => 24; use Test::Deep; BEGIN { @@ -121,6 +121,13 @@ ModItemTransfer( ); #Begin Tests +#Test GetAllTransfers() +my $allTransfers = C4::Circulation::GetAllTransfers(); +ok(($allTransfers && scalar(@$allTransfers) == 2), "GetAllTransfers() returns all transfers :)"); +#Test GetAllPendingTransfers() +my $pendingTransfers = C4::Circulation::GetAllPendingTransfers(); +ok(($pendingTransfers && scalar(@$pendingTransfers) == 2), "GetAllPendingTransfers() returns all pending transfers :)"); + #Test CreateBranchTransferLimit is( CreateBranchTransferLimit( -- 1.7.9.5