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
use List::MoreUtils 'any';
-use Test::More tests => 19;
+use Test::More tests => 20;
use t::lib::TestBuilder;
#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();