|
Lines 2-15
Link Here
|
| 2 |
|
2 |
|
| 3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
| 4 |
|
4 |
|
| 5 |
use Test::More tests => 19; |
5 |
use Test::More tests => 23; |
| 6 |
use Test::MockModule; |
6 |
use Test::MockModule; |
| 7 |
use DBI; |
7 |
use DBI; |
| 8 |
use DateTime; |
8 |
use DateTime; |
| 9 |
use t::lib::Mocks; |
9 |
use t::lib::Mocks; |
| 10 |
use t::lib::TestBuilder; |
10 |
use t::lib::TestBuilder; |
| 11 |
use C4::Calendar qw( new insert_single_holiday delete_holiday insert_week_day_holiday ); |
11 |
use C4::Calendar qw( new insert_single_holiday delete_holiday insert_week_day_holiday ); |
| 12 |
|
12 |
use Koha::DateUtils qw( dt_from_string ); |
|
|
13 |
use Koha::Library::Hours; |
| 13 |
use Koha::CirculationRules; |
14 |
use Koha::CirculationRules; |
| 14 |
|
15 |
|
| 15 |
use_ok('C4::Circulation', qw( CalcDateDue )); |
16 |
use_ok('C4::Circulation', qw( CalcDateDue )); |
|
Lines 18-24
my $schema = Koha::Database->new->schema;
Link Here
|
| 18 |
$schema->storage->txn_begin; |
19 |
$schema->storage->txn_begin; |
| 19 |
my $builder = t::lib::TestBuilder->new; |
20 |
my $builder = t::lib::TestBuilder->new; |
| 20 |
|
21 |
|
| 21 |
|
22 |
t::lib::Mocks::mock_preference( 'ConsiderLibraryHoursInCirculation', 'ignore' ); |
| 22 |
my $library = $builder->build_object({ class => 'Koha::Libraries' })->store; |
23 |
my $library = $builder->build_object({ class => 'Koha::Libraries' })->store; |
| 23 |
my $dateexpiry = '2013-01-01'; |
24 |
my $dateexpiry = '2013-01-01'; |
| 24 |
my $patron_category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { category_type => 'B' } })->store; |
25 |
my $patron_category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { category_type => 'B' } })->store; |
|
Lines 356-360
my $renewed_date = $start_date->clone->add( days => 7 );
Link Here
|
| 356 |
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 ); |
357 |
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 ); |
| 357 |
is( $date->ymd, $renewed_date->ymd, 'Renewal period of "" should trigger fallover to issuelength for renewal' ); |
358 |
is( $date->ymd, $renewed_date->ymd, 'Renewal period of "" should trigger fallover to issuelength for renewal' ); |
| 358 |
|
359 |
|
|
|
360 |
# Testing hourly loans consider library open hours |
| 361 |
|
| 362 |
my $library1 = $builder->build( { source => 'Branch' } ); |
| 363 |
Koha::CirculationRules->set_rules( |
| 364 |
{ |
| 365 |
categorycode => $categorycode, |
| 366 |
itemtype => $itemtype, |
| 367 |
branchcode => $library1->{branchcode}, |
| 368 |
rules => { |
| 369 |
issuelength => 3, # loan period is 3 hours |
| 370 |
lengthunit => 'hours', |
| 371 |
} |
| 372 |
} |
| 373 |
); |
| 374 |
|
| 375 |
my $open = DateTime->now->subtract( hours => 4 )->hms; |
| 376 |
my $close = DateTime->now->add( hours => 2 )->hms; |
| 377 |
my $now = DateTime->now; |
| 378 |
|
| 379 |
foreach (0..6) { |
| 380 |
# library opened 4 hours ago and closes in 2 hours. |
| 381 |
Koha::Library::Hour->new({ day => $_, library_id => $library1->{branchcode}, open_time => $open, close_time => $close })->store; |
| 382 |
} |
| 383 |
|
| 384 |
# ignore calendar |
| 385 |
t::lib::Mocks::mock_preference('useDaysMode', 'Days'); |
| 386 |
t::lib::Mocks::mock_preference('ConsiderLibraryHoursInCirculation', 'close'); |
| 387 |
# shorten loan period |
| 388 |
|
| 389 |
$date = C4::Circulation::CalcDateDue( $now, $itemtype, $library1->{branchcode}, $borrower ); |
| 390 |
my $expected_duetime = DateTime->now->add( hours => 2 ); |
| 391 |
is( $date, $expected_duetime, "Loan period was shortened because ConsiderLibraryHoursInCirculation is set to close time" ); |
| 392 |
|
| 393 |
t::lib::Mocks::mock_preference('ConsiderLibraryHoursWhenIssuing', 'open'); |
| 394 |
# extend loan period |
| 395 |
|
| 396 |
$date = C4::Circulation::CalcDateDue( $now, $itemtype, $library1->{branchcode}, $borrower ); |
| 397 |
$expected_duetime = DateTime->now->add( days => 1 )->subtract( hours => 4 ); |
| 398 |
is( $date, $expected_duetime, "Loan period was extended because ConsiderLibraryHoursInCirculation is set to open time" ); |
| 399 |
|
| 400 |
my $holiday_tomorrow = DateTime->now->add( days => 1 ); |
| 401 |
|
| 402 |
# consider calendar |
| 403 |
my $library1_calendar = C4::Calendar->new( branchcode => $library1->{branchcode} ); |
| 404 |
$library1_calendar->insert_single_holiday( |
| 405 |
day => $holiday_tomorrow->day, |
| 406 |
month => $holiday_tomorrow->month, |
| 407 |
year => $holiday_tomorrow->year, |
| 408 |
title => 'testholiday', |
| 409 |
description => 'testholiday' |
| 410 |
); |
| 411 |
Koha::CirculationRules->set_rules( |
| 412 |
{ |
| 413 |
categorycode => $categorycode, |
| 414 |
itemtype => $itemtype, |
| 415 |
branchcode => $library1->{branchcode}, |
| 416 |
rules => { |
| 417 |
issuelength => 13, # loan period must cross over into tomorrow |
| 418 |
lengthunit => 'hours', |
| 419 |
} |
| 420 |
} |
| 421 |
); |
| 422 |
|
| 423 |
t::lib::Mocks::mock_preference('useDaysMode', 'Calendar'); |
| 424 |
t::lib::Mocks::mock_preference('ConsiderLibraryHoursInCirculation', 'close'); |
| 425 |
# shorten loan period |
| 426 |
|
| 427 |
$date = C4::Circulation::CalcDateDue( $now, $itemtype, $library1->{branchcode}, $borrower ); |
| 428 |
$expected_duetime = DateTime->now->add( days => 2, hours => 2 ); |
| 429 |
is( $date, $expected_duetime, "Loan period was shortened (but considers the holiday) because ConsiderLibraryHoursInCirculation is set to close time" ); |
| 430 |
|
| 431 |
t::lib::Mocks::mock_preference( 'ConsiderLibraryHoursInCirculation', 'open' ); |
| 432 |
# extend loan period |
| 433 |
|
| 434 |
$date = C4::Circulation::CalcDateDue( $now, $itemtype, $library1->{branchcode}, $borrower ); |
| 435 |
$expected_duetime = DateTime->now->add( days => 2 )->subtract( hours => 4 ); |
| 436 |
is( $date, $expected_duetime, "Loan period was extended (but considers the holiday) because ConsiderLibraryHoursInCirculation is set to open time" ); |
| 437 |
|
| 359 |
$cache->clear_from_cache($key); |
438 |
$cache->clear_from_cache($key); |
| 360 |
$schema->storage->txn_rollback; |
439 |
$schema->storage->txn_rollback; |
| 361 |
- |
|
|