|
Lines 19-26
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 2; |
22 |
use Test::More tests => 3; |
| 23 |
|
23 |
|
|
|
24 |
use C4::Biblio; |
| 25 |
use C4::Items; |
| 24 |
use C4::Reserves; |
26 |
use C4::Reserves; |
| 25 |
|
27 |
|
| 26 |
use Koha::DateUtils qw( dt_from_string ); |
28 |
use Koha::DateUtils qw( dt_from_string ); |
|
Lines 80-85
subtest 'subscriptions' => sub {
Link Here
|
| 80 |
is( $subscriptions->count, 2, 'Koha::Biblio->subscriptions should return the correct number of subscriptions'); |
82 |
is( $subscriptions->count, 2, 'Koha::Biblio->subscriptions should return the correct number of subscriptions'); |
| 81 |
}; |
83 |
}; |
| 82 |
|
84 |
|
|
|
85 |
subtest 'can_be_transferred' => sub { |
| 86 |
plan tests => 11; |
| 87 |
|
| 88 |
t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1); |
| 89 |
t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype'); |
| 90 |
|
| 91 |
my $library1 = $builder->build( { source => 'Branch' } )->{branchcode}; |
| 92 |
my $library2 = $builder->build( { source => 'Branch' } )->{branchcode}; |
| 93 |
my $library3 = $builder->build( { source => 'Branch' } )->{branchcode}; |
| 94 |
my ($bibnum, $title, $bibitemnum) = create_helper_biblio('ONLY1'); |
| 95 |
my ($item_bibnum, $item_bibitemnum, $itemnumber) |
| 96 |
= AddItem({ homebranch => $library1, holdingbranch => $library1 }, $bibnum); |
| 97 |
my $item = Koha::Items->find($itemnumber); |
| 98 |
my $biblio = Koha::Biblios->find($bibnum); |
| 99 |
|
| 100 |
is(Koha::Item::Transfer::Limits->search({ |
| 101 |
fromBranch => $library1, |
| 102 |
toBranch => $library2, |
| 103 |
})->count, 0, 'There are no transfer limits between libraries.'); |
| 104 |
ok($biblio->can_be_transferred({ to => $library2 }), |
| 105 |
'Some items of this biblio can be transferred between libraries.'); |
| 106 |
|
| 107 |
my $limit = Koha::Item::Transfer::Limit->new({ |
| 108 |
fromBranch => $library1, |
| 109 |
toBranch => $library2, |
| 110 |
itemtype => $item->effective_itemtype, |
| 111 |
})->store; |
| 112 |
is(Koha::Item::Transfer::Limits->search({ |
| 113 |
fromBranch => $library1, |
| 114 |
toBranch => $library2, |
| 115 |
})->count, 1, 'Given we have added a transfer limit that applies for all ' |
| 116 |
.'of this biblio\s items,'); |
| 117 |
is($biblio->can_be_transferred({ to => $library2 }), 0, |
| 118 |
'None of the items of biblio can no longer be transferred between ' |
| 119 |
.'libraries.'); |
| 120 |
is($biblio->can_be_transferred({ to => $library2, from => $library1 }), 0, |
| 121 |
'We get the same result also if we pass the from-library parameter.'); |
| 122 |
$item->holdingbranch($library2)->store; |
| 123 |
is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given one of the ' |
| 124 |
.'items is already located at to-library, then the transfer is possible.'); |
| 125 |
$item->holdingbranch($library1)->store; |
| 126 |
my ($item_bibnum2, $item_bibitemnum2, $itemnumber2) |
| 127 |
= AddItem({ homebranch => $library1, holdingbranch => $library3 }, $bibnum); |
| 128 |
my $item2 = Koha::Items->find($itemnumber2); |
| 129 |
is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given we added ' |
| 130 |
.'another item that should have no transfer limits applying on, then ' |
| 131 |
.'the transfer is possible.'); |
| 132 |
$item2->holdingbranch($library1)->store; |
| 133 |
is($biblio->can_be_transferred({ to => $library2 }), 0, 'Given all of items' |
| 134 |
.' of the biblio are from same, transfer limited library, then transfer' |
| 135 |
.' is not possible.'); |
| 136 |
eval { $biblio->can_be_transferred({ to => undef }); }; |
| 137 |
is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when no' |
| 138 |
.' library given.'); |
| 139 |
eval { $biblio->can_be_transferred({ to => 'heaven' }); }; |
| 140 |
is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when' |
| 141 |
.' invalid library is given.'); |
| 142 |
eval { $biblio->can_be_transferred({ to => $library2, from => 'hell' }); }; |
| 143 |
is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when' |
| 144 |
.' invalid library is given.'); |
| 145 |
}; |
| 146 |
|
| 83 |
$schema->storage->txn_rollback; |
147 |
$schema->storage->txn_rollback; |
| 84 |
|
148 |
|
|
|
149 |
# Helper method to set up a Biblio. |
| 150 |
sub create_helper_biblio { |
| 151 |
my $itemtype = shift; |
| 152 |
my ($bibnum, $title, $bibitemnum); |
| 153 |
my $bib = MARC::Record->new(); |
| 154 |
$title = 'Silence in the library'; |
| 155 |
$bib->append_fields( |
| 156 |
MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'), |
| 157 |
MARC::Field->new('245', ' ', ' ', a => $title), |
| 158 |
MARC::Field->new('942', ' ', ' ', c => $itemtype), |
| 159 |
); |
| 160 |
return ($bibnum, $title, $bibitemnum) = AddBiblio($bib, ''); |
| 161 |
} |
| 162 |
|
| 85 |
1; |
163 |
1; |
| 86 |
- |
|
|