Lines 19-32
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 5; |
22 |
use Test::More tests => 6; |
23 |
|
23 |
|
24 |
use C4::Circulation; |
24 |
use C4::Circulation; |
25 |
use Koha::Item; |
25 |
use Koha::Item; |
|
|
26 |
use Koha::Item::Transfer::Limits; |
26 |
use Koha::Items; |
27 |
use Koha::Items; |
27 |
use Koha::Database; |
28 |
use Koha::Database; |
28 |
|
29 |
|
29 |
use t::lib::TestBuilder; |
30 |
use t::lib::TestBuilder; |
|
|
31 |
use t::lib::Mocks; |
30 |
|
32 |
|
31 |
my $schema = Koha::Database->new->schema; |
33 |
my $schema = Koha::Database->new->schema; |
32 |
$schema->storage->txn_begin; |
34 |
$schema->storage->txn_begin; |
Lines 74-79
subtest 'get_transfer' => sub {
Link Here
|
74 |
is( $transfer->itemnumber, $new_item_1->itemnumber, 'Koha::Item->get_transfer should return a valid Koha::Item::Transfers object' ); |
76 |
is( $transfer->itemnumber, $new_item_1->itemnumber, 'Koha::Item->get_transfer should return a valid Koha::Item::Transfers object' ); |
75 |
}; |
77 |
}; |
76 |
|
78 |
|
|
|
79 |
subtest 'can_be_transferred' => sub { |
80 |
plan tests => 8; |
81 |
|
82 |
t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1); |
83 |
t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype'); |
84 |
|
85 |
my $library1 = $builder->build( { source => 'Branch' } )->{branchcode}; |
86 |
my $library2 = $builder->build( { source => 'Branch' } )->{branchcode}; |
87 |
my $item = Koha::Item->new({ |
88 |
biblionumber => $biblioitem->{biblionumber}, |
89 |
biblioitemnumber => $biblioitem->{biblioitemnumber}, |
90 |
homebranch => $library1, |
91 |
holdingbranch => $library1, |
92 |
itype => 'test', |
93 |
barcode => "newbarcode", |
94 |
})->store; |
95 |
$nb_of_items++; |
96 |
|
97 |
is(Koha::Item::Transfer::Limits->search({ |
98 |
fromBranch => $library1, |
99 |
toBranch => $library2, |
100 |
})->count, 0, 'There are no transfer limits between libraries.'); |
101 |
ok($item->can_be_transferred($library2), |
102 |
'Item can be transferred between libraries.'); |
103 |
|
104 |
my $limit = Koha::Item::Transfer::Limit->new({ |
105 |
fromBranch => $library1, |
106 |
toBranch => $library2, |
107 |
itemtype => $item->effective_itemtype, |
108 |
})->store; |
109 |
is(Koha::Item::Transfer::Limits->search({ |
110 |
fromBranch => $library1, |
111 |
toBranch => $library2, |
112 |
})->count, 1, 'Given we have added a transfer limit,'); |
113 |
is($item->can_be_transferred($library2), 0, |
114 |
'Item can no longer be transferred between libraries.'); |
115 |
is($item->can_be_transferred($library2, $library1), 0, |
116 |
'We get the same result also if we pass the from-library parameter.'); |
117 |
eval { $item->can_be_transferred(); }; |
118 |
is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when no library given.'); |
119 |
eval { $item->can_be_transferred('heaven'); }; |
120 |
is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when invalid library is given.'); |
121 |
eval { $item->can_be_transferred($library2, 'hell'); }; |
122 |
is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when invalid library is given.'); |
123 |
}; |
124 |
|
77 |
$retrieved_item_1->delete; |
125 |
$retrieved_item_1->delete; |
78 |
is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted the item' ); |
126 |
is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted the item' ); |
79 |
|
127 |
|
80 |
- |
|
|