Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 37; |
20 |
use Test::More tests => 38; |
21 |
use Test::Warn; |
21 |
use Test::Warn; |
22 |
|
22 |
|
23 |
use C4::Context; |
23 |
use C4::Context; |
Lines 231-233
is( $patron->get_enrollable_clubs->count,
Link Here
|
231 |
is( $club->club_enrollments->count, 1, 'There is 1 enrollment for club' ); |
231 |
is( $club->club_enrollments->count, 1, 'There is 1 enrollment for club' ); |
232 |
|
232 |
|
233 |
$schema->storage->txn_rollback(); |
233 |
$schema->storage->txn_rollback(); |
234 |
- |
234 |
|
|
|
235 |
subtest 'filter_out_empty' => sub { |
236 |
plan tests => 2; |
237 |
|
238 |
$schema->storage->txn_begin(); |
239 |
|
240 |
Koha::Clubs->delete; |
241 |
|
242 |
my $club_template = $builder->build_object({ class => 'Koha::Club::Templates' }); |
243 |
|
244 |
# club_1 has 2 patrons |
245 |
my $club_1 = $builder->build_object( |
246 |
{ |
247 |
class => 'Koha::Clubs', |
248 |
value => { club_template_id => $club_template->id } |
249 |
} |
250 |
); |
251 |
|
252 |
# club_2 has 1 patron but they canceled enrollment |
253 |
my $club_2 = $builder->build_object( |
254 |
{ |
255 |
class => 'Koha::Clubs', |
256 |
value => { club_template_id => $club_template->id } |
257 |
} |
258 |
); |
259 |
|
260 |
# club_3 is empty |
261 |
my $club_3 = $builder->build_object( |
262 |
{ |
263 |
class => 'Koha::Clubs', |
264 |
value => { club_template_id => $club_template->id } |
265 |
} |
266 |
); |
267 |
|
268 |
my $patron_1 = $builder->build_object({ class => 'Koha::Patrons' }); |
269 |
my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' }); |
270 |
|
271 |
my $enrollment_1_1 = Koha::Club::Enrollment->new( |
272 |
{ |
273 |
club_id => $club_1->id, |
274 |
borrowernumber => $patron_1->borrowernumber, |
275 |
branchcode => $patron_1->branchcode, |
276 |
} |
277 |
)->store(); |
278 |
my $enrollment_2_1 = Koha::Club::Enrollment->new( |
279 |
{ |
280 |
club_id => $club_2->id, |
281 |
borrowernumber => $patron_1->borrowernumber, |
282 |
branchcode => $patron_1->branchcode, |
283 |
} |
284 |
)->store(); |
285 |
my $enrollment_1_2 = Koha::Club::Enrollment->new( |
286 |
{ |
287 |
club_id => $club_1->id, |
288 |
borrowernumber => $patron_2->borrowernumber, |
289 |
branchcode => $patron_2->branchcode, |
290 |
} |
291 |
)->store(); |
292 |
|
293 |
|
294 |
$enrollment_2_1->cancel; |
295 |
|
296 |
my $clubs = Koha::Clubs->search->filter_out_empty; |
297 |
is( $clubs->count, 1, 'Only one club has patron enrolled' ); |
298 |
is( $clubs->next->id, $club_1->id, 'Correct club is considered non-empty'); |
299 |
|
300 |
$schema->storage->txn_rollback(); |
301 |
} |