From b2ed82403b2a34bed904bee8a65b1d2fdb514141 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 31 Aug 2020 08:33:05 -0400 Subject: [PATCH] Bug 19382: Tests refactoring [alternate] --- t/db_dependent/Koha/Patron.t | 66 ++++++------------------------------ 1 file changed, 11 insertions(+), 55 deletions(-) diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t index 045c201fe5..d91d5b8128 100644 --- a/t/db_dependent/Koha/Patron.t +++ b/t/db_dependent/Koha/Patron.t @@ -97,69 +97,25 @@ subtest 'relationships_debt() tests' => sub { is( $parent_1->guarantee_relationships->guarantees->count, 2, 'Parent 1 has correct number of guarantors' ); is( $parent_2->guarantee_relationships->guarantees->count, 2, 'Parent 2 has correct number of guarantors' ); - # 3 params, count from 0 to 7 in binary ( 3 places ) to get the set of switches, then do that 4 times, one for each parent and child + # 3 params, count from 0 to 6 in binary ( 3 places ) to get the set of switches, then do that 4 times, one for each parent and child for my $i ( 0 .. 7 ) { my ( $only_this_guarantor, $include_guarantors, $include_this_patron ) = split '', sprintf( "%03b", $i ); - for my $patron ( $parent_1, $parent_2, $child_1, $child_2 ) { - is( - $patron->relationships_debt( - { - only_this_guarantor => $only_this_guarantor, - include_guarantors => $include_guarantors, - include_this_patron => $include_this_patron - } - ), 0, 'Family debt is correct' - ); + for my $patron ( $child_1, $child_2, $parent_1, $parent_2 ) { + is( $patron->relationships_debt( { only_this_guarantor => $only_this_guarantor, include_guarantors => $include_guarantors, include_this_patron => $include_this_patron } ), 0, 'Family debt is correct' ); } } - - my $child_2_debt = 10; - $child_2->account->add_debit({ type => 'ACCOUNT', amount => $child_2_debt, interface => 'commandline' }); + $child_2->account->add_debit({ type => 'ACCOUNT', amount => 10, interface => 'commandline' }); is( $child_2->account->non_issues_charges, 10, 'Child 2 owes correct amount' ); + for my $i ( 0 .. 7 ) { my ( $only_this_guarantor, $include_guarantors, $include_this_patron ) = split '', sprintf( "%03b", $i ); - is( - $parent_1->relationships_debt( - { - only_this_guarantor => $only_this_guarantor, - include_guarantors => $include_guarantors, - include_this_patron => $include_this_patron - } - ), - $child_2_debt, "parent 1 debt is correct (only_this_guarantor => $only_this_guarantor, include_guarantors => $include_guarantors, include_this_patron => $include_this_patron" - ); - is( - $parent_2->relationships_debt( - { - only_this_guarantor => $only_this_guarantor, - include_guarantors => $include_guarantors, - include_this_patron => $include_this_patron - } - ), - $child_2_debt, "parent 2 debt is correct (only_this_guarantor => $only_this_guarantor, include_guarantors => $include_guarantors, include_this_patron => $include_this_patron" - ); - is( - $child_1->relationships_debt( - { - only_this_guarantor => $only_this_guarantor, - include_guarantors => $include_guarantors, - include_this_patron => $include_this_patron - } - ), - $child_2_debt, "child 1 debt is correct (only_this_guarantor => $only_this_guarantor, include_guarantors => $include_guarantors, include_this_patron => $include_this_patron" - ); - - is( - $child_2->relationships_debt( - { - only_this_guarantor => $only_this_guarantor, - include_guarantors => $include_guarantors, - include_this_patron => $include_this_patron - } - ), - ( $include_this_patron && $child_2_debt ) ? $child_2_debt : 0, "child 2 debt is correct (only_this_guarantor => $only_this_guarantor, include_guarantors => $include_guarantors, include_this_patron => $include_this_patron" - ); + for my $patron ( $child_1, $child_2, $parent_1, $parent_2 ) { + my $amount = 10; + $amount = 0 if ( $patron->id == $child_1->id && $i > 3 ); + $amount = 0 if ( $patron->id == $child_2->id && ( $i == 0 || $i == 2 || $i == 4 || $i == 5 || $i == 6 ) ); + is( $patron->relationships_debt( { only_this_guarantor => $only_this_guarantor, include_guarantors => $include_guarantors, include_this_patron => $include_this_patron } ), $amount, 'Family debt is correct' ); + } } $parent_1->account->add_debit({ type => 'ACCOUNT', amount => 10, interface => 'commandline' }); -- 2.24.1 (Apple Git-126)