From 4d5d8809b5b0f63d457a71924837e69b38fa647f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20=C5=A0iman?= Date: Tue, 10 Oct 2017 11:46:01 +0200 Subject: [PATCH] Bug 17492: (followup) Added missing tests This patch only adds a missing condition to test defined age in is_category_valid method. The other task of this patch is to add missing automated db-dependent tests. Test plan: 1) Apply patch 2) Create a patron and assign him a category having age limits set 3) Change patron's age to be older/younger than category's limits 4) At "Check out" and "Details" tabs you should see a warning with a button allowing to change the category, eg.: - http://prntscr.com/cz7ch3 - http://prntscr.com/cz7em4 - http://prntscr.com/cz7dj1 5) Set a valid category according to patron's age 6) Warning should disappear 7) Perform similar test again, but instead of changing the age change the limits of a category 8) During tests verify "Change category" button everytime opens "Modify patron" page: http://prntscr.com/cz7g5q 9) Ensure that left-side panel is always on its expected place 10) Remove patron's date of birth and test that all categories are allowed now 11) Run automated tests: prove t/db_dependent/Koha/Patron.t Signed-off-by: Katrin Fischer --- Koha/Patron.pm | 2 +- t/db_dependent/Koha/Patrons.t | 60 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index d444111..982bc05 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -583,7 +583,7 @@ sub is_category_valid { my $patroncategory = $self->category; my ($low,$high) = ($patroncategory->dateofbirthrequired, $patroncategory->upperagelimit); - return (($high && ($age > $high)) or ($age < $low)) ? 0 : 1; + return (defined($age) && (($high && ($age > $high)) or ($age < $low))) ? 0 : 1; } =head3 account diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index a0a19fd..35b5d36 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 22; +use Test::More tests => 23; use Test::Warn; use Time::Fake; use DateTime; @@ -531,6 +531,64 @@ subtest 'get_age' => sub { $patron->delete; }; +subtest 'is_category_valid' => sub { + plan tests => 10; + + my $today = dt_from_string; + + my $category = $builder->build({ + source => 'Category', + value => { + categorycode => 'AGE_5_10', + dateofbirthrequired => 5, + upperagelimit => 10 + } + }); + $category = Koha::Patron::Categories->find( $category->{categorycode} ); + + my $patron = $builder->build({ + source => 'Borrower', + value => { + categorycode => 'AGE_5_10' + } + }); + $patron = Koha::Patrons->find( $patron->{borrowernumber} ); + + + $patron->dateofbirth( undef ); + is( $patron->is_category_valid, 1, 'Patron with no dateofbirth is always valid for any category'); + + $patron->dateofbirth( $today->clone->add( years => -12, months => -6, days => -1 ) ); + is( $patron->is_category_valid, 0, 'Patron is 12, so his age is above allowed range 5-10 years'); + + $patron->dateofbirth( $today->clone->add( years => -3, months => -6, days => -1 ) ); + is( $patron->is_category_valid, 0, 'Patron is 3, so his age is below allowed range 5-10 years'); + + $patron->dateofbirth( $today->clone->add( years => -7, months => -6, days => -1 ) ); + is( $patron->is_category_valid, 1, 'Patron is 7, so his age perfectly suits allowed range 5-10 years'); + + $patron->dateofbirth( $today->clone->add( years => -5, months => 0, days => 0 ) ); + is( $patron->is_category_valid, 1, 'Patron celebrates the 5th birthday today, so he is allowed for this category'); + + $patron->dateofbirth( $today->clone->add( years => -5, months => 0, days => 1 ) ); + is( $patron->is_category_valid, 0, 'Patron will celebrate the 5th birthday tomorrow, so he is NOT allowed for this category'); + + $patron->dateofbirth( $today->clone->add( years => -5, months => 0, days => -1 ) ); + is( $patron->is_category_valid, 1, 'Patron celebrated the 5th birthday yesterday, so he is allowed for this category'); + + $patron->dateofbirth( $today->clone->add( years => -11, months => 0, days => 0 ) ); + is( $patron->is_category_valid, 0, 'Patron celebrate the 11th birthday today, so he is NOT allowed for this category'); + + $patron->dateofbirth( $today->clone->add( years => -11, months => 0, days => 1 ) ); + is( $patron->is_category_valid, 1, 'Patron will celebrate the 11th birthday tomorrow, so he is allowed for this category'); + + $patron->dateofbirth( $today->clone->add( years => -11, months => 0, days => -1 ) ); + is( $patron->is_category_valid, 0, 'Patron celebrated the 11th birthday yesterday, so he is NOT allowed for this category'); + + $patron->delete; + $category->delete; +}; + subtest 'account' => sub { plan tests => 1; -- 2.1.4