a3428ebfb8a0dad511da597dc55765064df4bcc8
[koha.git] / t / db_dependent / Circulation / MarkIssueReturned.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
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.
9 #
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.
14 #
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>.
17
18 use Modern::Perl;
19
20 use Test::More tests => 2;
21 use Test::Warn;
22
23 use t::lib::Mocks;
24 use t::lib::TestBuilder;
25
26 use C4::Circulation;
27 use C4::Members;
28 use Koha::Library;
29
30 my $schema = Koha::Database->schema;
31 my $dbh = C4::Context->dbh;
32
33 $schema->storage->txn_begin;
34
35 my $builder = t::lib::TestBuilder->new;
36
37 t::lib::Mocks::mock_preference('AnonymousPatron', '');
38
39 my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode };
40 my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
41
42 my %item_branch_infos = (
43     homebranch => $branchcode,
44     holdingbranch => $branchcode,
45 );
46
47 my $borrowernumber = AddMember( categorycode => $categorycode, branchcode => $branchcode );
48
49 eval { C4::Circulation::MarkIssueReturned( $borrowernumber, 'itemnumber', 'dropbox_branch', 'returndate', 2 ) };
50 like ( $@, qr<Fatal error: the patron \(\d+\) .* AnonymousPatron>, );
51
52 my $anonymous_borrowernumber = AddMember( categorycode => $categorycode, branchcode => $branchcode );
53 t::lib::Mocks::mock_preference('AnonymousPatron', $anonymous_borrowernumber);
54 # The next call will raise an error, because data are not correctly set
55 $dbh->{PrintError} = 0;
56 eval { C4::Circulation::MarkIssueReturned( $borrowernumber, 'itemnumber', 'dropbox_branch', 'returndate', 2 ) };
57 unlike ( $@, qr<Fatal error: the patron \(\d+\) .* AnonymousPatron>, );
58
59 $schema->storage->txn_rollback;
60
61 1;