From 7e9ab97390b8cad111bbe9853dc0e27172719c27 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 29 Nov 2018 14:11:36 +0000 Subject: [PATCH] Bug 21910: Koha::Library::Groups->get_search_groups should return the groups To test: 1 - Add a library group (Admin->Library groups) 2 - Enable use as an opac and staff search limit 3 - Add some libraries to the group 4 - Visit advanced search on staff and opac 5 - Note the dropdown has as many empty rows as there are libraries in the group 6 - Apply patch, restart all the things 7 - Visit staff and opac advanced search 8 - Confirm the group dropdowns are correct 9 - Enable OpacMastheadLibraryPulldown 10 - Ensure the dropdown on opac shows groups correctly 11 - Confirm earchign groups works from all three locations 12 - prove -v t/db_dependent/LibraryGroups.t Signed-off-by: Martin Renvoize Signed-off-by: Josef Moravec Signed-off-by: Jonathan Druart Signed-off-by: Nick Clemens (cherry picked from commit f3b8c66392098d69bca48bbf04b7e93fa2100280) Signed-off-by: Martin Renvoize --- Koha/Library/Groups.pm | 8 ++------ t/db_dependent/LibraryGroups.t | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Koha/Library/Groups.pm b/Koha/Library/Groups.pm index 4bad9e1512..d4521b0620 100644 --- a/Koha/Library/Groups.pm +++ b/Koha/Library/Groups.pm @@ -62,13 +62,9 @@ sub get_search_groups { my $field = $interface eq 'staff' ? 'ft_search_groups_staff' : 'ft_search_groups_opac'; - my @search_groups = $self->search( { $field => 1 } ); + my $search_groups = $self->search( { $field => 1 } ); - return unless @search_groups; - - my @children = map { $_->children() } @search_groups; - - return @children; + return wantarray ? $search_groups->as_list : $search_groups; } =head3 type diff --git a/t/db_dependent/LibraryGroups.t b/t/db_dependent/LibraryGroups.t index 4b60777a7d..02d20651e1 100644 --- a/t/db_dependent/LibraryGroups.t +++ b/t/db_dependent/LibraryGroups.t @@ -4,7 +4,7 @@ use Modern::Perl; use List::MoreUtils 'any'; -use Test::More tests => 19; +use Test::More tests => 20; use t::lib::TestBuilder; @@ -107,6 +107,31 @@ subtest 'Koha::Library::Group->has_child' => sub { #is( $groupA->has_child( $groupA1_library2->branchcode ), 1, 'groupA1_library2 should be considered as a child of groupA (it is a grandchild)' ); }; +subtest 'Koha::Library::Group->get_search_groups' => sub { + plan tests => 2; + + #Enable as search groups + $groupA->ft_search_groups_opac(1)->store(); + $groupB->ft_search_groups_staff(1)->store(); + + #Update the objects + $groupA = Koha::Library::Groups->find( $groupA->id ); + $groupB = Koha::Library::Groups->find( $groupB->id ); + + my @groups = Koha::Library::Groups->get_search_groups({ interface => 'opac' }); + is_deeply( $groups[0]->unblessed, $groupA->unblessed, 'Get search groups opac should return enabled group' ); + @groups = Koha::Library::Groups->get_search_groups({ interface => 'staff' }); + is_deeply( $groups[0]->unblessed, $groupB->unblessed, 'Get search groups staff should return enabled group' ); + + # TODO This is not implemented because not used yet + # ->has_child only works with libraries + #is( $groupA->has_child( $groupA1 ), 1, 'groupA1 should be condidered as a child of groupA' ); + + # FIXME At the time of writing this test fails because the ->children methods does not return more than 1 level of depth + # See Bug 15707 comments 166-170+ + #is( $groupA->has_child( $groupA1_library2->branchcode ), 1, 'groupA1_library2 should be considered as a child of groupA (it is a grandchild)' ); +}; + my $groupX = Koha::Library::Group->new( { title => "Group X" } )->store(); my $groupX_library1 = Koha::Library::Group->new({ parent_id => $groupX->id, branchcode => $library1->{branchcode} })->store(); my $groupX_library2 = Koha::Library::Group->new({ parent_id => $groupX->id, branchcode => $library2->{branchcode} })->store(); -- 2.39.5