Bug 24839: (QA follow-up) Remove unused variables
[koha.git] / t / db_dependent / Circulation / transferbook.t
blob835490351c8a4dd9d081e1eb6d4ccfd9d685cf2c
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
18 use Modern::Perl;
20 use Test::More tests => 3;
21 use t::lib::TestBuilder;
22 use t::lib::Mocks;
24 use C4::Circulation;
25 use C4::Reserves;
26 use Koha::DateUtils qw( dt_from_string );
28 my $builder = t::lib::TestBuilder->new;
30 my $library = $builder->build( { source => 'Branch' } );
32 #Transfert on unknown barcode
33 my $item = $builder->build_sample_item();
34 my $badbc = $item->barcode;
35 $item->delete;
37 my ( $dotransfer, $messages ) = C4::Circulation::transferbook( $library->{branchcode}, $badbc );
38 is( $dotransfer, 0, "Can't transfer a bad barcode");
39 is_deeply( $messages, { BadBarcode => $badbc }, "We got the expected barcode");
41 subtest 'transfer an issued item' => sub {
42 plan tests => 3;
44 my $library = $builder->build_object( { class => 'Koha::Libraries' } )->store;
45 t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode } );
47 my $patron = $builder->build_object(
49 class => 'Koha::Patrons',
50 value => { branchcode => $library->branchcode }
54 my $item = $builder->build_sample_item(
56 library => $library->branchcode,
60 my $dt_to = dt_from_string();
61 my $issue = AddIssue( $patron->unblessed, $item->barcode, $dt_to );
63 # We are making sure there is no regression, feel free to change the behavior if needed.
64 # * WasReturned does not seem like a variable that should contain a borrowernumber
65 # * Should we return even if the transfer did not happen? (same branches)
66 my ($dotransfer, $messages) = transferbook( $library->branchcode, $item->barcode );
67 is( $messages->{WasReturned}, $patron->borrowernumber, 'transferbook should have return a WasReturned flag is the item was issued before the transferbook call');
69 AddReserve({
70 branchcode => $item->homebranch,
71 borrowernumber => $patron->borrowernumber,
72 biblionumber => $item->biblionumber,
73 itemnumber => $item->itemnumber,
74 });
75 ($dotransfer, $messages ) = transferbook( $library->branchcode, $item->barcode );
76 is( $messages->{ResFound}->{ResFound}, 'Reserved', "We found the reserve");
77 is( $messages->{ResFound}->{itemnumber}, $item->itemnumber, "We got the reserve info");