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

(-)a/Koha/Library/Group.pm (+15 lines)
Lines 62-67 sub children { Link Here
62
    return wantarray ? $children->as_list : $children;
62
    return wantarray ? $children->as_list : $children;
63
}
63
}
64
64
65
=head3 has_child
66
67
my $has_child = $group->has_child( $branchcode );
68
69
Return true if the given branchcode library is a child of this group.
70
71
=cut
72
73
sub has_child {
74
    my ( $self, $branchcode ) = @_;
75
    return unless $branchcode; # Does not support group of libraries.
76
    return ( grep { $_ and $_ eq $branchcode }
77
          $self->children->get_column('branchcode') ) ? 1 : 0;
78
}
79
65
=head3 library
80
=head3 library
66
81
67
my $library = $group->library();
82
my $library = $group->library();
(-)a/t/db_dependent/LibraryGroups.t (-2 / +24 lines)
Lines 4-10 use Modern::Perl; Link Here
4
4
5
use List::MoreUtils 'any';
5
use List::MoreUtils 'any';
6
6
7
use Test::More tests => 16;
7
use Test::More tests => 17;
8
8
9
use t::lib::TestBuilder;
9
use t::lib::TestBuilder;
10
10
Lines 84-89 subtest 'Koha::Library->library_groups' => sub { Link Here
84
    is( $groups->count, 2, 'Library 1 should be part of 2 groups' );
84
    is( $groups->count, 2, 'Library 1 should be part of 2 groups' );
85
};
85
};
86
86
87
# root_group
88
#     + groupA
89
#         + groupA1
90
#             + groupA1_library2
91
#         + groupA_library1
92
#         + groupA2
93
#     + groupB
94
#         + groupB_library1
95
96
subtest 'Koha::Library::Group->has_child' => sub {
97
    plan tests => 2;
98
    is( $groupA->has_child( $library1->{branchcode} ), 1, 'library1 should be condidered as a child of groupA' );
99
    is( $groupB->has_child( $library2->{branchcode} ), 0, 'library2 should not be considered as a child of groupB' );
100
101
    # TODO This is not implemented because not used yet
102
    # ->has_child only works with libraries
103
    #is( $groupA->has_child( $groupA1 ), 1, 'groupA1 should be condidered as a child of groupA' );
104
105
    # FIXME At the time of writing this test fails because the ->children methods does not return more than 1 level of depth
106
    # See Bug 15707 comments 166-170+
107
    #is( $groupA->has_child( $groupA1_library2->branchcode ), 1, 'groupA1_library2 should be considered as a child of groupA (it is a grandchild)' );
108
};
109
87
my $groupX = Koha::Library::Group->new( { title => "Group X" } )->store();
110
my $groupX = Koha::Library::Group->new( { title => "Group X" } )->store();
88
my $groupX_library1 = Koha::Library::Group->new({ parent_id => $groupX->id,  branchcode => $library1->{branchcode} })->store();
111
my $groupX_library1 = Koha::Library::Group->new({ parent_id => $groupX->id,  branchcode => $library1->{branchcode} })->store();
89
my $groupX_library2 = Koha::Library::Group->new({ parent_id => $groupX->id,  branchcode => $library2->{branchcode} })->store();
112
my $groupX_library2 = Koha::Library::Group->new({ parent_id => $groupX->id,  branchcode => $library2->{branchcode} })->store();
90
- 

Return to bug 18403