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>.
20 use Test::More tests => 5;
30 use t::lib::TestBuilder;
34 my $schema = Koha::Database->schema;
35 $schema->storage->txn_begin;
36 my $builder = t::lib::TestBuilder->new;
38 my $library = $builder->build({ source => 'Branch' });
39 my $itemtype = $builder->build({ source => 'Itemtype' })->{itemtype};
41 C4::Context->_new_userenv('DUMMY SESSION');
42 C4::Context->set_userenv(
43 undef, undef, undef, undef, undef,
44 $library->{branchcode},
45 $library->{branchname}
50 my $borrowernumber = AddMember(
51 firstname => 'my firstname',
52 surname => 'my surname',
54 branchcode => $library->{branchcode},
57 my $borrower = GetMember( borrowernumber => $borrowernumber );
58 my $record = MARC::Record->new();
59 my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' );
61 my ( undef, undef, $itemnumber ) = AddItem(
62 { homebranch => $library->{branchcode},
63 holdingbranch => $library->{branchcode},
64 barcode => 'i_dont_exist',
70 my $item = GetItem( $itemnumber );
72 is ( IsItemIssued( $item->{itemnumber} ), 0, "item is not on loan at first" );
74 AddIssue($borrower, 'i_dont_exist');
75 is ( IsItemIssued( $item->{itemnumber} ), 1, "item is now on loan" );
78 DelItemCheck( $biblionumber, $itemnumber),
80 'item that is on loan cannot be deleted',
83 AddReturn('i_dont_exist', $library->{branchcode});
84 is ( IsItemIssued( $item->{itemnumber} ), 0, "item has been returned" );
87 DelItemCheck( $biblionumber, $itemnumber),
89 'item that is not on loan can be deleted',
92 $schema->storage->txn_rollback;