Lines 18-24
Link Here
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
use utf8; |
19 |
use utf8; |
20 |
|
20 |
|
21 |
use Test::More tests => 51; |
21 |
use Test::More tests => 48; |
22 |
use Test::MockModule; |
22 |
use Test::MockModule; |
23 |
use Test::Deep qw( cmp_deeply ); |
23 |
use Test::Deep qw( cmp_deeply ); |
24 |
|
24 |
|
Lines 4062-4095
subtest 'Filling a hold should cancel existing transfer' => sub {
Link Here
|
4062 |
is( Koha::Item::Transfers->search({ itemnumber => $item->itemnumber, datearrived => undef })->count, 0, "No outstanding transfers when hold is waiting"); |
4062 |
is( Koha::Item::Transfers->search({ itemnumber => $item->itemnumber, datearrived => undef })->count, 0, "No outstanding transfers when hold is waiting"); |
4063 |
}; |
4063 |
}; |
4064 |
|
4064 |
|
4065 |
subtest 'Tests for NoRefundOnLostReturnedItemsAge = undef' => sub { |
4065 |
subtest 'Tests for NoRefundOnLostReturnedItemsAge' => sub { |
4066 |
plan tests => 3; |
|
|
4067 |
|
4068 |
t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee', 1 ); |
4069 |
t::lib::Mocks::mock_preference( 'NoRefundOnLostReturnedItemsAge', undef ); |
4070 |
|
4066 |
|
4071 |
my $lost_on = dt_from_string->subtract( days => 7 )->date; |
4067 |
plan tests => 4; |
4072 |
|
4068 |
|
4073 |
my $library = $builder->build( { source => 'Branch' } ); |
4069 |
t::lib::Mocks::mock_preference('BlockReturnOfLostItems', 0); |
4074 |
my $patron = $builder->build( |
4070 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
|
|
4071 |
my $patron = $builder->build_object( |
4075 |
{ |
4072 |
{ |
4076 |
source => 'Borrower', |
4073 |
class => 'Koha::Patrons', |
4077 |
value => { categorycode => $patron_category->{categorycode} } |
4074 |
value => { categorycode => $patron_category->{categorycode} } |
4078 |
} |
4075 |
} |
4079 |
); |
4076 |
); |
4080 |
|
4077 |
|
4081 |
my $biblionumber = $builder->build_sample_biblio( |
4078 |
my $biblionumber = $builder->build_sample_biblio( |
4082 |
{ |
4079 |
{ |
4083 |
branchcode => $library->{branchcode}, |
4080 |
branchcode => $library->branchcode, |
4084 |
} |
4081 |
} |
4085 |
)->biblionumber; |
4082 |
)->biblionumber; |
4086 |
my $item = $builder->build_sample_item( |
|
|
4087 |
{ |
4088 |
biblionumber => $biblionumber, |
4089 |
library => $library->{branchcode}, |
4090 |
replacementprice => '42.00', |
4091 |
} |
4092 |
); |
4093 |
|
4083 |
|
4094 |
# And the circulation rule |
4084 |
# And the circulation rule |
4095 |
Koha::CirculationRules->search->delete; |
4085 |
Koha::CirculationRules->search->delete; |
Lines 4117-4365
subtest 'Tests for NoRefundOnLostReturnedItemsAge = undef' => sub {
Link Here
|
4117 |
} |
4107 |
} |
4118 |
); |
4108 |
); |
4119 |
|
4109 |
|
4120 |
# Test with NoRefundOnLostReturnedItemsAge disabled |
4110 |
subtest 'NoRefundOnLostReturnedItemsAge = undef' => sub { |
4121 |
my $issue = AddIssue( $patron, $item->barcode ); |
4111 |
plan tests => 3; |
4122 |
LostItem( $item->itemnumber, 'cli', 0 ); |
|
|
4123 |
$item->_result->itemlost(1); |
4124 |
$item->_result->itemlost_on( $lost_on ); |
4125 |
$item->_result->update(); |
4126 |
|
4127 |
my $a = Koha::Account::Lines->find( |
4128 |
{ |
4129 |
itemnumber => $item->id, |
4130 |
borrowernumber => $patron->{borrowernumber} |
4131 |
} |
4132 |
); |
4133 |
ok( $a, "Found accountline for lost fee" ); |
4134 |
is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" ); |
4135 |
my ( $doreturn, $messages ) = AddReturn( $item->barcode, $library->{branchcode}, undef, dt_from_string ); |
4136 |
$a = Koha::Account::Lines->find( $a->id ); |
4137 |
is( $a->amountoutstanding + 0, 0, "Lost fee was refunded" ); |
4138 |
}; |
4139 |
|
4140 |
subtest 'Tests for NoRefundOnLostReturnedItemsAge > length of days item has been lost' => sub { |
4141 |
plan tests => 3; |
4142 |
|
4143 |
t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee', 1 ); |
4144 |
t::lib::Mocks::mock_preference( 'NoRefundOnLostReturnedItemsAge', 7 ); |
4145 |
|
4146 |
my $lost_on = dt_from_string->subtract( days => 6 )->date; |
4147 |
|
4112 |
|
4148 |
my $library = $builder->build( { source => 'Branch' } ); |
4113 |
t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee', 1 ); |
4149 |
my $patron = $builder->build( |
4114 |
t::lib::Mocks::mock_preference( 'NoRefundOnLostReturnedItemsAge', undef ); |
4150 |
{ |
|
|
4151 |
source => 'Borrower', |
4152 |
value => { categorycode => $patron_category->{categorycode} } |
4153 |
} |
4154 |
); |
4155 |
|
4115 |
|
4156 |
my $biblionumber = $builder->build_sample_biblio( |
4116 |
my $lost_on = dt_from_string->subtract( days => 7 )->date; |
4157 |
{ |
|
|
4158 |
branchcode => $library->{branchcode}, |
4159 |
} |
4160 |
)->biblionumber; |
4161 |
my $item = $builder->build_sample_item( |
4162 |
{ |
4163 |
biblionumber => $biblionumber, |
4164 |
library => $library->{branchcode}, |
4165 |
replacementprice => '42.00', |
4166 |
} |
4167 |
); |
4168 |
|
4117 |
|
4169 |
# And the circulation rule |
4118 |
my $item = $builder->build_sample_item( |
4170 |
Koha::CirculationRules->search->delete; |
4119 |
{ |
4171 |
Koha::CirculationRules->set_rules( |
4120 |
biblionumber => $biblionumber, |
4172 |
{ |
4121 |
library => $library->branchcode, |
4173 |
categorycode => undef, |
4122 |
replacementprice => '42', |
4174 |
itemtype => undef, |
|
|
4175 |
branchcode => undef, |
4176 |
rules => { |
4177 |
issuelength => 14, |
4178 |
lengthunit => 'days', |
4179 |
} |
4180 |
} |
4181 |
); |
4182 |
$builder->build( |
4183 |
{ |
4184 |
source => 'CirculationRule', |
4185 |
value => { |
4186 |
branchcode => undef, |
4187 |
categorycode => undef, |
4188 |
itemtype => undef, |
4189 |
rule_name => 'refund', |
4190 |
rule_value => 1 |
4191 |
} |
4123 |
} |
4192 |
} |
4124 |
); |
4193 |
); |
4125 |
my $issue = AddIssue( $patron->unblessed, $item->barcode ); |
4194 |
|
4126 |
LostItem( $item->itemnumber, 'cli', 0 ); |
4195 |
# Test with NoRefundOnLostReturnedItemsAge disabled |
4127 |
$item->_result->itemlost(1); |
4196 |
my $issue = AddIssue( $patron, $item->barcode ); |
4128 |
$item->_result->itemlost_on( $lost_on ); |
4197 |
LostItem( $item->itemnumber, 'cli', 0 ); |
4129 |
$item->_result->update(); |
4198 |
$item->_result->itemlost(1); |
|
|
4199 |
$item->_result->itemlost_on( $lost_on ); |
4200 |
$item->_result->update(); |
4201 |
|
4202 |
my $a = Koha::Account::Lines->find( |
4203 |
{ |
4204 |
itemnumber => $item->id, |
4205 |
borrowernumber => $patron->{borrowernumber} |
4206 |
} |
4207 |
); |
4208 |
ok( $a, "Found accountline for lost fee" ); |
4209 |
is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" ); |
4210 |
my ( $doreturn, $messages ) = AddReturn( $item->barcode, $library->{branchcode}, undef, dt_from_string ); |
4211 |
$a = Koha::Account::Lines->find( $a->id ); |
4212 |
is( $a->amountoutstanding + 0, 0, "Lost fee was refunded" ); |
4213 |
}; |
4214 |
|
4215 |
subtest 'Tests for NoRefundOnLostReturnedItemsAge = length of days item has been lost' => sub { |
4216 |
plan tests => 3; |
4217 |
|
4130 |
|
4218 |
t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee', 1 ); |
4131 |
my $a = Koha::Account::Lines->search( |
4219 |
t::lib::Mocks::mock_preference( 'NoRefundOnLostReturnedItemsAge', 7 ); |
4132 |
{ |
|
|
4133 |
itemnumber => $item->id, |
4134 |
borrowernumber => $patron->borrowernumber |
4135 |
} |
4136 |
)->next; |
4137 |
ok( $a, "Found accountline for lost fee" ); |
4138 |
is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" ); |
4139 |
my ( $doreturn, $messages ) = AddReturn( $item->barcode, $library->branchcode, undef, dt_from_string ); |
4140 |
$a = $a->get_from_storage; |
4141 |
is( $a->amountoutstanding + 0, 0, "Lost fee was refunded" ); |
4142 |
$a->delete; |
4143 |
}; |
4220 |
|
4144 |
|
4221 |
my $lost_on = dt_from_string->subtract( days => 7 )->date; |
4145 |
subtest 'NoRefundOnLostReturnedItemsAge > length of days item has been lost' => sub { |
|
|
4146 |
plan tests => 3; |
4222 |
|
4147 |
|
4223 |
my $library = $builder->build( { source => 'Branch' } ); |
4148 |
t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee', 1 ); |
4224 |
my $patron = $builder->build( |
4149 |
t::lib::Mocks::mock_preference( 'NoRefundOnLostReturnedItemsAge', 7 ); |
4225 |
{ |
|
|
4226 |
source => 'Borrower', |
4227 |
value => { categorycode => $patron_category->{categorycode} } |
4228 |
} |
4229 |
); |
4230 |
|
4150 |
|
4231 |
my $biblionumber = $builder->build_sample_biblio( |
4151 |
my $lost_on = dt_from_string->subtract( days => 6 )->date; |
4232 |
{ |
|
|
4233 |
branchcode => $library->{branchcode}, |
4234 |
} |
4235 |
)->biblionumber; |
4236 |
my $item = $builder->build_sample_item( |
4237 |
{ |
4238 |
biblionumber => $biblionumber, |
4239 |
library => $library->{branchcode}, |
4240 |
replacementprice => '42.00', |
4241 |
} |
4242 |
); |
4243 |
|
4152 |
|
4244 |
# And the circulation rule |
4153 |
my $item = $builder->build_sample_item( |
4245 |
Koha::CirculationRules->search->delete; |
4154 |
{ |
4246 |
Koha::CirculationRules->set_rules( |
4155 |
biblionumber => $biblionumber, |
4247 |
{ |
4156 |
library => $library->branchcode, |
4248 |
categorycode => undef, |
4157 |
replacementprice => '42', |
4249 |
itemtype => undef, |
|
|
4250 |
branchcode => undef, |
4251 |
rules => { |
4252 |
issuelength => 14, |
4253 |
lengthunit => 'days', |
4254 |
} |
4158 |
} |
4255 |
} |
4159 |
); |
4256 |
); |
4160 |
my $issue = AddIssue( $patron->unblessed, $item->barcode ); |
4257 |
$builder->build( |
4161 |
LostItem( $item->itemnumber, 'cli', 0 ); |
4258 |
{ |
4162 |
$item->_result->itemlost(1); |
4259 |
source => 'CirculationRule', |
4163 |
$item->_result->itemlost_on( $lost_on ); |
4260 |
value => { |
4164 |
$item->_result->update(); |
4261 |
branchcode => undef, |
4165 |
|
4262 |
categorycode => undef, |
4166 |
my $a = Koha::Account::Lines->search( |
4263 |
itemtype => undef, |
4167 |
{ |
4264 |
rule_name => 'refund', |
4168 |
itemnumber => $item->id, |
4265 |
rule_value => 1 |
4169 |
borrowernumber => $patron->borrowernumber |
4266 |
} |
4170 |
} |
4267 |
} |
4171 |
)->next; |
4268 |
); |
4172 |
ok( $a, "Found accountline for lost fee" ); |
|
|
4173 |
is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" ); |
4174 |
my ( $doreturn, $messages ) = AddReturn( $item->barcode, $library->branchcode, undef, dt_from_string ); |
4175 |
$a = $a->get_from_storage; |
4176 |
is( $a->amountoutstanding + 0, 0, "Lost fee was refunded" ); |
4177 |
$a->delete; |
4178 |
}; |
4269 |
|
4179 |
|
4270 |
# Test with NoRefundOnLostReturnedItemsAge disabled |
4180 |
subtest 'NoRefundOnLostReturnedItemsAge = length of days item has been lost' => sub { |
4271 |
my $issue = AddIssue( $patron, $item->barcode ); |
4181 |
plan tests => 3; |
4272 |
LostItem( $item->itemnumber, 'cli', 0 ); |
|
|
4273 |
$item->_result->itemlost(1); |
4274 |
$item->_result->itemlost_on( $lost_on ); |
4275 |
$item->_result->update(); |
4276 |
|
4182 |
|
4277 |
my $a = Koha::Account::Lines->find( |
4183 |
t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee', 1 ); |
4278 |
{ |
4184 |
t::lib::Mocks::mock_preference( 'NoRefundOnLostReturnedItemsAge', 7 ); |
4279 |
itemnumber => $item->id, |
|
|
4280 |
borrowernumber => $patron->{borrowernumber} |
4281 |
} |
4282 |
); |
4283 |
ok( $a, "Found accountline for lost fee" ); |
4284 |
is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" ); |
4285 |
my ( $doreturn, $messages ) = AddReturn( $item->barcode, $library->{branchcode}, undef, dt_from_string ); |
4286 |
$a = Koha::Account::Lines->find( $a->id ); |
4287 |
is( $a->amountoutstanding + 0, 42, "Lost fee was not refunded" ); |
4288 |
}; |
4289 |
|
4185 |
|
4290 |
subtest 'Tests for NoRefundOnLostReturnedItemsAge < length of days item has been lost' => sub { |
4186 |
my $lost_on = dt_from_string->subtract( days => 7 )->date; |
4291 |
plan tests => 3; |
|
|
4292 |
|
4187 |
|
4293 |
t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee', 1 ); |
4188 |
my $item = $builder->build_sample_item( |
4294 |
t::lib::Mocks::mock_preference( 'NoRefundOnLostReturnedItemsAge', 7 ); |
4189 |
{ |
|
|
4190 |
biblionumber => $biblionumber, |
4191 |
library => $library->branchcode, |
4192 |
replacementprice => '42', |
4193 |
} |
4194 |
); |
4195 |
my $issue = AddIssue( $patron->unblessed, $item->barcode ); |
4196 |
LostItem( $item->itemnumber, 'cli', 0 ); |
4197 |
$item->_result->itemlost(1); |
4198 |
$item->_result->itemlost_on( $lost_on ); |
4199 |
$item->_result->update(); |
4295 |
|
4200 |
|
4296 |
my $lost_on = dt_from_string->subtract( days => 8 )->date; |
4201 |
my $a = Koha::Account::Lines->search( |
|
|
4202 |
{ |
4203 |
itemnumber => $item->id, |
4204 |
borrowernumber => $patron->borrowernumber |
4205 |
} |
4206 |
)->next; |
4207 |
ok( $a, "Found accountline for lost fee" ); |
4208 |
is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" ); |
4209 |
my ( $doreturn, $messages ) = AddReturn( $item->barcode, $library->branchcode, undef, dt_from_string ); |
4210 |
$a = $a->get_from_storage; |
4211 |
is( $a->amountoutstanding + 0, 42, "Lost fee was not refunded" ); |
4212 |
$a->delete; |
4213 |
}; |
4297 |
|
4214 |
|
4298 |
my $library = $builder->build( { source => 'Branch' } ); |
4215 |
subtest 'NoRefundOnLostReturnedItemsAge < length of days item has been lost' => sub { |
4299 |
my $patron = $builder->build( |
4216 |
plan tests => 3; |
4300 |
{ |
|
|
4301 |
source => 'Borrower', |
4302 |
value => { categorycode => $patron_category->{categorycode} } |
4303 |
} |
4304 |
); |
4305 |
|
4217 |
|
4306 |
my $biblionumber = $builder->build_sample_biblio( |
4218 |
t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee', 1 ); |
4307 |
{ |
4219 |
t::lib::Mocks::mock_preference( 'NoRefundOnLostReturnedItemsAge', 7 ); |
4308 |
branchcode => $library->{branchcode}, |
|
|
4309 |
} |
4310 |
)->biblionumber; |
4311 |
my $item = $builder->build_sample_item( |
4312 |
{ |
4313 |
biblionumber => $biblionumber, |
4314 |
library => $library->{branchcode}, |
4315 |
replacementprice => '42.00', |
4316 |
} |
4317 |
); |
4318 |
|
4220 |
|
4319 |
# And the circulation rule |
4221 |
my $lost_on = dt_from_string->subtract( days => 8 )->date; |
4320 |
Koha::CirculationRules->search->delete; |
|
|
4321 |
Koha::CirculationRules->set_rules( |
4322 |
{ |
4323 |
categorycode => undef, |
4324 |
itemtype => undef, |
4325 |
branchcode => undef, |
4326 |
rules => { |
4327 |
issuelength => 14, |
4328 |
lengthunit => 'days', |
4329 |
} |
4330 |
} |
4331 |
); |
4332 |
$builder->build( |
4333 |
{ |
4334 |
source => 'CirculationRule', |
4335 |
value => { |
4336 |
branchcode => undef, |
4337 |
categorycode => undef, |
4338 |
itemtype => undef, |
4339 |
rule_name => 'refund', |
4340 |
rule_value => 1 |
4341 |
} |
4342 |
} |
4343 |
); |
4344 |
|
4222 |
|
4345 |
# Test with NoRefundOnLostReturnedItemsAge disabled |
4223 |
my $item = $builder->build_sample_item( |
4346 |
my $issue = AddIssue( $patron, $item->barcode ); |
4224 |
{ |
4347 |
LostItem( $item->itemnumber, 'cli', 0 ); |
4225 |
biblionumber => $biblionumber, |
4348 |
$item->_result->itemlost(1); |
4226 |
library => $library->branchcode, |
4349 |
$item->_result->itemlost_on( $lost_on ); |
4227 |
replacementprice => '42', |
4350 |
$item->_result->update(); |
4228 |
} |
|
|
4229 |
); |
4230 |
my $issue = AddIssue( $patron->unblessed, $item->barcode ); |
4231 |
LostItem( $item->itemnumber, 'cli', 0 ); |
4232 |
$item->_result->itemlost(1); |
4233 |
$item->_result->itemlost_on( $lost_on ); |
4234 |
$item->_result->update(); |
4351 |
|
4235 |
|
4352 |
my $a = Koha::Account::Lines->find( |
4236 |
my $a = Koha::Account::Lines->search( |
4353 |
{ |
4237 |
{ |
4354 |
itemnumber => $item->id, |
4238 |
itemnumber => $item->id, |
4355 |
borrowernumber => $patron->{borrowernumber} |
4239 |
borrowernumber => $patron->borrowernumber |
4356 |
} |
4240 |
} |
4357 |
); |
4241 |
); |
4358 |
ok( $a, "Found accountline for lost fee" ); |
4242 |
$a = $a->next; |
4359 |
is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" ); |
4243 |
ok( $a, "Found accountline for lost fee" ); |
4360 |
my ( $doreturn, $messages ) = AddReturn( $item->barcode, $library->{branchcode}, undef, dt_from_string ); |
4244 |
is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" ); |
4361 |
$a = Koha::Account::Lines->find( $a->id ); |
4245 |
my ( $doreturn, $messages ) = AddReturn( $item->barcode, $library->branchcode, undef, dt_from_string ); |
4362 |
is( $a->amountoutstanding + 0, 42, "Lost fee was not refunded" ); |
4246 |
$a = $a->get_from_storage; |
|
|
4247 |
is( $a->amountoutstanding + 0, 42, "Lost fee was not refunded" ); |
4248 |
$a->delete; |
4249 |
}; |
4363 |
}; |
4250 |
}; |
4364 |
|
4251 |
|
4365 |
$schema->storage->txn_rollback; |
4252 |
$schema->storage->txn_rollback; |
4366 |
- |
|
|