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;
36 my $schema = Koha::Database->schema;
37 $schema->storage->txn_begin;
38 my $builder = t::lib::TestBuilder->new;
40 my $library = $builder->build({ source => 'Branch' });
41 my $itemtype = $builder->build({ source => 'Itemtype' })->{itemtype};
42 my $patron_category = $builder->build({ source => 'Category' });
44 t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} });
46 my $borrowernumber = Koha::Patron->new({
47 firstname => 'my firstname',
48 surname => 'my surname',
49 categorycode => $patron_category->{categorycode},
50 branchcode => $library->{branchcode},
51 })->store->borrowernumber;
53 my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
54 my $record = MARC::Record->new();
55 my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' );
57 my $item = $builder->build_sample_item(
59 biblionumber => $biblionumber,
60 library => $library->{branchcode},
65 is ( IsItemIssued( $item->itemnumber ), 0, "item is not on loan at first" );
67 AddIssue($borrower, $item->barcode);
68 is ( IsItemIssued( $item->itemnumber ), 1, "item is now on loan" );
71 DelItemCheck( $biblionumber, $item->itemnumber),
73 'item that is on loan cannot be deleted',
76 AddReturn($item->barcode, $library->{branchcode});
77 is ( IsItemIssued( $item->itemnumber ), 0, "item has been returned" );
80 DelItemCheck( $biblionumber, $item->itemnumber),
82 'item that is not on loan can be deleted',
85 $schema->storage->txn_rollback;