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;
31 use t::lib::TestBuilder;
35 my $schema = Koha::Database->schema;
36 $schema->storage->txn_begin;
37 my $builder = t::lib::TestBuilder->new;
39 my $library = $builder->build({ source => 'Branch' });
40 my $itemtype = $builder->build({ source => 'Itemtype' })->{itemtype};
41 my $patron_category = $builder->build({ source => 'Category' });
43 C4::Context->_new_userenv('DUMMY SESSION');
44 C4::Context->set_userenv(
45 undef, undef, undef, undef, undef,
46 $library->{branchcode},
47 $library->{branchname}
52 my $borrowernumber = AddMember(
53 firstname => 'my firstname',
54 surname => 'my surname',
55 categorycode => $patron_category->{categorycode},
56 branchcode => $library->{branchcode},
59 my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
60 my $record = MARC::Record->new();
61 my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' );
63 my ( undef, undef, $itemnumber ) = AddItem(
64 { homebranch => $library->{branchcode},
65 holdingbranch => $library->{branchcode},
66 barcode => 'i_dont_exist',
72 my $item = GetItem( $itemnumber );
74 is ( IsItemIssued( $item->{itemnumber} ), 0, "item is not on loan at first" );
76 AddIssue($borrower, 'i_dont_exist');
77 is ( IsItemIssued( $item->{itemnumber} ), 1, "item is now on loan" );
80 DelItemCheck( $biblionumber, $itemnumber),
82 'item that is on loan cannot be deleted',
85 AddReturn('i_dont_exist', $library->{branchcode});
86 is ( IsItemIssued( $item->{itemnumber} ), 0, "item has been returned" );
89 DelItemCheck( $biblionumber, $itemnumber),
91 'item that is not on loan can be deleted',
94 $schema->storage->txn_rollback;