Lines 19-26
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 1; |
22 |
use Test::More tests => 2; |
23 |
|
23 |
|
|
|
24 |
use C4::Biblio; |
25 |
use C4::Items; |
24 |
use C4::Reserves; |
26 |
use C4::Reserves; |
25 |
|
27 |
|
26 |
use Koha::Biblios; |
28 |
use Koha::Biblios; |
Lines 52-57
subtest 'holds' => sub {
Link Here
|
52 |
is( $holds->next->borrowernumber, $patron->borrowernumber, '->holds should return the correct hold' ); |
54 |
is( $holds->next->borrowernumber, $patron->borrowernumber, '->holds should return the correct hold' ); |
53 |
}; |
55 |
}; |
54 |
|
56 |
|
|
|
57 |
subtest 'can_be_transferred' => sub { |
58 |
plan tests => 11; |
59 |
|
60 |
t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1); |
61 |
t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype'); |
62 |
|
63 |
my $library1 = $builder->build( { source => 'Branch' } )->{branchcode}; |
64 |
my $library2 = $builder->build( { source => 'Branch' } )->{branchcode}; |
65 |
my $library3 = $builder->build( { source => 'Branch' } )->{branchcode}; |
66 |
my ($bibnum, $title, $bibitemnum) = create_helper_biblio('ONLY1'); |
67 |
my ($item_bibnum, $item_bibitemnum, $itemnumber) |
68 |
= AddItem({ homebranch => $library1, holdingbranch => $library1 }, $bibnum); |
69 |
my $item = Koha::Items->find($itemnumber); |
70 |
my $biblio = Koha::Biblios->find($bibnum); |
71 |
|
72 |
is(Koha::Item::Transfer::Limits->search({ |
73 |
fromBranch => $library1, |
74 |
toBranch => $library2, |
75 |
})->count, 0, 'There are no transfer limits between libraries.'); |
76 |
ok($biblio->can_be_transferred({ to => $library2 }), |
77 |
'Some items of this biblio can be transferred between libraries.'); |
78 |
|
79 |
my $limit = Koha::Item::Transfer::Limit->new({ |
80 |
fromBranch => $library1, |
81 |
toBranch => $library2, |
82 |
itemtype => $item->effective_itemtype, |
83 |
})->store; |
84 |
is(Koha::Item::Transfer::Limits->search({ |
85 |
fromBranch => $library1, |
86 |
toBranch => $library2, |
87 |
})->count, 1, 'Given we have added a transfer limit that applies for all ' |
88 |
.'of this biblio\s items,'); |
89 |
is($biblio->can_be_transferred({ to => $library2 }), 0, |
90 |
'None of the items of biblio can no longer be transferred between ' |
91 |
.'libraries.'); |
92 |
is($biblio->can_be_transferred({ to => $library2, from => $library1 }), 0, |
93 |
'We get the same result also if we pass the from-library parameter.'); |
94 |
$item->holdingbranch($library2)->store; |
95 |
is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given one of the ' |
96 |
.'items is already located at to-library, then the transfer is possible.'); |
97 |
$item->holdingbranch($library1)->store; |
98 |
my ($item_bibnum2, $item_bibitemnum2, $itemnumber2) |
99 |
= AddItem({ homebranch => $library1, holdingbranch => $library3 }, $bibnum); |
100 |
my $item2 = Koha::Items->find($itemnumber2); |
101 |
is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given we added ' |
102 |
.'another item that should have no transfer limits applying on, then ' |
103 |
.'the transfer is possible.'); |
104 |
$item2->holdingbranch($library1)->store; |
105 |
is($biblio->can_be_transferred({ to => $library2 }), 0, 'Given all of items' |
106 |
.' of the biblio are from same, transfer limited library, then transfer' |
107 |
.' is not possible.'); |
108 |
eval { $biblio->can_be_transferred({ to => undef }); }; |
109 |
is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when no' |
110 |
.' library given.'); |
111 |
eval { $biblio->can_be_transferred({ to => 'heaven' }); }; |
112 |
is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when' |
113 |
.' invalid library is given.'); |
114 |
eval { $biblio->can_be_transferred({ to => $library2, from => 'hell' }); }; |
115 |
is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when' |
116 |
.' invalid library is given.'); |
117 |
}; |
118 |
|
55 |
$schema->storage->txn_rollback; |
119 |
$schema->storage->txn_rollback; |
56 |
|
120 |
|
|
|
121 |
|
122 |
# Helper method to set up a Biblio. |
123 |
sub create_helper_biblio { |
124 |
my $itemtype = shift; |
125 |
my ($bibnum, $title, $bibitemnum); |
126 |
my $bib = MARC::Record->new(); |
127 |
$title = 'Silence in the library'; |
128 |
$bib->append_fields( |
129 |
MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'), |
130 |
MARC::Field->new('245', ' ', ' ', a => $title), |
131 |
MARC::Field->new('942', ' ', ' ', c => $itemtype), |
132 |
); |
133 |
return ($bibnum, $title, $bibitemnum) = AddBiblio($bib, ''); |
134 |
} |
135 |
|
57 |
1; |
136 |
1; |
58 |
- |
|
|