View | Details | Raw Unified | Return to bug 27071
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Libraries.t (-10 / +32 lines)
Lines 247-279 subtest 'cash_registers' => sub { Link Here
247
247
248
subtest 'get_hold_libraries and validate_hold_sibling' => sub {
248
subtest 'get_hold_libraries and validate_hold_sibling' => sub {
249
249
250
    plan tests => 5;
250
    plan tests => 12;
251
251
252
    $schema->storage->txn_begin;
252
    $schema->storage->txn_begin;
253
253
254
    my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
254
    my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
255
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
255
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
256
    my $library3 = $builder->build_object( { class => 'Koha::Libraries' } );
256
    my $library3 = $builder->build_object( { class => 'Koha::Libraries' } );
257
    my $library4 = $builder->build_object( { class => 'Koha::Libraries' } );
258
    my $library5 = $builder->build_object( { class => 'Koha::Libraries' } );
259
260
    my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
261
    my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
262
    # G1
263
    $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } );
264
    $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } );
265
    # G2
266
    $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } );
267
    $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } );
268
    $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library5->branchcode } } );
269
270
    my @hold_libraries_1 = ($library1, $library2);
271
    my @hold_libraries_2 = ($library3, $library4, $library5);
257
272
258
    my $root = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
273
    my @result = $library1->get_hold_libraries();
259
    my $g1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root->id, branchcode => $library1->branchcode } } );
274
    # library1 and library2 are siblings
260
    my $g2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root->id, branchcode => $library2->branchcode } } );
275
    is(scalar(@result), 2, 'get_hold_libraries returns 2 libraries');
261
276
262
    my @hold_libraries = ($library1, $library2);
277
    my %map = map {$_->branchcode, 1} @result;
263
278
264
    my @result = $library1->get_hold_libraries();
279
    foreach my $hold_library ( @hold_libraries_1 ) {
280
        ok(exists $map{$hold_library->branchcode}, 'library in hold group');
281
    }
265
282
266
    ok(scalar(@result) == 2, 'get_hold_libraries returns 2 libraries');
283
    @result = $library3->get_hold_libraries();
284
    # library3, library4 and library5 are siblings
285
    is(scalar(@result), 3, 'get_hold_libraries returns 3 libraries');
267
286
268
    my %map = map {$_->branchcode, 1} @result;
287
    %map = map {$_->branchcode, 1} @result;
269
288
270
    foreach my $hold_library ( @hold_libraries ) {
289
    foreach my $hold_library ( @hold_libraries_2 ) {
271
        ok(exists $map{$hold_library->branchcode}, 'library in hold group');
290
        ok(exists $map{$hold_library->branchcode}, 'library in hold group');
272
    }
291
    }
273
292
274
    ok($library1->validate_hold_sibling( { branchcode => $library2->branchcode } ), 'Library 2 is a valid hold sibling');
293
    ok($library1->validate_hold_sibling( { branchcode => $library2->branchcode } ), 'Library 2 is a valid hold sibling');
275
    ok(!$library1->validate_hold_sibling( { branchcode => $library3->branchcode } ), 'Library 3 is not a valid hold sibling');
294
    ok(!$library1->validate_hold_sibling( { branchcode => $library3->branchcode } ), 'Library 3 is not a valid hold sibling');
276
295
296
    ok($library3->validate_hold_sibling( { branchcode => $library4->branchcode } ), 'Library 4 is a valid hold sibling');
297
    ok($library3->validate_hold_sibling( { branchcode => $library5->branchcode } ), 'Library 5 is a valid hold sibling');
298
    ok(!$library3->validate_hold_sibling( { branchcode => $library2->branchcode } ), 'Library 2 is not a valid hold sibling');
299
277
    $schema->storage->txn_rollback;
300
    $schema->storage->txn_rollback;
278
301
279
};
302
};
280
- 

Return to bug 27071