From 8c1375acccd4e22588b1f3283518f13b1b5fcc12 Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Thu, 27 Aug 2020 14:14:19 +0200 Subject: [PATCH] Bug 26307: Reveal problem in unit test for too_old Logic : ======= Looking at Koha::Patron->get_age : At birthday aniversary, patron has aged 1 year more. For example : - today is 2020-08-27 - patron with date of birth 2000-08-28 is 19 year old - patron with date of birth 2000-08-27 is 20 year old Looking at Koha::Patron->is_valid_age : Category min and max limits are inclusive. For example max=17 means : - patron having 17 years old is valid - patron having 18 years old is not valid Test suite : =========== Changes child3 to have 18 years tomorrow. Adds a child4 with 18 years today. Test plan : Run prove t/db_dependent/Patrons.t See it fails on 'One under age patron in child category' --- t/db_dependent/Patrons.t | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/t/db_dependent/Patrons.t b/t/db_dependent/Patrons.t index 2aa964a28b..5d8a5056c9 100755 --- a/t/db_dependent/Patrons.t +++ b/t/db_dependent/Patrons.t @@ -162,20 +162,27 @@ subtest "Update patron categories" => sub { }); $child2->add_guarantor({guarantor_id => $adult1->borrowernumber, relationship => 'test'}); my $child3 = $builder->build_object({class => 'Koha::Patrons', value => { - dateofbirth => dt_from_string->add(years=>-18), + dateofbirth => dt_from_string->add( years => -18, days => 1 ), categorycode=>$c_categorycode, branchcode=>$branchcode1, } }); $child3->add_guarantor({guarantor_id => $adult1->borrowernumber, relationship => 'test'}); + my $child4 = $builder->build_object({class => 'Koha::Patrons', value => { + surname => 'child4', + dateofbirth => dt_from_string->add( years => -18 ), + categorycode=>$c_categorycode, + branchcode=>$branchcode1, + } + }); $builder->build({source=>'Accountline',value => {amountoutstanding=>4.99,borrowernumber=>$adult1->borrowernumber}}); $builder->build({source=>'Accountline',value => {amountoutstanding=>5.01,borrowernumber=>$adult2->borrowernumber}}); - is( Koha::Patrons->search_patrons_to_update_category({from=>$c_categorycode})->count,3,'Three patrons in child category'); + is( Koha::Patrons->search_patrons_to_update_category({from=>$c_categorycode})->count,4,'Four patrons in child category'); is( Koha::Patrons->search_patrons_to_update_category({from=>$c_categorycode,too_young=>1})->count,1,'One under age patron in child category'); is( Koha::Patrons->search_patrons_to_update_category({from=>$c_categorycode,too_young=>1})->next->borrowernumber,$child1->borrowernumber,'Under age patron in child category is expected one'); is( Koha::Patrons->search_patrons_to_update_category({from=>$c_categorycode,too_old=>1})->count,1,'One over age patron in child category'); - is( Koha::Patrons->search_patrons_to_update_category({from=>$c_categorycode,too_old=>1})->next->borrowernumber,$child3->borrowernumber,'Over age patron in child category is expected one'); + is( Koha::Patrons->search_patrons_to_update_category({from=>$c_categorycode,too_old=>1})->next->borrowernumber,$child4->borrowernumber,'Over age patron in child category is expected one'); is( Koha::Patrons->search({branchcode=>$branchcode2})->search_patrons_to_update_category({from=>$a_categorycode})->count,1,'One patron in branch 2'); is( Koha::Patrons->search({branchcode=>$branchcode2})->search_patrons_to_update_category({from=>$a_categorycode})->next->borrowernumber,$adult2->borrowernumber,'Adult patron in branch 2 is expected one'); is( Koha::Patrons->search_patrons_to_update_category({from=>$a_categorycode,fine_min=>5})->count,1,'One patron with fines over $5'); @@ -191,7 +198,7 @@ subtest "Update patron categories" => sub { is( Koha::Patrons->search_patrons_to_update_category({from=>$a_categorycode,fine_max=>5})->count,2,'Two patrons with fines under $5, patron with no fine history is found'); is( Koha::Patrons->find($adult1->borrowernumber)->guarantee_relationships->guarantees->count,3,'Guarantor has 3 guarantees'); - is( Koha::Patrons->search_patrons_to_update_category({from=>$c_categorycode})->update_category_to({category=>$c_categorycode_2}),3,'Three child patrons updated to another child category with no params passed'); + is( Koha::Patrons->search_patrons_to_update_category({from=>$c_categorycode})->update_category_to({category=>$c_categorycode_2}),4,'Four child patrons updated to another child category with no params passed'); is( Koha::Patrons->find($adult1->borrowernumber)->guarantee_relationships->guarantees->count,3,'Guarantees not removed when made changing child categories'); is( Koha::Patrons->search_patrons_to_update_category({from=>$c_categorycode_2,too_young=>1})->update_category_to({category=>$a_categorycode}),1,'One child patron updated to adult category'); is( Koha::Patrons->find($adult1->borrowernumber)->guarantee_relationships->guarantees->count,2,'Guarantee was removed when made adult'); -- 2.27.0