Bug 17653: Remove itemtype-related t/db_dependent/Circulation* warnings
[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({ source => 'Branch' });
39 my $itemtype = $builder->build({ source => 'Itemtype' })->{itemtype};
40
41 C4::Context->_new_userenv('DUMMY SESSION');
42 C4::Context->set_userenv(
43     undef, undef, undef, undef, undef,
44     $library->{branchcode},
45     $library->{branchname}
46 );
47
48
49
50 my $borrowernumber = AddMember(
51     firstname =>  'my firstname',
52     surname => 'my surname',
53     categorycode => 'S',
54     branchcode => $library->{branchcode},
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(
62     {   homebranch    => $library->{branchcode},
63         holdingbranch => $library->{branchcode},
64         barcode       => 'i_dont_exist',
65         itype         => $itemtype
66     },
67     $biblionumber
68 );
69
70 my $item = GetItem( $itemnumber );
71
72 is ( IsItemIssued( $item->{itemnumber} ), 0, "item is not on loan at first" );
73
74 AddIssue($borrower, 'i_dont_exist');
75 is ( IsItemIssued( $item->{itemnumber} ), 1, "item is now on loan" );
76
77 is(
78     DelItemCheck( $biblionumber, $itemnumber),
79     'book_on_loan',
80     'item that is on loan cannot be deleted',
81 );
82
83 AddReturn('i_dont_exist', $library->{branchcode});
84 is ( IsItemIssued( $item->{itemnumber} ), 0, "item has been returned" );
85
86 is(
87     DelItemCheck( $biblionumber, $itemnumber),
88     1,
89     'item that is not on loan can be deleted',
90 );
91
92 $schema->storage->txn_rollback;
93
94 1;