Bug 14778: Make Barcodes_ValueBuilder.t db dependent
[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 C4::Branch;
24 use C4::Circulation;
25 use C4::Members;
26 use t::lib::Mocks;
27
28 my $dbh = C4::Context->dbh;
29 $dbh->{AutoCommit} = 0;
30 $dbh->{RaiseError} = 1;
31
32 t::lib::Mocks::mock_preference('AnonymousPatron', '');
33
34 my $branchcode = 'B';
35 ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' });
36
37 my $categorycode = 'C';
38 $dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
39
40 my %item_branch_infos = (
41     homebranch => $branchcode,
42     holdingbranch => $branchcode,
43 );
44
45 my $borrowernumber = AddMember( categorycode => $categorycode, branchcode => $branchcode );
46
47 eval { C4::Circulation::MarkIssueReturned( $borrowernumber, 'itemnumber', 'dropbox_branch', 'returndate', 2 ) };
48 like ( $@, qr<Fatal error: the patron \(\d+\) .* AnonymousPatron>, );
49
50 my $anonymous_borrowernumber = AddMember( categorycode => $categorycode, branchcode => $branchcode );
51 t::lib::Mocks::mock_preference('AnonymousPatron', $anonymous_borrowernumber);
52 # The next call will raise an error, because data are not correctly set
53 $dbh->{PrintError} = 0;
54 eval { C4::Circulation::MarkIssueReturned( $borrowernumber, 'itemnumber', 'dropbox_branch', 'returndate', 2 ) };
55 unlike ( $@, qr<Fatal error: the patron \(\d+\) .* AnonymousPatron>, );