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;
23 use C4::Circulation qw( IsItemIssued AddIssue AddReturn );
25 use C4::Biblio qw( AddBiblio );
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 $item = $builder->build_sample_item(
58 biblionumber => $biblionumber,
59 library => $library->{branchcode},
64 is ( IsItemIssued( $item->itemnumber ), 0, "item is not on loan at first" );
66 AddIssue($borrower, $item->barcode);
67 is ( IsItemIssued( $item->itemnumber ), 1, "item is now on loan" );
70 @{$item->safe_delete->messages}[0]->message,
72 'item that is on loan cannot be deleted',
75 AddReturn($item->barcode, $library->{branchcode});
76 is ( IsItemIssued( $item->itemnumber ), 0, "item has been returned" );
78 $item->discard_changes; # FIXME We should not need that
79 # If we do not, $self->checkout in safe_to_delete will not know the item has been checked out
82 'item that is not on loan can be deleted',
85 $schema->storage->txn_rollback;