From 0d6fccecc0484225ce4c834214c9d95cdbabad42 Mon Sep 17 00:00:00 2001 From: Mehdi Hamidi Date: Mon, 16 Jan 2017 10:13:20 -0500 Subject: [PATCH] Bug 17015 - Updated Koha tests to use the new DiscreteCalendar module --- t/db_dependent/Circulation/CalcFine.t | 26 ++++---------------------- t/db_dependent/Fines.t | 11 ++++++----- t/db_dependent/Holds.t | 16 +++++----------- t/db_dependent/HoldsQueue.t | 27 ++++++++++++++++++--------- 4 files changed, 33 insertions(+), 47 deletions(-) diff --git a/t/db_dependent/Circulation/CalcFine.t b/t/db_dependent/Circulation/CalcFine.t index 862673f..bdfe0bb 100644 --- a/t/db_dependent/Circulation/CalcFine.t +++ b/t/db_dependent/Circulation/CalcFine.t @@ -90,17 +90,8 @@ subtest 'Test basic functionality' => sub { } ); - my $start_dt = DateTime->new( - year => 2000, - month => 1, - day => 1, - ); - - my $end_dt = DateTime->new( - year => 2000, - month => 1, - day => 30, - ); + my $start_dt = DateTime->today; + my $end_dt = DateTime->today->add(days => 29); my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt ); @@ -129,17 +120,8 @@ subtest 'Test cap_fine_to_replacement_price' => sub { } ); - my $start_dt = DateTime->new( - year => 2000, - month => 1, - day => 1, - ); - - my $end_dt = DateTime->new( - year => 2000, - month => 1, - day => 30, - ); + my $start_dt = DateTime->today; + my $end_dt = DateTime->today->add(days => 29); my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt ); diff --git a/t/db_dependent/Fines.t b/t/db_dependent/Fines.t index 1f273ba..8e9d018 100644 --- a/t/db_dependent/Fines.t +++ b/t/db_dependent/Fines.t @@ -1,6 +1,7 @@ #!/usr/bin/perl use Modern::Perl; +use DateTime; use C4::Context; use C4::Overdues; @@ -34,23 +35,23 @@ my $issuingrule = $schema->resultset('Issuingrule')->create( ok( $issuingrule, 'Issuing rule created' ); -my $period_start = dt_from_string('2000-01-01'); -my $period_end = dt_from_string('2000-01-05'); +my $period_start = DateTime->today; +my $period_end = DateTime->today->add(days => 4); my ( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end ); is( $fine, 0, '4 days overdue, charge period 7 days, charge at end of interval gives fine of $0' ); -$period_end = dt_from_string('2000-01-10'); +$period_end = DateTime->today->add(days => 9); ( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end ); is( $fine, 1, '9 days overdue, charge period 7 days, charge at end of interval gives fine of $1' ); # Test charging fine at the *beginning* of each charge period $issuingrule->update( { chargeperiod_charge_at => 1 } ); -$period_end = dt_from_string('2000-01-05'); +$period_end = DateTime->today->add(days => 4); ( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end ); is( $fine, 1, '4 days overdue, charge period 7 days, charge at start of interval gives fine of $1' ); -$period_end = dt_from_string('2000-01-10'); +$period_end = DateTime->today->add(days => 9); ( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end ); is( $fine, 2, '9 days overdue, charge period 7 days, charge at start of interval gives fine of $2' ); diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index 61b9e6e..881b21d 100755 --- a/t/db_dependent/Holds.t +++ b/t/db_dependent/Holds.t @@ -13,6 +13,7 @@ use C4::Biblio; use C4::Items; use C4::Members; use C4::Calendar; +use Koha::DiscreteCalendar; use Koha::Database; use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::Holds; @@ -426,19 +427,12 @@ is(CanItemBeReserved($borrowernumbers[0], $itemnumber), 'OK', t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelay', 1); t::lib::Mocks::mock_preference('ReservesMaxPickUpDelay', 1); -my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime(time); -$year += 1900; -$mon += 1; $reserves = $dbh->selectall_arrayref('SELECT * FROM reserves', { Slice => {} }); $reserve = $reserves->[0]; -my $calendar = C4::Calendar->new(branchcode => $reserve->{branchcode}); -$calendar->insert_single_holiday( - day => $mday, - month => $mon, - year => $year, - title => 'Test', - description => 'Test', -); + +my $today = dt_from_string(); +Koha::DiscreteCalendar->new( branchcode => $reserve->{branchcode} )->edit_holiday("Today", '', "E", '', '', $today, $today); + $reserve_id = $reserve->{reserve_id}; $dbh->do("UPDATE reserves SET waitingdate = DATE_SUB( NOW(), INTERVAL 5 DAY ), found = 'W', priority = 0 WHERE reserve_id = ?", undef, $reserve_id ); t::lib::Mocks::mock_preference('ExpireReservesOnHolidays', 0); diff --git a/t/db_dependent/HoldsQueue.t b/t/db_dependent/HoldsQueue.t index c71a516..9c132cc 100755 --- a/t/db_dependent/HoldsQueue.t +++ b/t/db_dependent/HoldsQueue.t @@ -11,9 +11,9 @@ use Modern::Perl; use Test::More tests => 42; use Data::Dumper; -use C4::Calendar; use C4::Context; use C4::Members; +use Koha::DiscreteCalendar; use Koha::Database; use Koha::DateUtils; @@ -187,6 +187,21 @@ $library2 = $builder->build({ $library3 = $builder->build({ source => 'Branch', }); + +$schema->resultset('DiscreteCalendar')->search({ + branchcode =>'DFLT' +})->update_all({ + isopened => 1, + holidaytype => '', + note => '', + openhour => '08:00:00', + closehour => '16:00:00' +}); + +Koha::DiscreteCalendar->new( branchcode => 'DFLT' )->add_new_branch('DFLT', $library1->{branchcode}); +Koha::DiscreteCalendar->new( branchcode => 'DFLT' )->add_new_branch('DFLT', $library2->{branchcode}); +Koha::DiscreteCalendar->new( branchcode => 'DFLT' )->add_new_branch('DFLT', $library3->{branchcode}); + @branchcodes = ( $library1->{branchcode}, $library2->{branchcode}, $library3->{branchcode} ); my $borrower1 = $builder->build({ @@ -300,16 +315,10 @@ is( $holds_queue->[1]->{cardnumber}, $borrower2->{cardnumber}, "Holds queue fill # have 1 row in the holds queue t::lib::Mocks::mock_preference('HoldsQueueSkipClosed', 1); my $today = dt_from_string(); -C4::Calendar->new( branchcode => $branchcodes[0] )->insert_single_holiday( - day => $today->day(), - month => $today->month(), - year => $today->year(), - title => "$today", - description => "$today", -); # If the test below is removed, aother tests using the holiday will fail. For some reason if we call is_holiday now # the holiday will get set in cache correctly, but not if we let C4::HoldsQueue call is_holiday instead. -is( Koha::Calendar->new( branchcode => $branchcodes[0] )->is_holiday( $today ), 1, 'Is today a holiday for pickup branch' ); +Koha::DiscreteCalendar->new( branchcode => $branchcodes[0] )->edit_holiday("Today", '', "E", '', '', $today, $today); +is( Koha::DiscreteCalendar->new( branchcode => $branchcodes[0] )->is_holiday( $today ), 1, 'Is today a holiday for pickup branch' ); C4::HoldsQueue::CreateQueue(); $holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); is( scalar( @$holds_queue ), 1, "Holds not filled with items from closed libraries" ); -- 1.9.1