3 # Copyright 2020 Koha Development team
5 # This file is part of Koha
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 use t::lib::TestBuilder;
26 use Test::More tests => 2;
29 my $schema = Koha::Database->new->schema;
30 my $builder = t::lib::TestBuilder->new;
32 subtest 'item relation tests' => sub {
35 $schema->storage->txn_begin;
37 my $item = $builder->build_sample_item();
38 my $transfer = $builder->build_object(
40 class => 'Koha::Item::Transfers',
42 itemnumber => $item->itemnumber,
47 my $transfer_item = $transfer->item;
48 is( ref( $transfer_item ), 'Koha::Item', 'Koha::Item::Transfer->item should return a Koha::Item' );
49 is( $transfer_item->itemnumber, $item->itemnumber, 'Koha::Item::Transfer->item should return the correct item' );
51 $schema->storage->txn_rollback;
54 subtest 'transit tests' => sub {
57 $schema->storage->txn_begin;
59 my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
60 my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
61 my $item = $builder->build_sample_item(
63 homebranch => $library1->branchcode,
64 holdingbranch => $library2->branchcode,
69 my $transfer = $builder->build_object(
71 class => 'Koha::Item::Transfers',
73 itemnumber => $item->itemnumber,
74 frombranch => $library2->branchcode,
75 tobranch => $library1->branchcode,
80 is( ref($transfer), 'Koha::Item::Transfer', 'Mock transfer added' );
82 # Item checked out should result in failure
83 my $checkout = $builder->build_object(
85 class => 'Koha::Checkouts',
87 itemnumber => $item->itemnumber
91 is( ref($checkout), 'Koha::Checkout', 'Mock checkout added' );
93 throws_ok { $transfer->transit() }
94 'Koha::Exceptions::Item::Transfer::Out',
95 'Exception thrown if item is checked out';
100 $item->set({ location => 'CART', permanent_location => 'TEST' })->store();
101 is ( $item->location, 'CART', 'Item location set to CART');
102 $transfer->discard_changes;
103 $transfer->transit();
104 $item->discard_changes;
105 is ( $item->location, 'TEST', 'Item location correctly restored to match permanent location');
108 ok( $transfer->datesent, 'Transit set the datesent for the transfer' );
111 ok ( $item->datelastseen, 'Transit set item datelastseen date');
113 $schema->storage->txn_rollback;