From 14ed371a49ec4a4eb875d7c30b2fd20cc0458d3e Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 24 Nov 2020 11:55:14 -0300 Subject: [PATCH] Bug 27071: More tests for Koha::Library->validate_hold_sibling This patch adds tests for more than one non-same sibling libraries in the hold group. Tests pass which means it is working as expected. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Libraries.t => SUCCESS: Tests pass Signed-off-by: Tomas Cohen Arazi Signed-off-by: David Nind --- t/db_dependent/Koha/Libraries.t | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/t/db_dependent/Koha/Libraries.t b/t/db_dependent/Koha/Libraries.t index b5e8d93b2a..4bed00d852 100755 --- a/t/db_dependent/Koha/Libraries.t +++ b/t/db_dependent/Koha/Libraries.t @@ -247,33 +247,56 @@ subtest 'cash_registers' => sub { subtest 'get_hold_libraries and validate_hold_sibling' => sub { - plan tests => 5; + plan tests => 12; $schema->storage->txn_begin; my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); my $library3 = $builder->build_object( { class => 'Koha::Libraries' } ); + my $library4 = $builder->build_object( { class => 'Koha::Libraries' } ); + my $library5 = $builder->build_object( { class => 'Koha::Libraries' } ); + + my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } ); + my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } ); + # G1 + $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } ); + $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } ); + # G2 + $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } ); + $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } ); + $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library5->branchcode } } ); + + my @hold_libraries_1 = ($library1, $library2); + my @hold_libraries_2 = ($library3, $library4, $library5); - my $root = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } ); - my $g1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root->id, branchcode => $library1->branchcode } } ); - my $g2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root->id, branchcode => $library2->branchcode } } ); + my @result = $library1->get_hold_libraries(); + # library1 and library2 are siblings + is(scalar(@result), 2, 'get_hold_libraries returns 2 libraries'); - my @hold_libraries = ($library1, $library2); + my %map = map {$_->branchcode, 1} @result; - my @result = $library1->get_hold_libraries(); + foreach my $hold_library ( @hold_libraries_1 ) { + ok(exists $map{$hold_library->branchcode}, 'library in hold group'); + } - ok(scalar(@result) == 2, 'get_hold_libraries returns 2 libraries'); + @result = $library3->get_hold_libraries(); + # library3, library4 and library5 are siblings + is(scalar(@result), 3, 'get_hold_libraries returns 3 libraries'); - my %map = map {$_->branchcode, 1} @result; + %map = map {$_->branchcode, 1} @result; - foreach my $hold_library ( @hold_libraries ) { + foreach my $hold_library ( @hold_libraries_2 ) { ok(exists $map{$hold_library->branchcode}, 'library in hold group'); } ok($library1->validate_hold_sibling( { branchcode => $library2->branchcode } ), 'Library 2 is a valid hold sibling'); ok(!$library1->validate_hold_sibling( { branchcode => $library3->branchcode } ), 'Library 3 is not a valid hold sibling'); + ok($library3->validate_hold_sibling( { branchcode => $library4->branchcode } ), 'Library 4 is a valid hold sibling'); + ok($library3->validate_hold_sibling( { branchcode => $library5->branchcode } ), 'Library 5 is a valid hold sibling'); + ok(!$library3->validate_hold_sibling( { branchcode => $library2->branchcode } ), 'Library 2 is not a valid hold sibling'); + $schema->storage->txn_rollback; }; -- 2.11.0