From bba409898f73032362e14dc5f7ea9a20bd32f36c Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Thu, 27 Aug 2020 15:51:45 +0200 Subject: [PATCH] Bug 26307: Add a unit test for too_young In unit test for update patron categories : Changes $child1 to bee 4 years 11 month old => is under age Add $child1bis having exactly the lower age limit of 5 years => is not under age Run t/db_dependent/Patrons.t Test is to renforce the test suite, it is OK event without next patch --- t/db_dependent/Patrons.t | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/t/db_dependent/Patrons.t b/t/db_dependent/Patrons.t index 5d8a5056c9..d855d29b13 100755 --- a/t/db_dependent/Patrons.t +++ b/t/db_dependent/Patrons.t @@ -147,13 +147,21 @@ subtest "Update patron categories" => sub { } }); $prof->add_guarantor({guarantor_id => $inst->borrowernumber, relationship => 'test'}); + # Child beeing 4 years 11 months old => should be under age my $child1 = $builder->build_object({class => 'Koha::Patrons', value => { - dateofbirth => dt_from_string->add(years=>-4), + dateofbirth => dt_from_string->add( years => -5, days => 1 ), categorycode=>$c_categorycode, branchcode=>$branchcode1, } }); $child1->add_guarantor({guarantor_id => $adult1->borrowernumber, relationship => 'test'}); + # Patron beeing exactly 5 years old => should not be under age + my $child1bis = $builder->build_object({class => 'Koha::Patrons', value => { + dateofbirth => dt_from_string->add( years => -5 ), + categorycode=>$c_categorycode, + branchcode=>$branchcode1, + } + }); my $child2 = $builder->build_object({class => 'Koha::Patrons', value => { dateofbirth => dt_from_string->add(years=>-8), categorycode=>$c_categorycode, @@ -161,6 +169,7 @@ subtest "Update patron categories" => sub { } }); $child2->add_guarantor({guarantor_id => $adult1->borrowernumber, relationship => 'test'}); + # Patron beeing 17 years 11 months old => should not be over age my $child3 = $builder->build_object({class => 'Koha::Patrons', value => { dateofbirth => dt_from_string->add( years => -18, days => 1 ), categorycode=>$c_categorycode, @@ -168,6 +177,7 @@ subtest "Update patron categories" => sub { } }); $child3->add_guarantor({guarantor_id => $adult1->borrowernumber, relationship => 'test'}); + # Patron beeing exactly 18 years old => should be over age my $child4 = $builder->build_object({class => 'Koha::Patrons', value => { surname => 'child4', dateofbirth => dt_from_string->add( years => -18 ), @@ -178,7 +188,7 @@ subtest "Update patron categories" => sub { $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,4,'Four patrons in child category'); + is( Koha::Patrons->search_patrons_to_update_category({from=>$c_categorycode})->count,5,'Five 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'); @@ -198,7 +208,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}),4,'Four 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}),5,'Five 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