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 (-4 / +27 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 => 14;
7
use Test::More tests => 15;
8
8
9
use t::lib::TestBuilder;
9
use t::lib::TestBuilder;
10
10
Lines 80-94 ok( !$in_list, 'Method libraries_not_direct_children returns all libraries not d Link Here
80
$in_list = any { $_->id eq $groupA1_library2->branchcode } @libraries_not_direct_children;
80
$in_list = any { $_->id eq $groupA1_library2->branchcode } @libraries_not_direct_children;
81
ok( $in_list, 'Method libraries_not_direct_children returns all libraries not direct descendants of group, library 2 is in the list');
81
ok( $in_list, 'Method libraries_not_direct_children returns all libraries not direct descendants of group, library 2 is in the list');
82
82
83
$library1 = Koha::Libraries->find( $library1->{branchcode} );
84
$library2 = Koha::Libraries->find( $library2->{branchcode} );
85
$library3 = Koha::Libraries->find( $library3->{branchcode} );
83
subtest 'Koha::Library->library_groups' => sub {
86
subtest 'Koha::Library->library_groups' => sub {
84
    plan tests => 4;
87
    plan tests => 4;
85
    my $library3 = Koha::Libraries->find( $library3->{branchcode} );
86
    my $groups = $library3->library_groups;
88
    my $groups = $library3->library_groups;
87
    is( ref( $groups ), 'Koha::Library::Groups', 'Koha::Library->library_groups should return Koha::Library::Groups' );
89
    is( ref( $groups ), 'Koha::Library::Groups', 'Koha::Library->library_groups should return Koha::Library::Groups' );
88
    is( $groups->count, 0, 'Library 3 should not be part of any groups');
90
    is( $groups->count, 0, 'Library 3 should not be part of any groups');
89
91
90
    my $library1 = Koha::Libraries->find( $library1->{branchcode} );
91
    $groups = $library1->library_groups;
92
    $groups = $library1->library_groups;
92
    is( ref( $groups ), 'Koha::Library::Groups', 'Koha::Library->library_groups should return Koha::Library::Groups' );
93
    is( ref( $groups ), 'Koha::Library::Groups', 'Koha::Library->library_groups should return Koha::Library::Groups' );
93
    is( $groups->count, 2, 'Library 1 should be part of 2 groups' );
94
    is( $groups->count, 2, 'Library 1 should be part of 2 groups' );
94
};
95
};
95
- 
96
97
# root_group
98
#     + groupA
99
#         + groupA1
100
#             + groupA1_library2
101
#         + groupA_library1
102
#         + groupA2
103
#     + groupB
104
#         + groupB_library1
105
106
subtest 'Koha::Library::Group->has_child' => sub {
107
    plan tests => 2;
108
    is( $groupA->has_child( $library1->branchcode ), 1, 'library1 should be condidered as a child of groupA' );
109
    is( $groupB->has_child( $library2->branchcode ), 0, 'library2 should not be considered as a child of groupB' );
110
111
    # TODO This is not implemented because not used yet
112
    # ->has_child only works with libraries
113
    #is( $groupA->has_child( $groupA1 ), 1, 'groupA1 should be condidered as a child of groupA' );
114
115
    # FIXME At the time of writing this test fails because the ->children methods does not return more than 1 level of depth
116
    # See Bug 15707 comments 166-170+
117
    #is( $groupA->has_child( $groupA1_library2->branchcode ), 1, 'groupA1_library2 should be considered as a child of groupA (it is a grandchild)' );
118
};

Return to bug 18403