Bugzilla – Attachment 97130 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: Add new tests for hours_between
Bug-23974-Add-new-tests-for-hoursbetween.patch (text/plain), 6.11 KB, created by
Tomás Cohen Arazi (tcohen)
on 2020-01-09 19:05:03 UTC
(
hide
)
Description:
Bug 23974: Add new tests for hours_between
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2020-01-09 19:05:03 UTC
Size:
6.11 KB
patch
obsolete
>From f730e3eaa75f06820167b23bfd721cc15d48c3a4 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 5 Nov 2019 16:23:00 +0100 >Subject: [PATCH] Bug 23974: Add new tests for hours_between > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> > >Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > t/db_dependent/Calendar.t | 144 +++++++++++++++++++++++++++++++++++++- > 1 file changed, 143 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Calendar.t b/t/db_dependent/Calendar.t >index 9788cf6d5e..e24e9bc6bc 100644 >--- a/t/db_dependent/Calendar.t >+++ b/t/db_dependent/Calendar.t >@@ -17,7 +17,8 @@ > > use Modern::Perl; > >-use Test::More tests => 3; >+use Test::More tests => 4; >+use Time::Fake; > use t::lib::TestBuilder; > > use DateTime; >@@ -91,4 +92,145 @@ subtest 'crossing_DST' => sub { > ); > }; > >+subtest 'hours_between' => sub { >+ >+ plan tests => 2; >+ >+ # November 2019 >+ # Su Mo Tu We Th Fr Sa >+ # 1 2 >+ # 3 4 *5* 6 7 8 9 >+ # 10 11 12 13 14 15 16 >+ # 17 18 19 20 21 22 23 >+ # 24 25 26 27 28 29 30 >+ >+ my $now = dt_from_string('2019-11-05 12:34:56'); # Today is 2019 Nov 5th >+ my $nov_6 = dt_from_string('2019-11-06 12:34:56'); >+ my $nov_7 = dt_from_string('2019-11-07 12:34:56'); >+ my $nov_12 = dt_from_string('2019-11-12 12:34:56'); >+ my $nov_13 = dt_from_string('2019-11-13 12:34:56'); >+ my $nov_15 = dt_from_string('2019-11-15 12:34:56'); >+ Time::Fake->offset($now->epoch); >+ >+ subtest 'No holiday' => sub { >+ >+ plan tests => 2; >+ >+ my $library = $builder->build_object({ class => 'Koha::Libraries' }); >+ my $calendar = Koha::Calendar->new( branchcode => $library->branchcode ); >+ >+ subtest 'Same hours' => sub { >+ >+ plan tests => 4; >+ >+ # Between 5th and 6th >+ my $diff_hours = $calendar->hours_between( $now, $nov_6 )->hours; >+ is( $diff_hours, 1 * 24, '' ); >+ >+ # Between 5th and 7th >+ $diff_hours = $calendar->hours_between( $now, $nov_7 )->hours; >+ is( $diff_hours, 2 * 24, '' ); >+ >+ # Between 5th and 12th >+ $diff_hours = $calendar->hours_between( $now, $nov_12 )->hours; >+ is( $diff_hours, 7 * 24, '' ); >+ >+ # Between 5th and 15th >+ $diff_hours = $calendar->hours_between( $now, $nov_15 )->hours; >+ is( $diff_hours, 10 * 24, '' ); >+ }; >+ >+ subtest 'Different hours' => sub { >+ >+ plan tests => 4; >+ >+ # Between 5th and 6th >+ my $diff_hours = $calendar->hours_between( $now, $nov_6->clone->subtract(hours => 3) )->hours; >+ is( $diff_hours, 1 * 24 - 3, '' ); >+ >+ # Between 5th and 7th >+ $diff_hours = $calendar->hours_between( $now, $nov_7->clone->subtract(hours => 3) )->hours; >+ is( $diff_hours, 2 * 24 - 3, '' ); >+ >+ # Between 5th and 12th >+ $diff_hours = $calendar->hours_between( $now, $nov_12->clone->subtract(hours => 3) )->hours; >+ is( $diff_hours, 7 * 24 - 3, '' ); >+ >+ # Between 5th and 15th >+ $diff_hours = $calendar->hours_between( $now, $nov_15->clone->subtract(hours => 3) )->hours; >+ is( $diff_hours, 10 * 24 - 3, '' ); >+ }; >+ }; >+ >+ subtest 'With holiday' => sub { >+ plan tests => 2; >+ >+ my $library = $builder->build_object({ class => 'Koha::Libraries' }); >+ >+ # Wednesdays are closed >+ my $dbh = C4::Context->dbh; >+ $dbh->do(q| >+ INSERT INTO repeatable_holidays (branchcode,weekday,day,month,title,description) >+ VALUES ( ?, ?, NULL, NULL, ?, '' ) >+ |, undef, $library->branchcode, 3, 'Closed on Wednesday'); >+ >+ my $calendar = Koha::Calendar->new( branchcode => $library->branchcode ); >+ >+ subtest 'Same hours' => sub { >+ plan tests => 5; >+ >+ my $diff_hours; >+ >+ # Between 5th and 6th >+ $diff_hours = $calendar->hours_between( $now, $nov_6 )->hours; >+ is( $diff_hours, 0 * 24, '' ); # FIXME Is this really should be 0? >+ >+ # Between 5th and 7th >+ $diff_hours = $calendar->hours_between( $now, $nov_7 )->hours; >+ is( $diff_hours, 2 * 24 - 1 * 24, '' ); >+ >+ # Between 5th and 12th >+ $diff_hours = $calendar->hours_between( $now, $nov_12 )->hours; >+ is( $diff_hours, 7 * 24 - 1 * 24, '' ); >+ >+ # Between 5th and 13th >+ $diff_hours = $calendar->hours_between( $now, $nov_13 )->hours; >+ is( $diff_hours, 8 * 24 - 2 * 24, '' ); >+ >+ # Between 5th and 15th >+ $diff_hours = $calendar->hours_between( $now, $nov_15 )->hours; >+ is( $diff_hours, 10 * 24 - 2 * 24, '' ); >+ }; >+ >+ subtest 'Different hours' => sub { >+ plan tests => 6; >+ >+ my $diff_hours; >+ >+ # Between 5th and 6th >+ my $duration = $calendar->hours_between( $now, $nov_6->clone->subtract(hours => 3) ); >+ is( $duration->hours, abs(0 * 24 - 3), '' ); # FIXME $duration->hours always return a abs >+ is( $duration->is_negative, 1, ); # FIXME Do really test for that case in our calls to hours_between? >+ >+ # Between 5th and 7th >+ $diff_hours = $calendar->hours_between( $now, $nov_7->clone->subtract(hours => 3) )->hours; >+ is( $diff_hours, 2 * 24 - 1 * 24 - 3, '' ); >+ >+ # Between 5th and 12th >+ $diff_hours = $calendar->hours_between( $now, $nov_12->clone->subtract(hours => 3) )->hours; >+ is( $diff_hours, 7 * 24 - 1 * 24 - 3, '' ); >+ >+ # Between 5th and 13th >+ $diff_hours = $calendar->hours_between( $now, $nov_13->clone->subtract(hours => 3) )->hours; >+ is( $diff_hours, 8 * 24 - 2 * 24 - 3, '' ); >+ >+ # Between 5th and 15th >+ $diff_hours = $calendar->hours_between( $now, $nov_15->clone->subtract(hours => 3) )->hours; >+ is( $diff_hours, 10 * 24 - 2 * 24 - 3, '' ); >+ }; >+ >+ }; >+ >+}; >+ > $schema->storage->txn_rollback(); >-- >2.24.1
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