Lines 19-32
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 6; |
22 |
use Test::More tests => 7; |
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 82-87
subtest 'biblio' => sub {
Link Here
|
82 |
is( $biblio->biblionumber, $retrieved_item_1->biblionumber, 'Koha::Item->biblio should return the correct biblio' ); |
84 |
is( $biblio->biblionumber, $retrieved_item_1->biblionumber, 'Koha::Item->biblio should return the correct biblio' ); |
83 |
}; |
85 |
}; |
84 |
|
86 |
|
|
|
87 |
subtest 'can_be_transferred' => sub { |
88 |
plan tests => 8; |
89 |
|
90 |
t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1); |
91 |
t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype'); |
92 |
|
93 |
my $library1 = $builder->build( { source => 'Branch' } )->{branchcode}; |
94 |
my $library2 = $builder->build( { source => 'Branch' } )->{branchcode}; |
95 |
my $item = Koha::Item->new({ |
96 |
biblionumber => $biblioitem->{biblionumber}, |
97 |
biblioitemnumber => $biblioitem->{biblioitemnumber}, |
98 |
homebranch => $library1, |
99 |
holdingbranch => $library1, |
100 |
itype => 'test', |
101 |
barcode => "newbarcode", |
102 |
})->store; |
103 |
$nb_of_items++; |
104 |
|
105 |
is(Koha::Item::Transfer::Limits->search({ |
106 |
fromBranch => $library1, |
107 |
toBranch => $library2, |
108 |
})->count, 0, 'There are no transfer limits between libraries.'); |
109 |
ok($item->can_be_transferred($library2), |
110 |
'Item can be transferred between libraries.'); |
111 |
|
112 |
my $limit = Koha::Item::Transfer::Limit->new({ |
113 |
fromBranch => $library1, |
114 |
toBranch => $library2, |
115 |
itemtype => $item->effective_itemtype, |
116 |
})->store; |
117 |
is(Koha::Item::Transfer::Limits->search({ |
118 |
fromBranch => $library1, |
119 |
toBranch => $library2, |
120 |
})->count, 1, 'Given we have added a transfer limit,'); |
121 |
is($item->can_be_transferred($library2), 0, |
122 |
'Item can no longer be transferred between libraries.'); |
123 |
is($item->can_be_transferred($library2, $library1), 0, |
124 |
'We get the same result also if we pass the from-library parameter.'); |
125 |
eval { $item->can_be_transferred(); }; |
126 |
is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when no library given.'); |
127 |
eval { $item->can_be_transferred('heaven'); }; |
128 |
is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when invalid library is given.'); |
129 |
eval { $item->can_be_transferred($library2, 'hell'); }; |
130 |
is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when invalid library is given.'); |
131 |
}; |
132 |
|
85 |
$retrieved_item_1->delete; |
133 |
$retrieved_item_1->delete; |
86 |
is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted the item' ); |
134 |
is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted the item' ); |
87 |
|
135 |
|
88 |
- |
|
|