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;
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 t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} });
45 my $borrowernumber = Koha::Patron->new({
46 firstname => 'my firstname',
47 surname => 'my surname',
48 categorycode => $patron_category->{categorycode},
49 branchcode => $library->{branchcode},
50 })->store->borrowernumber;
52 my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
53 my $record = MARC::Record->new();
54 my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' );
56 my ( undef, undef, $itemnumber ) = AddItem(
57 { homebranch => $library->{branchcode},
58 holdingbranch => $library->{branchcode},
59 barcode => 'i_dont_exist',
65 my $item = GetItem( $itemnumber );
67 is ( IsItemIssued( $item->{itemnumber} ), 0, "item is not on loan at first" );
69 AddIssue($borrower, 'i_dont_exist');
70 is ( IsItemIssued( $item->{itemnumber} ), 1, "item is now on loan" );
73 DelItemCheck( $biblionumber, $itemnumber),
75 'item that is on loan cannot be deleted',
78 AddReturn('i_dont_exist', $library->{branchcode});
79 is ( IsItemIssued( $item->{itemnumber} ), 0, "item has been returned" );
82 DelItemCheck( $biblionumber, $itemnumber),
84 'item that is not on loan can be deleted',
87 $schema->storage->txn_rollback;