|
Lines 82-91
subtest 'relationships_debt() tests' => sub {
Link Here
|
| 82 |
|
82 |
|
| 83 |
t::lib::Mocks::mock_preference( 'borrowerRelationship', 'parent' ); |
83 |
t::lib::Mocks::mock_preference( 'borrowerRelationship', 'parent' ); |
| 84 |
|
84 |
|
| 85 |
my $parent_1 = $builder->build_object({ class => 'Koha::Patrons' }); |
85 |
my $parent_1 = $builder->build_object({ class => 'Koha::Patrons', value => { firstname => "Parent 1" } }); |
| 86 |
my $parent_2 = $builder->build_object({ class => 'Koha::Patrons' }); |
86 |
my $parent_2 = $builder->build_object({ class => 'Koha::Patrons', value => { firstname => "Parent 2" } }); |
| 87 |
my $child_1 = $builder->build_object({ class => 'Koha::Patrons' }); |
87 |
my $child_1 = $builder->build_object({ class => 'Koha::Patrons', value => { firstname => "Child 1" } }); |
| 88 |
my $child_2 = $builder->build_object({ class => 'Koha::Patrons' }); |
88 |
my $child_2 = $builder->build_object({ class => 'Koha::Patrons', value => { firstname => "Child 2" } }); |
| 89 |
|
89 |
|
| 90 |
$child_1->add_guarantor({ guarantor_id => $parent_1->borrowernumber, relationship => 'parent' }); |
90 |
$child_1->add_guarantor({ guarantor_id => $parent_1->borrowernumber, relationship => 'parent' }); |
| 91 |
$child_1->add_guarantor({ guarantor_id => $parent_2->borrowernumber, relationship => 'parent' }); |
91 |
$child_1->add_guarantor({ guarantor_id => $parent_2->borrowernumber, relationship => 'parent' }); |
|
Lines 94-378
subtest 'relationships_debt() tests' => sub {
Link Here
|
| 94 |
|
94 |
|
| 95 |
is( $child_1->guarantor_relationships->guarantors->count, 2, 'Child 1 has correct number of guarantors' ); |
95 |
is( $child_1->guarantor_relationships->guarantors->count, 2, 'Child 1 has correct number of guarantors' ); |
| 96 |
is( $child_2->guarantor_relationships->guarantors->count, 2, 'Child 2 has correct number of guarantors' ); |
96 |
is( $child_2->guarantor_relationships->guarantors->count, 2, 'Child 2 has correct number of guarantors' ); |
| 97 |
is( $parent_1->guarantee_relationships->guarantees->count, 2, 'Parent 1 has correct number of guarantors' ); |
97 |
is( $parent_1->guarantee_relationships->guarantees->count, 2, 'Parent 1 has correct number of guarantees' ); |
| 98 |
is( $parent_2->guarantee_relationships->guarantees->count, 2, 'Parent 2 has correct number of guarantors' ); |
98 |
is( $parent_2->guarantee_relationships->guarantees->count, 2, 'Parent 2 has correct number of guarantees' ); |
| 99 |
|
99 |
|
| 100 |
# 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 |
100 |
my $patrons = [ $parent_1, $parent_2, $child_1, $child_2 ]; |
| 101 |
is( $parent_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
101 |
|
| 102 |
is( $parent_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
102 |
# First test: No debt |
| 103 |
is( $parent_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
103 |
my ($parent1_debt, $parent2_debt, $child1_debt, $child2_debt) = (0,0,0,0); |
| 104 |
is( $parent_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
104 |
_test_combinations($patrons, $parent1_debt,$parent2_debt,$child1_debt,$child2_debt); |
| 105 |
is( $parent_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
105 |
|
| 106 |
is( $parent_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
106 |
# Add debt to child_2 |
| 107 |
is( $parent_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
107 |
$child2_debt = 2; |
| 108 |
is( $parent_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
108 |
$child_2->account->add_debit({ type => 'ACCOUNT', amount => $child2_debt, interface => 'commandline' }); |
| 109 |
is( $parent_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
109 |
is( $child_2->account->non_issues_charges, $child2_debt, 'Debt added to Child 2' ); |
| 110 |
is( $parent_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
110 |
_test_combinations($patrons, $parent1_debt,$parent2_debt,$child1_debt,$child2_debt); |
| 111 |
is( $parent_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
111 |
|
| 112 |
is( $parent_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
112 |
$parent1_debt = 3; |
| 113 |
is( $parent_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
113 |
$parent_1->account->add_debit({ type => 'ACCOUNT', amount => $parent1_debt, interface => 'commandline' }); |
| 114 |
is( $parent_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
114 |
is( $parent_1->account->non_issues_charges, $parent1_debt, 'Debt added to Parent 1' ); |
| 115 |
is( $parent_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
115 |
_test_combinations($patrons, $parent1_debt,$parent2_debt,$child1_debt,$child2_debt); |
| 116 |
is( $parent_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
116 |
|
| 117 |
is( $child_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
117 |
$parent2_debt = 5; |
| 118 |
is( $child_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
118 |
$parent_2->account->add_debit({ type => 'ACCOUNT', amount => $parent2_debt, interface => 'commandline' }); |
| 119 |
is( $child_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
119 |
is( $parent_2->account->non_issues_charges, $parent2_debt, 'Parent 2 owes correct amount' ); |
| 120 |
is( $child_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
120 |
_test_combinations($patrons, $parent1_debt,$parent2_debt,$child1_debt,$child2_debt); |
| 121 |
|
121 |
|
| 122 |
throws_ok { |
122 |
$child1_debt = 7; |
| 123 |
is( $child_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
123 |
$child_1->account->add_debit({ type => 'ACCOUNT', amount => $child1_debt, interface => 'commandline' }); |
| 124 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
124 |
is( $child_1->account->non_issues_charges, $child1_debt, 'Child 1 owes correct amount' ); |
| 125 |
throws_ok { |
125 |
_test_combinations($patrons, $parent1_debt,$parent2_debt,$child1_debt,$child2_debt); |
| 126 |
is( $child_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
|
|
| 127 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 128 |
throws_ok { |
| 129 |
is( $child_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 130 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 131 |
throws_ok { |
| 132 |
is( $child_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
| 133 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 134 |
|
| 135 |
is( $child_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 136 |
is( $child_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
| 137 |
is( $child_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 138 |
is( $child_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
| 139 |
|
| 140 |
throws_ok { |
| 141 |
is( $child_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 142 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 143 |
throws_ok { |
| 144 |
is( $child_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
| 145 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 146 |
throws_ok { |
| 147 |
is( $child_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 148 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 149 |
throws_ok { |
| 150 |
is( $child_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
| 151 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 152 |
|
| 153 |
$child_2->account->add_debit({ type => 'ACCOUNT', amount => 10, interface => 'commandline' }); |
| 154 |
is( $child_2->account->non_issues_charges, 10, 'Child 2 owes correct amount' ); |
| 155 |
|
| 156 |
is( $parent_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 157 |
is( $parent_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 158 |
is( $parent_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 159 |
is( $parent_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 160 |
is( $parent_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 161 |
is( $parent_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 162 |
is( $parent_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 163 |
is( $parent_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 164 |
is( $parent_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 165 |
is( $parent_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 166 |
is( $parent_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 167 |
is( $parent_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 168 |
is( $parent_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 169 |
is( $parent_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 170 |
is( $parent_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 171 |
is( $parent_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 172 |
is( $child_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 173 |
is( $child_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 174 |
is( $child_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 175 |
is( $child_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 176 |
|
| 177 |
throws_ok { |
| 178 |
is( $child_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 179 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 180 |
throws_ok { |
| 181 |
is( $child_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
| 182 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 183 |
throws_ok { |
| 184 |
is( $child_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 185 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 186 |
throws_ok { |
| 187 |
is( $child_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
| 188 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 189 |
|
| 190 |
is( $child_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 191 |
is( $child_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 192 |
is( $child_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 193 |
is( $child_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 194 |
|
| 195 |
throws_ok { |
| 196 |
is( $child_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 197 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 198 |
throws_ok { |
| 199 |
is( $child_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
| 200 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 201 |
throws_ok { |
| 202 |
is( $child_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 203 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 204 |
throws_ok { |
| 205 |
is( $child_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 206 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 207 |
|
| 208 |
$parent_1->account->add_debit({ type => 'ACCOUNT', amount => 10, interface => 'commandline' }); |
| 209 |
is( $parent_1->account->non_issues_charges, 10, 'Parent 1 owes correct amount' ); |
| 210 |
|
| 211 |
is( $parent_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 212 |
is( $parent_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 213 |
is( $parent_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 214 |
is( $parent_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 1 }), 20, 'Family debt is correct' ); |
| 215 |
is( $parent_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 216 |
is( $parent_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 217 |
is( $parent_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 218 |
is( $parent_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 1 }), 20, 'Family debt is correct' ); |
| 219 |
is( $parent_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 220 |
is( $parent_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 221 |
is( $parent_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 0 }), 20, 'Family debt is correct' ); |
| 222 |
is( $parent_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 1 }), 20, 'Family debt is correct' ); |
| 223 |
is( $parent_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 224 |
is( $parent_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 225 |
is( $parent_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 226 |
is( $parent_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 227 |
is( $child_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 228 |
is( $child_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 229 |
is( $child_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 0 }), 20, 'Family debt is correct' ); |
| 230 |
is( $child_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 1 }), 20, 'Family debt is correct' ); |
| 231 |
|
| 232 |
throws_ok { |
| 233 |
is( $child_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 234 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 235 |
throws_ok { |
| 236 |
is( $child_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
| 237 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 238 |
throws_ok { |
| 239 |
is( $child_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 240 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 241 |
throws_ok { |
| 242 |
is( $child_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
| 243 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 244 |
|
| 245 |
is( $child_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 246 |
is( $child_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 247 |
is( $child_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 248 |
is( $child_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 1 }), 20, 'Family debt is correct' ); |
| 249 |
|
| 250 |
throws_ok { |
| 251 |
is( $child_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 252 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 253 |
throws_ok { |
| 254 |
is( $child_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
| 255 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 256 |
throws_ok { |
| 257 |
is( $child_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 258 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 259 |
throws_ok { |
| 260 |
is( $child_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 261 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 262 |
|
| 263 |
$parent_2->account->add_debit({ type => 'ACCOUNT', amount => 10, interface => 'commandline' }); |
| 264 |
is( $parent_2->account->non_issues_charges, 10, 'Parent 2 owes correct amount' ); |
| 265 |
|
| 266 |
is( $parent_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 267 |
is( $parent_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 268 |
is( $parent_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 0 }), 20, 'Family debt is correct' ); |
| 269 |
is( $parent_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 1 }), 30, 'Family debt is correct' ); |
| 270 |
is( $parent_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 271 |
is( $parent_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 272 |
is( $parent_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 273 |
is( $parent_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 1 }), 20, 'Family debt is correct' ); |
| 274 |
is( $parent_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 275 |
is( $parent_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 276 |
is( $parent_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 0 }), 20, 'Family debt is correct' ); |
| 277 |
is( $parent_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 1 }), 30, 'Family debt is correct' ); |
| 278 |
is( $parent_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 279 |
is( $parent_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 280 |
is( $parent_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 281 |
is( $parent_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 1 }), 20, 'Family debt is correct' ); |
| 282 |
is( $child_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 283 |
is( $child_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 284 |
is( $child_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 0 }), 30, 'Family debt is correct' ); |
| 285 |
is( $child_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 1 }), 30, 'Family debt is correct' ); |
| 286 |
|
| 287 |
throws_ok { |
| 288 |
is( $child_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 289 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 290 |
throws_ok { |
| 291 |
is( $child_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
| 292 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 293 |
throws_ok { |
| 294 |
is( $child_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 295 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 296 |
throws_ok { |
| 297 |
is( $child_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
| 298 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 299 |
|
| 300 |
is( $child_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 301 |
is( $child_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 302 |
is( $child_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 0 }), 20, 'Family debt is correct' ); |
| 303 |
is( $child_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 1 }), 30, 'Family debt is correct' ); |
| 304 |
|
| 305 |
throws_ok { |
| 306 |
is( $child_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 307 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 308 |
throws_ok { |
| 309 |
is( $child_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
| 310 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 311 |
throws_ok { |
| 312 |
is( $child_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 313 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 314 |
throws_ok { |
| 315 |
is( $child_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 316 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 317 |
|
| 318 |
$child_1->account->add_debit({ type => 'ACCOUNT', amount => 10, interface => 'commandline' }); |
| 319 |
is( $child_1->account->non_issues_charges, 10, 'Child 1 owes correct amount' ); |
| 320 |
|
| 321 |
is( $parent_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 0 }), 20, 'Family debt is correct' ); |
| 322 |
is( $parent_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 1 }), 20, 'Family debt is correct' ); |
| 323 |
is( $parent_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 0 }), 30, 'Family debt is correct' ); |
| 324 |
is( $parent_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 1 }), 40, 'Family debt is correct' ); |
| 325 |
is( $parent_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 0 }), 20, 'Family debt is correct' ); |
| 326 |
is( $parent_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 1 }), 20, 'Family debt is correct' ); |
| 327 |
is( $parent_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 0 }), 20, 'Family debt is correct' ); |
| 328 |
is( $parent_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 1 }), 30, 'Family debt is correct' ); |
| 329 |
is( $parent_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 0 }), 20, 'Family debt is correct' ); |
| 330 |
is( $parent_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 1 }), 20, 'Family debt is correct' ); |
| 331 |
is( $parent_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 0 }), 30, 'Family debt is correct' ); |
| 332 |
is( $parent_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 1 }), 40, 'Family debt is correct' ); |
| 333 |
is( $parent_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 0 }), 20, 'Family debt is correct' ); |
| 334 |
is( $parent_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 1 }), 20, 'Family debt is correct' ); |
| 335 |
is( $parent_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 0 }), 20, 'Family debt is correct' ); |
| 336 |
is( $parent_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 1 }), 30, 'Family debt is correct' ); |
| 337 |
is( $child_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 338 |
is( $child_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 1 }), 20, 'Family debt is correct' ); |
| 339 |
is( $child_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 0 }), 30, 'Family debt is correct' ); |
| 340 |
is( $child_1->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 1 }), 40, 'Family debt is correct' ); |
| 341 |
|
| 342 |
throws_ok { |
| 343 |
is( $child_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 344 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 345 |
throws_ok { |
| 346 |
is( $child_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
| 347 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 348 |
throws_ok { |
| 349 |
is( $child_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 350 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 351 |
throws_ok { |
| 352 |
is( $child_1->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 353 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 354 |
|
| 355 |
is( $child_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 0 }), 10, 'Family debt is correct' ); |
| 356 |
is( $child_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 0, include_this_patron => 1 }), 20, 'Family debt is correct' ); |
| 357 |
is( $child_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 0 }), 30, 'Family debt is correct' ); |
| 358 |
is( $child_2->relationships_debt({ only_this_guarantor => 0, include_guarantors => 1, include_this_patron => 1 }), 40, 'Family debt is correct' ); |
| 359 |
|
| 360 |
throws_ok { |
| 361 |
is( $child_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 362 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 363 |
throws_ok { |
| 364 |
is( $child_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 0, include_this_patron => 1 }), 0, 'Family debt is correct' ); |
| 365 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 366 |
throws_ok { |
| 367 |
is( $child_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 0 }), 0, 'Family debt is correct' ); |
| 368 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 369 |
throws_ok { |
| 370 |
is( $child_2->relationships_debt({ only_this_guarantor => 1, include_guarantors => 1, include_this_patron => 1 }), 10, 'Family debt is correct' ); |
| 371 |
} 'Koha::Exceptions::BadParameter', 'Exception is thrown as patron is not a guarantor'; |
| 372 |
|
126 |
|
| 373 |
$schema->storage->txn_rollback; |
127 |
$schema->storage->txn_rollback; |
| 374 |
}; |
128 |
}; |
| 375 |
|
129 |
|
|
|
130 |
sub _test_combinations { |
| 131 |
my ( $patrons, $parent1_debt, $parent2_debt, $child1_debt, $child2_debt ) = @_; |
| 132 |
|
| 133 |
# Options |
| 134 |
# P1 => P1 + C1 + C2 ( - P1 ) ( + P2 ) |
| 135 |
# P2 => P2 + C1 + C2 ( - P2 ) ( + P1 ) |
| 136 |
# C1 => P1 + P2 + C1 + C2 ( - C1 ) |
| 137 |
# C2 => P1 + P2 + C1 + C2 ( - C2 ) |
| 138 |
|
| 139 |
# 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 |
| 140 |
for my $i ( 0 .. 7 ) { |
| 141 |
my ( $only_this_guarantor, $include_guarantors, $include_this_patron ) |
| 142 |
= split '', sprintf( "%03b", $i ); |
| 143 |
for my $patron ( @$patrons ) { |
| 144 |
if ( $only_this_guarantor |
| 145 |
&& !$patron->guarantee_relationships->count ) |
| 146 |
{ |
| 147 |
throws_ok { |
| 148 |
$patron->relationships_debt( |
| 149 |
{ |
| 150 |
only_this_guarantor => $only_this_guarantor, |
| 151 |
include_guarantors => $include_guarantors, |
| 152 |
include_this_patron => $include_this_patron |
| 153 |
} |
| 154 |
); |
| 155 |
} |
| 156 |
'Koha::Exceptions::BadParameter', |
| 157 |
'Exception is thrown as patron is not a guarantor'; |
| 158 |
|
| 159 |
} |
| 160 |
else { |
| 161 |
|
| 162 |
my $debt = 0; |
| 163 |
if ( $patron->firstname eq 'Parent 1' ) { |
| 164 |
$debt += $parent1_debt if ($include_this_patron && $include_guarantors); |
| 165 |
$debt += $child1_debt + $child2_debt; |
| 166 |
$debt += $parent2_debt unless ($only_this_guarantor || !$include_guarantors); |
| 167 |
} |
| 168 |
elsif ( $patron->firstname eq 'Parent 2' ) { |
| 169 |
$debt += $parent2_debt if ($include_this_patron & $include_guarantors); |
| 170 |
$debt += $child1_debt + $child2_debt; |
| 171 |
$debt += $parent1_debt unless ($only_this_guarantor || !$include_guarantors); |
| 172 |
} |
| 173 |
elsif ( $patron->firstname eq 'Child 1' ) { |
| 174 |
$debt += $child1_debt if ($include_this_patron); |
| 175 |
$debt += $child2_debt; |
| 176 |
$debt += $parent1_debt + $parent2_debt if ($include_guarantors); |
| 177 |
} |
| 178 |
else { |
| 179 |
$debt += $child2_debt if ($include_this_patron); |
| 180 |
$debt += $child1_debt; |
| 181 |
$debt += $parent1_debt + $parent2_debt if ($include_guarantors); |
| 182 |
} |
| 183 |
|
| 184 |
is( |
| 185 |
$patron->relationships_debt( |
| 186 |
{ |
| 187 |
only_this_guarantor => $only_this_guarantor, |
| 188 |
include_guarantors => $include_guarantors, |
| 189 |
include_this_patron => $include_this_patron |
| 190 |
} |
| 191 |
), |
| 192 |
$debt, |
| 193 |
$patron->firstname |
| 194 |
. " debt of $debt calculated correctly for ( only_this_guarantor: $only_this_guarantor, include_guarantors: $include_guarantors, include_this_patron: $include_this_patron)" |
| 195 |
); |
| 196 |
} |
| 197 |
} |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 376 |
subtest 'add_enrolment_fee_if_needed() tests' => sub { |
201 |
subtest 'add_enrolment_fee_if_needed() tests' => sub { |
| 377 |
|
202 |
|
| 378 |
plan tests => 2; |
203 |
plan tests => 2; |
| 379 |
- |
|
|