Bugzilla – Attachment 99862 Details for
Bug 24757
t/db_dependent/Koha/Patrons.t get_age fails on February 28 in a Leap Year
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24757: Leap day failing tests - refactoring
Bug-24757-Leap-day-failing-tests---refactoring.patch (text/plain), 7.07 KB, created by
Jonathan Druart
on 2020-03-02 09:59:37 UTC
(
hide
)
Description:
Bug 24757: Leap day failing tests - refactoring
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-03-02 09:59:37 UTC
Size:
7.07 KB
patch
obsolete
>From d794114e1805813c660c09c492afde3fd059dfd7 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 28 Feb 2020 16:47:57 +0100 >Subject: [PATCH] Bug 24757: Leap day failing tests - refactoring > >Refactore the tests to add more of them after we fixed the failing ones. >--- > t/db_dependent/Koha/Patrons.t | 125 ++++++++++++++++++++-------------- > 1 file changed, 72 insertions(+), 53 deletions(-) > >diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t >index bfe10a32f7..297ed84a9d 100644 >--- a/t/db_dependent/Koha/Patrons.t >+++ b/t/db_dependent/Koha/Patrons.t >@@ -708,37 +708,45 @@ subtest 'get_age' => sub { > my $patron = $builder->build( { source => 'Borrower' } ); > $patron = Koha::Patrons->find( $patron->{borrowernumber} ); > >- my $dt = dt_from_string('2020-02-28'); >+ my @dates = ( >+ { >+ today => '2020-02-28', >+ add_m12_m6_m1 => { date => '2007-08-27', expected_age => 12 }, >+ add_m18_0_p1 => { date => '2002-02-28', expected_age => 17 }, >+ add_m18_0_0 => { date => '2002-02-28', expected_age => 18 }, >+ add_m18_m12_m31 => { date => '2001-01-28', expected_age => 19 }, >+ add_m18_m12_m30 => { date => '2001-01-29', expected_age => 19 } , >+ add_0_m1_m1 => { date => '2020-01-27', expected_age => 0 }, >+ }, >+ ); > >- Time::Fake->offset( $dt->epoch ); > $patron->dateofbirth( undef ); > is( $patron->get_age, undef, 'get_age should return undef if no dateofbirth is defined' ); > >- my $add_m12_m6_m1 = '2007-08-27'; >- $patron->dateofbirth( dt_from_string($add_m12_m6_m1, 'iso') ); >- is( $patron->get_age, 12, 'Patron should be 12' ); >+ for my $date ( @dates ) { > >- my $add_m18_0_p1 = '2002-02-28'; >- $patron->dateofbirth( dt_from_string($add_m18_0_p1, 'iso')); >- is( $patron->get_age, 17, 'Patron should be 17, happy birthday tomorrow!' ); >+ my $dt = dt_from_string($date->{today}); > >- my $add_m18_0_0 = '2002-02-28'; >- $patron->dateofbirth( dt_from_string($add_m18_0_0, 'iso')); >- is( $patron->get_age, 18, 'Patron should be 18' ); >- >- my $add_m18_m12_m31 = '2001-01-28'; >- $patron->dateofbirth( dt_from_string($add_m18_m12_m31, 'iso')); >- is( $patron->get_age, 19, 'Patron should be 19' ); >+ Time::Fake->offset( $dt->epoch ); > >- my $add_m18_m12_m30 = '2001-01-29'; >- $patron->dateofbirth( dt_from_string($add_m18_m12_m30, 'iso' )); >- is( $patron->get_age, 19, 'Patron should be 19 again' ); >+ for my $k ( keys %$date ) { >+ next if $k eq 'today'; >+ >+ my $dob = $date->{$k}; >+ $patron->dateofbirth( dt_from_string( $dob->{date}, 'iso' ) ); >+ is( >+ $patron->get_age, >+ $dob->{expected_age}, >+ sprintf( >+ "Today=%s, dob=%s, should be %d", >+ $date->{today}, $dob->{date}, $dob->{expected_age} >+ ) >+ ); >+ } > >- my $add_0_m1_m1 = '2020-01-27'; >- $patron->dateofbirth( dt_from_string($add_0_m1_m1, 'iso' )); >- is( $patron->get_age, 0, 'Patron is a newborn child' ); >+ Time::Fake->reset; > >- Time::Fake->reset; >+ } > > $patron->delete; > }; >@@ -772,43 +780,54 @@ subtest 'is_valid_age' => sub { > $patron->dateofbirth( undef ); > is( $patron->is_valid_age, 1, 'Patron with no dateofbirth is always valid for any category'); > >- my $add_m12_m6_m1 = '2007-08-27'; >- $patron->dateofbirth( dt_from_string($add_m12_m6_m1, 'iso') ); >- is( $patron->is_valid_age, 0, 'Patron is 12, so the age is above allowed range 5-10 years'); >- >- my $add_m3_m6_m1 = '2016-08-27'; >- $patron->dateofbirth( dt_from_string($add_m3_m6_m1, 'iso')); >- is( $patron->is_valid_age, 0, 'Patron is 3, so the age is below allowed range 5-10 years'); >- >- my $add_m7_m6_m1 = '2015-02-28'; >- $patron->dateofbirth( dt_from_string($add_m7_m6_m1, 'iso')); >- is( $patron->is_valid_age, 1, 'Patron is 7, so the age perfectly suits allowed range 5-10 years'); >- >- my $add_m5_0_1 = '2015-02-28'; >- $patron->dateofbirth( dt_from_string($add_m5_0_1, 'iso' )); >- is( $patron->is_valid_age, 1, 'Patron celebrates the 5th birthday today, so the age is allowed for this category'); >+ my @dates = ( >+ { >+ today => '2020-02-28', >+ add_m12_m6_m1 => >+ { date => '2007-08-27', expected_age => 12, valid => 0 }, >+ add_m3_m6_m1 => >+ { date => '2016-08-27', expected_age => 3, valid => 0 }, >+ add_m7_m6_m1 => >+ { date => '2015-02-28', expected_age => 7, valid => 1 }, >+ add_m5_0_0 => >+ { date => '2015-02-28', expected_age => 5, valid => 1 }, >+ add_m5_0_p1 => >+ { date => '2015-02-28', expected_age => 5, valid => 0 }, >+ add_m5_0_m1 => >+ { date => '2015-02-27', expected_age => 5, valid => 1 }, >+ add_m11_0_0 => >+ { date => '2009-02-28', expected_age => 11, valid => 0 }, >+ add_m11_0_p1 => >+ { date => '2009-02-28', expected_age => 11, valid => 1 }, >+ add_m11_0_m1 => >+ { date => '2009-02-27', expected_age => 11, valid => 0 }, >+ }, >+ ); > >- my $add_m5_0_p1 = '2015-02-28'; >- $patron->dateofbirth( dt_from_string($add_m5_0_p1, 'iso')); >- is( $patron->is_valid_age, 0, 'Patron will celebrate the 5th birthday tomorrow, so the age is NOT allowed for this category'); >+ for my $date ( @dates ) { > >- my $add_m5_0_m1 = '2015-02-27'; >- $patron->dateofbirth( dt_from_string($add_m5_0_m1, 'iso')); >- is( $patron->is_valid_age, 1, 'Patron celebrated the 5th birthday yesterday, so the age is allowed for this category'); >+ my $dt = dt_from_string($date->{today}); > >- my $add_m11_0_p0 = '2009-02-28'; >- $patron->dateofbirth( dt_from_string($add_m11_0_p0, 'iso')); >- is( $patron->is_valid_age, 0, 'Patron celebrate the 11th birthday today, so the age is NOT allowed for this category'); >+ Time::Fake->offset( $dt->epoch ); > >- my $add_m11_0_p1 = '2009-02-28'; >- $patron->dateofbirth( dt_from_string($add_m11_0_p1, 'iso')); >- is( $patron->is_valid_age, 1, 'Patron will celebrate the 11th birthday tomorrow, so the age is allowed for this category'); >+ for my $k ( keys %$date ) { >+ next if $k eq 'today'; >+ >+ my $dob = $date->{$k}; >+ $patron->dateofbirth( dt_from_string( $dob->{date}, 'iso' ) ); >+ is( >+ $patron->is_valid_age, >+ $dob->{valid}, >+ sprintf( >+ "Today=%s, dob=%s, is %s, should be valid=%s", >+ $date->{today}, $dob->{date}, $dob->{expected_age}, $dob->{valid} >+ ) >+ ); >+ } > >- my $add_m11_0_m1 = '2009-02-27'; >- $patron->dateofbirth( dt_from_string($add_m11_0_m1, 'iso' )); >- is( $patron->is_valid_age, 0, 'Patron celebrated the 11th birthday yesterday, so the age is NOT allowed for this category'); >+ Time::Fake->reset; > >- Time::Fake->reset; >+ } > > $patron->delete; > $category->delete; >-- >2.20.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 24757
:
99861
|
99862
|
99863
|
99864
|
99865
|
99866
|
99867
|
99868
|
99982