Bugzilla – Attachment 95062 Details for
Bug 23974
hours_between and days_between lack tests
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23974: Improve readability
Bug-23974-Improve-readability.patch (text/plain), 4.58 KB, created by
Jonathan Druart
on 2019-11-05 16:44:59 UTC
(
hide
)
Description:
Bug 23974: Improve readability
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2019-11-05 16:44:59 UTC
Size:
4.58 KB
patch
obsolete
>From 01d9a8787ac112f7bfc1d8ab42a6f28da049bc7a Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 5 Nov 2019 15:18:38 +0100 >Subject: [PATCH] Bug 23974: Improve readability > >This patch does not change anything, just a bit of cleaning >--- > t/db_dependent/Calendar.t | 85 ++++++++++++++++++++++++++--------------------- > 1 file changed, 47 insertions(+), 38 deletions(-) > >diff --git a/t/db_dependent/Calendar.t b/t/db_dependent/Calendar.t >index 3cfe961e20..9788cf6d5e 100644 >--- a/t/db_dependent/Calendar.t >+++ b/t/db_dependent/Calendar.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 6; >+use Test::More tests => 3; > use t::lib::TestBuilder; > > use DateTime; >@@ -31,55 +31,64 @@ $schema->storage->txn_begin; > > my $today = dt_from_string(); > my $holiday_dt = $today->clone; >-$holiday_dt->add(days => 15); >+$holiday_dt->add(days => 3); > > Koha::Caches->get_instance()->flush_all(); > > my $builder = t::lib::TestBuilder->new(); >-my $holiday = $builder->build({ >- source => 'SpecialHoliday', >- value => { >- branchcode => 'LIB1', >- day => $holiday_dt->day, >- month => $holiday_dt->month, >- year => $holiday_dt->year, >- title => 'My holiday', >- isexception => 0 >- }, >-}); >- >-my $calendar = Koha::Calendar->new( branchcode => 'LIB1'); >-my $forwarded_dt = $calendar->days_forward($today, 10); >- >-my $expected = $today->clone; >-$expected->add(days => 10); >-is($forwarded_dt->ymd, $expected->ymd, 'With no holiday on the perioddays_forward should add 10 days'); >- >-$forwarded_dt = $calendar->days_forward($today, 20); >- >-$expected->add(days => 11); >-is($forwarded_dt->ymd, $expected->ymd, 'With holiday on the perioddays_forward should add 20 days + 1 day for holiday'); >- >-$forwarded_dt = $calendar->days_forward($today, 0); >-is($forwarded_dt->ymd, $today->ymd, '0 day should return start dt'); >- >-$forwarded_dt = $calendar->days_forward($today, -2); >-is($forwarded_dt->ymd, $today->ymd, 'negative day should return start dt'); >+my $library = $builder->build_object({ class => 'Koha::Libraries' }); >+my $holiday = $builder->build( >+ { >+ source => 'SpecialHoliday', >+ value => { >+ branchcode => $library->branchcode, >+ day => $holiday_dt->day, >+ month => $holiday_dt->month, >+ year => $holiday_dt->year, >+ title => 'My holiday', >+ isexception => 0 >+ }, >+ } >+); >+ >+my $calendar = Koha::Calendar->new( branchcode => $library->branchcode ); >+ >+subtest 'days_forward' => sub { >+ >+ plan tests => 4; >+ my $forwarded_dt = $calendar->days_forward( $today, 2 ); >+ my $expected = $today->clone->add( days => 2 ); >+ is( $forwarded_dt->ymd, $expected->ymd, 'With no holiday on the perioddays_forward should add 2 days' ); >+ >+ $forwarded_dt = $calendar->days_forward( $today, 5 ); >+ $expected = $today->clone->add( days => 6 ); >+ is( $forwarded_dt->ymd, $expected->ymd, 'With holiday on the perioddays_forward should add 5 days + 1 day for holiday' >+ ); >+ >+ $forwarded_dt = $calendar->days_forward( $today, 0 ); >+ is( $forwarded_dt->ymd, $today->ymd, '0 day should return start dt' ); >+ >+ $forwarded_dt = $calendar->days_forward( $today, -2 ); >+ is( $forwarded_dt->ymd, $today->ymd, 'negative day should return start dt' ); >+}; > > subtest 'crossing_DST' => sub { > > plan tests => 3; > > my $tz = DateTime::TimeZone->new( name => 'America/New_York' ); >- my $start_date = dt_from_string( "2016-03-09 02:29:00",undef,$tz ); >- my $end_date = dt_from_string( "2017-01-01 00:00:00", undef, $tz ); >- my $days_between = $calendar->days_between($start_date,$end_date); >+ my $start_date = dt_from_string( "2016-03-09 02:29:00", undef, $tz ); >+ my $end_date = dt_from_string( "2017-01-01 00:00:00", undef, $tz ); >+ my $days_between = $calendar->days_between( $start_date, $end_date ); > is( $days_between->delta_days, 298, "Days calculated correctly" ); >- $days_between = $calendar->days_between($end_date,$start_date); >+ $days_between = $calendar->days_between( $end_date, $start_date ); > is( $days_between->delta_days, 298, "Swapping returns the same" ); >- my $hours_between = $calendar->hours_between($start_date,$end_date); >- is( $hours_between->delta_minutes, 298 * 24 * 60 - 149, "Hours (in minutes) calculated correctly" ); >- >+ my $hours_between = $calendar->hours_between( $start_date, $end_date ); >+ is( >+ $hours_between->delta_minutes, >+ 298 * 24 * 60 - 149, >+ "Hours (in minutes) calculated correctly" >+ ); > }; > > $schema->storage->txn_rollback(); >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 23974
:
95062
|
95063
|
95064
|
95065
|
95210
|
95211
|
95212
|
95213
|
95214
|
95889
|
95890
|
95891
|
95893
|
95894
|
95895
|
95896
|
96778
|
96779
|
96780
|
96781
|
96782
|
96783
|
96784
|
96785
|
96786
|
97129
|
97130
|
97131
|
97132
|
97133
|
97134
|
97135
|
97136
|
97137