Bug 14504: Changes missed while fixing patches
[koha.git] / t / db_dependent / Circulation / IsItemIssued.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 => 5;
21 use Test::MockModule;
22
23 use C4::Biblio;
24 use C4::Circulation;
25 use C4::Items;
26 use C4::Members;
27 use Koha::Database;
28 use Koha::DateUtils;
29
30 use t::lib::TestBuilder;
31
32 use MARC::Record;
33
34 my $schema = Koha::Database->schema;
35 $schema->storage->txn_begin;
36 my $builder = t::lib::TestBuilder->new;
37
38 my $library = $builder->build({
39     source => 'Branch',
40 });
41
42 my $module = new Test::MockModule('C4::Context');
43 $module->mock('userenv', sub {
44     {
45        branch => $library->{branchcode}
46     }
47 });
48
49 my $borrowernumber = AddMember(
50     firstname =>  'my firstname',
51     surname => 'my surname',
52     categorycode => 'S',
53     branchcode => $library->{branchcode},
54 );
55
56
57 my $borrower = GetMember( borrowernumber => $borrowernumber );
58 my $record = MARC::Record->new();
59 my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' );
60
61 my ( undef, undef, $itemnumber ) = AddItem( { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, barcode => 'i_dont_exist' }, $biblionumber );
62 my $item = GetItem( $itemnumber );
63
64 is ( IsItemIssued( $item->{itemnumber} ), 0, "item is not on loan at first" );
65
66 AddIssue($borrower, 'i_dont_exist');
67 is ( IsItemIssued( $item->{itemnumber} ), 1, "item is now on loan" );
68
69 is(
70     DelItemCheck( $biblionumber, $itemnumber),
71     'book_on_loan',
72     'item that is on loan cannot be deleted',
73 );
74
75 AddReturn('i_dont_exist', $library->{branchcode});
76 is ( IsItemIssued( $item->{itemnumber} ), 0, "item has been returned" );
77
78 is(
79     DelItemCheck( $biblionumber, $itemnumber),
80     1,
81     'item that is not on loan can be deleted',
82 );
83
84 $schema->storage->txn_rollback;
85
86 1;