Lines 89-96
subtest 'relationships_debt() tests' => sub {
Link Here
|
89 |
|
89 |
|
90 |
my $parent_1 = $builder->build_object({ class => 'Koha::Patrons', value => { firstname => "Parent 1" } }); |
90 |
my $parent_1 = $builder->build_object({ class => 'Koha::Patrons', value => { firstname => "Parent 1" } }); |
91 |
my $parent_2 = $builder->build_object({ class => 'Koha::Patrons', value => { firstname => "Parent 2" } }); |
91 |
my $parent_2 = $builder->build_object({ class => 'Koha::Patrons', value => { firstname => "Parent 2" } }); |
92 |
my $child_1 = $builder->build_object({ class => 'Koha::Patrons', value => { firstname => "Child 1" } }); |
92 |
my $child_1 = $builder->build_object({ class => 'Koha::Patrons', value => { firstname => " Child 1" } }); |
93 |
my $child_2 = $builder->build_object({ class => 'Koha::Patrons', value => { firstname => "Child 2" } }); |
93 |
my $child_2 = $builder->build_object({ class => 'Koha::Patrons', value => { firstname => " Child 2" } }); |
94 |
|
94 |
|
95 |
$child_1->add_guarantor({ guarantor_id => $parent_1->borrowernumber, relationship => 'parent' }); |
95 |
$child_1->add_guarantor({ guarantor_id => $parent_1->borrowernumber, relationship => 'parent' }); |
96 |
$child_1->add_guarantor({ guarantor_id => $parent_2->borrowernumber, relationship => 'parent' }); |
96 |
$child_1->add_guarantor({ guarantor_id => $parent_2->borrowernumber, relationship => 'parent' }); |
Lines 134-140
subtest 'relationships_debt() tests' => sub {
Link Here
|
134 |
|
134 |
|
135 |
sub _test_combinations { |
135 |
sub _test_combinations { |
136 |
my ( $patrons, $parent1_debt, $parent2_debt, $child1_debt, $child2_debt ) = @_; |
136 |
my ( $patrons, $parent1_debt, $parent2_debt, $child1_debt, $child2_debt ) = @_; |
137 |
|
137 |
diag("Testing with parent 1 debt $parent1_debt | Parent 2 debt $parent2_debt | Child 1 debt $child1_debt | Child 2 debt $child2_debt"); |
138 |
# Options |
138 |
# Options |
139 |
# P1 => P1 + C1 + C2 ( - P1 ) ( + P2 ) |
139 |
# P1 => P1 + C1 + C2 ( - P1 ) ( + P2 ) |
140 |
# P2 => P2 + C1 + C2 ( - P2 ) ( + P1 ) |
140 |
# P2 => P2 + C1 + C2 ( - P2 ) ( + P1 ) |
Lines 145-150
sub _test_combinations {
Link Here
|
145 |
for my $i ( 0 .. 7 ) { |
145 |
for my $i ( 0 .. 7 ) { |
146 |
my ( $only_this_guarantor, $include_guarantors, $include_this_patron ) |
146 |
my ( $only_this_guarantor, $include_guarantors, $include_this_patron ) |
147 |
= split '', sprintf( "%03b", $i ); |
147 |
= split '', sprintf( "%03b", $i ); |
|
|
148 |
diag("---------------------"); |
148 |
for my $patron ( @$patrons ) { |
149 |
for my $patron ( @$patrons ) { |
149 |
if ( $only_this_guarantor |
150 |
if ( $only_this_guarantor |
150 |
&& !$patron->guarantee_relationships->count ) |
151 |
&& !$patron->guarantee_relationships->count ) |
Lines 175-181
sub _test_combinations {
Link Here
|
175 |
$debt += $child1_debt + $child2_debt; |
176 |
$debt += $child1_debt + $child2_debt; |
176 |
$debt += $parent1_debt unless ($only_this_guarantor || !$include_guarantors); |
177 |
$debt += $parent1_debt unless ($only_this_guarantor || !$include_guarantors); |
177 |
} |
178 |
} |
178 |
elsif ( $patron->firstname eq 'Child 1' ) { |
179 |
elsif ( $patron->firstname eq ' Child 1' ) { |
179 |
$debt += $child1_debt if ($include_this_patron); |
180 |
$debt += $child1_debt if ($include_this_patron); |
180 |
$debt += $child2_debt; |
181 |
$debt += $child2_debt; |
181 |
$debt += $parent1_debt + $parent2_debt if ($include_guarantors); |
182 |
$debt += $parent1_debt + $parent2_debt if ($include_guarantors); |
Lines 196-202
sub _test_combinations {
Link Here
|
196 |
), |
197 |
), |
197 |
$debt, |
198 |
$debt, |
198 |
$patron->firstname |
199 |
$patron->firstname |
199 |
. " debt of $debt calculated correctly for ( only_this_guarantor: $only_this_guarantor, include_guarantors: $include_guarantors, include_this_patron: $include_this_patron)" |
200 |
. " debt of " . sprintf('%02d',$debt) . " calculated correctly for ( only_this_guarantor: $only_this_guarantor, include_guarantors: $include_guarantors, include_this_patron: $include_this_patron)" |
200 |
); |
201 |
); |
201 |
} |
202 |
} |
202 |
} |
203 |
} |