|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# Copyright 2020 Koha Development team |
| 4 |
# |
| 5 |
# This file is part of Koha |
| 6 |
# |
| 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. |
| 11 |
# |
| 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. |
| 16 |
# |
| 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>. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
|
| 22 |
use Koha::Database; |
| 23 |
|
| 24 |
use t::lib::TestBuilder; |
| 25 |
|
| 26 |
use Test::More tests => 1; |
| 27 |
use Test::Exception; |
| 28 |
|
| 29 |
my $schema = Koha::Database->new->schema; |
| 30 |
my $builder = t::lib::TestBuilder->new; |
| 31 |
|
| 32 |
subtest 'transit tests' => sub { |
| 33 |
plan tests => 7; |
| 34 |
|
| 35 |
$schema->storage->txn_begin; |
| 36 |
|
| 37 |
my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 38 |
my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 39 |
my $item = $builder->build_sample_item( |
| 40 |
{ |
| 41 |
homebranch => $library1->branchcode, |
| 42 |
holdingbranch => $library2->branchcode, |
| 43 |
datelastseen => undef |
| 44 |
} |
| 45 |
); |
| 46 |
|
| 47 |
my $transfer = $builder->build_object( |
| 48 |
{ |
| 49 |
class => 'Koha::Item::Transfers', |
| 50 |
value => { |
| 51 |
itemnumber => $item->itemnumber, |
| 52 |
frombranch => $library2->branchcode, |
| 53 |
tobranch => $library1->branchcode, |
| 54 |
reason => 'Manual' |
| 55 |
} |
| 56 |
} |
| 57 |
); |
| 58 |
is( ref($transfer), 'Koha::Item::Transfer', 'Mock transfer added' ); |
| 59 |
|
| 60 |
# Item checked out should result in failure |
| 61 |
my $checkout = $builder->build_object( |
| 62 |
{ |
| 63 |
class => 'Koha::Checkouts', |
| 64 |
value => { |
| 65 |
itemnumber => $item->itemnumber |
| 66 |
} |
| 67 |
} |
| 68 |
); |
| 69 |
is( ref($checkout), 'Koha::Checkout', 'Mock checkout added' ); |
| 70 |
|
| 71 |
throws_ok { $transfer->transit() } |
| 72 |
'Koha::Exceptions::Item::Transfer::Out', |
| 73 |
'Exception thrown if item is checked out'; |
| 74 |
|
| 75 |
$checkout->delete; |
| 76 |
|
| 77 |
# CartToShelf test |
| 78 |
$item->set({ location => 'CART', permanent_location => 'TEST' })->store(); |
| 79 |
is ( $item->location, 'CART', 'Item location set to CART'); |
| 80 |
$transfer->discard_changes; |
| 81 |
$transfer->transit(); |
| 82 |
$item->discard_changes; |
| 83 |
is ( $item->location, 'TEST', 'Item location correctly restored to match permanent location'); |
| 84 |
|
| 85 |
# Transit state set |
| 86 |
ok( $transfer->datesent, 'Transit set the datesent for the transfer' ); |
| 87 |
|
| 88 |
# Last seen |
| 89 |
ok ( $item->datelastseen, 'Transit set item datelastseen date'); |
| 90 |
|
| 91 |
$schema->storage->txn_rollback; |
| 92 |
}; |