Lines 19-32
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 8; |
22 |
use Test::More tests => 9; |
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 118-123
subtest 'checkout' => sub {
Link Here
|
118 |
is( $checkout, undef, 'Koha::Item->checkout should return undef if there is no *current* checkout on this item' ); |
120 |
is( $checkout, undef, 'Koha::Item->checkout should return undef if there is no *current* checkout on this item' ); |
119 |
}; |
121 |
}; |
120 |
|
122 |
|
|
|
123 |
subtest 'can_be_transferred' => sub { |
124 |
plan tests => 8; |
125 |
|
126 |
t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1); |
127 |
t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype'); |
128 |
|
129 |
my $library1 = $builder->build( { source => 'Branch' } )->{branchcode}; |
130 |
my $library2 = $builder->build( { source => 'Branch' } )->{branchcode}; |
131 |
my $item = Koha::Item->new({ |
132 |
biblionumber => $biblioitem->{biblionumber}, |
133 |
biblioitemnumber => $biblioitem->{biblioitemnumber}, |
134 |
homebranch => $library1, |
135 |
holdingbranch => $library1, |
136 |
itype => 'test', |
137 |
barcode => "newbarcode", |
138 |
})->store; |
139 |
$nb_of_items++; |
140 |
|
141 |
is(Koha::Item::Transfer::Limits->search({ |
142 |
fromBranch => $library1, |
143 |
toBranch => $library2, |
144 |
})->count, 0, 'There are no transfer limits between libraries.'); |
145 |
ok($item->can_be_transferred($library2), |
146 |
'Item can be transferred between libraries.'); |
147 |
|
148 |
my $limit = Koha::Item::Transfer::Limit->new({ |
149 |
fromBranch => $library1, |
150 |
toBranch => $library2, |
151 |
itemtype => $item->effective_itemtype, |
152 |
})->store; |
153 |
is(Koha::Item::Transfer::Limits->search({ |
154 |
fromBranch => $library1, |
155 |
toBranch => $library2, |
156 |
})->count, 1, 'Given we have added a transfer limit,'); |
157 |
is($item->can_be_transferred($library2), 0, |
158 |
'Item can no longer be transferred between libraries.'); |
159 |
is($item->can_be_transferred($library2, $library1), 0, |
160 |
'We get the same result also if we pass the from-library parameter.'); |
161 |
eval { $item->can_be_transferred(); }; |
162 |
is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when no library given.'); |
163 |
eval { $item->can_be_transferred('heaven'); }; |
164 |
is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when invalid library is given.'); |
165 |
eval { $item->can_be_transferred($library2, 'hell'); }; |
166 |
is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when invalid library is given.'); |
167 |
}; |
168 |
|
121 |
$retrieved_item_1->delete; |
169 |
$retrieved_item_1->delete; |
122 |
is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted the item' ); |
170 |
is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted the item' ); |
123 |
|
171 |
|
124 |
- |
|
|