Lines 84-118
subtest 'subscriptions' => sub {
Link Here
|
84 |
}; |
84 |
}; |
85 |
|
85 |
|
86 |
subtest 'can_be_transferred' => sub { |
86 |
subtest 'can_be_transferred' => sub { |
87 |
plan tests => 11; |
87 |
plan tests => 8; |
88 |
|
88 |
|
89 |
t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1); |
89 |
t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1); |
90 |
t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype'); |
90 |
t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype'); |
91 |
|
91 |
|
92 |
my $library1 = $builder->build( { source => 'Branch' } )->{branchcode}; |
92 |
my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); |
93 |
my $library2 = $builder->build( { source => 'Branch' } )->{branchcode}; |
93 |
my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); |
94 |
my $library3 = $builder->build( { source => 'Branch' } )->{branchcode}; |
94 |
my $library3 = $builder->build_object( { class => 'Koha::Libraries' } ); |
95 |
my ($bibnum, $title, $bibitemnum) = create_helper_biblio('ONLY1'); |
95 |
my ($bibnum, $title, $bibitemnum) = create_helper_biblio('ONLY1'); |
96 |
my ($item_bibnum, $item_bibitemnum, $itemnumber) |
96 |
my ($item_bibnum, $item_bibitemnum, $itemnumber) |
97 |
= AddItem({ homebranch => $library1, holdingbranch => $library1 }, $bibnum); |
97 |
= AddItem({ homebranch => $library1->branchcode, holdingbranch => $library1->branchcode }, $bibnum); |
98 |
my $item = Koha::Items->find($itemnumber); |
98 |
my $item = Koha::Items->find($itemnumber); |
99 |
my $biblio = Koha::Biblios->find($bibnum); |
99 |
my $biblio = Koha::Biblios->find($bibnum); |
100 |
|
100 |
|
101 |
is(Koha::Item::Transfer::Limits->search({ |
101 |
is(Koha::Item::Transfer::Limits->search({ |
102 |
fromBranch => $library1, |
102 |
fromBranch => $library1->branchcode, |
103 |
toBranch => $library2, |
103 |
toBranch => $library2->branchcode, |
104 |
})->count, 0, 'There are no transfer limits between libraries.'); |
104 |
})->count, 0, 'There are no transfer limits between libraries.'); |
105 |
ok($biblio->can_be_transferred({ to => $library2 }), |
105 |
ok($biblio->can_be_transferred({ to => $library2 }), |
106 |
'Some items of this biblio can be transferred between libraries.'); |
106 |
'Some items of this biblio can be transferred between libraries.'); |
107 |
|
107 |
|
108 |
my $limit = Koha::Item::Transfer::Limit->new({ |
108 |
my $limit = Koha::Item::Transfer::Limit->new({ |
109 |
fromBranch => $library1, |
109 |
fromBranch => $library1->branchcode, |
110 |
toBranch => $library2, |
110 |
toBranch => $library2->branchcode, |
111 |
itemtype => $item->effective_itemtype, |
111 |
itemtype => $item->effective_itemtype, |
112 |
})->store; |
112 |
})->store; |
113 |
is(Koha::Item::Transfer::Limits->search({ |
113 |
is(Koha::Item::Transfer::Limits->search({ |
114 |
fromBranch => $library1, |
114 |
fromBranch => $library1->branchcode, |
115 |
toBranch => $library2, |
115 |
toBranch => $library2->branchcode, |
116 |
})->count, 1, 'Given we have added a transfer limit that applies for all ' |
116 |
})->count, 1, 'Given we have added a transfer limit that applies for all ' |
117 |
.'of this biblio\s items,'); |
117 |
.'of this biblio\s items,'); |
118 |
is($biblio->can_be_transferred({ to => $library2 }), 0, |
118 |
is($biblio->can_be_transferred({ to => $library2 }), 0, |
Lines 120-148
subtest 'can_be_transferred' => sub {
Link Here
|
120 |
.'libraries.'); |
120 |
.'libraries.'); |
121 |
is($biblio->can_be_transferred({ to => $library2, from => $library1 }), 0, |
121 |
is($biblio->can_be_transferred({ to => $library2, from => $library1 }), 0, |
122 |
'We get the same result also if we pass the from-library parameter.'); |
122 |
'We get the same result also if we pass the from-library parameter.'); |
123 |
$item->holdingbranch($library2)->store; |
123 |
$item->holdingbranch($library2->branchcode)->store; |
124 |
is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given one of the ' |
124 |
is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given one of the ' |
125 |
.'items is already located at to-library, then the transfer is possible.'); |
125 |
.'items is already located at to-library, then the transfer is possible.'); |
126 |
$item->holdingbranch($library1)->store; |
126 |
$item->holdingbranch($library1->branchcode)->store; |
127 |
my ($item_bibnum2, $item_bibitemnum2, $itemnumber2) |
127 |
my ($item_bibnum2, $item_bibitemnum2, $itemnumber2) |
128 |
= AddItem({ homebranch => $library1, holdingbranch => $library3 }, $bibnum); |
128 |
= AddItem({ homebranch => $library1->branchcode, holdingbranch => $library3->branchcode }, $bibnum); |
129 |
my $item2 = Koha::Items->find($itemnumber2); |
129 |
my $item2 = Koha::Items->find($itemnumber2); |
130 |
is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given we added ' |
130 |
is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given we added ' |
131 |
.'another item that should have no transfer limits applying on, then ' |
131 |
.'another item that should have no transfer limits applying on, then ' |
132 |
.'the transfer is possible.'); |
132 |
.'the transfer is possible.'); |
133 |
$item2->holdingbranch($library1)->store; |
133 |
$item2->holdingbranch($library1->branchcode)->store; |
134 |
is($biblio->can_be_transferred({ to => $library2 }), 0, 'Given all of items' |
134 |
is($biblio->can_be_transferred({ to => $library2 }), 0, 'Given all of items' |
135 |
.' of the biblio are from same, transfer limited library, then transfer' |
135 |
.' of the biblio are from same, transfer limited library, then transfer' |
136 |
.' is not possible.'); |
136 |
.' is not possible.'); |
137 |
throws_ok { $biblio->can_be_transferred({ to => undef }); } |
|
|
138 |
'Koha::Exceptions::Library::NotFound', |
139 |
'Exception thrown when no library given.'; |
140 |
throws_ok { $biblio->can_be_transferred({ to => 'heaven' }); } |
141 |
'Koha::Exceptions::Library::NotFound', |
142 |
'Exception thrown when invalid library is given.'; |
143 |
throws_ok { $biblio->can_be_transferred({ to => $library2, from => 'hell' }); } |
144 |
'Koha::Exceptions::Library::NotFound', |
145 |
'Exception thrown when invalid library is given.'; |
146 |
}; |
137 |
}; |
147 |
|
138 |
|
148 |
$schema->storage->txn_rollback; |
139 |
$schema->storage->txn_rollback; |