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

(-)a/Koha/Library.pm (+12 lines)
Lines 56-61 sub get_effective_marcorgcode { Link Here
56
    return $self->marcorgcode || C4::Context->preference("MARCOrgCode");
56
    return $self->marcorgcode || C4::Context->preference("MARCOrgCode");
57
}
57
}
58
58
59
=head3 library_groups
60
61
Return the Library groups of this library
62
63
=cut
64
65
sub library_groups {
66
    my ( $self ) = @_;
67
    my $rs = $self->_result->library_groups;
68
    return Koha::Library::Groups->_new_from_dbic( $rs );
69
}
70
59
=head2 Internal methods
71
=head2 Internal methods
60
72
61
=head3 _type
73
=head3 _type
(-)a/t/db_dependent/LibraryGroups.t (-2 / +16 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 => 15;
7
use Test::More tests => 16;
8
8
9
use t::lib::TestBuilder;
9
use t::lib::TestBuilder;
10
10
Lines 42-49 ok( $in_list, 'New root group is in the list returned by the get_root_groups met Link Here
42
my $groupA  = Koha::Library::Group->new({ parent_id => $root_group->id, title => 'Group A' })->store();
42
my $groupA  = Koha::Library::Group->new({ parent_id => $root_group->id, title => 'Group A' })->store();
43
my $groupA1 = Koha::Library::Group->new({ parent_id => $groupA->id,     title => 'Group A1' })->store();
43
my $groupA1 = Koha::Library::Group->new({ parent_id => $groupA->id,     title => 'Group A1' })->store();
44
my $groupA2 = Koha::Library::Group->new({ parent_id => $groupA->id,     title => 'Group A2' })->store();
44
my $groupA2 = Koha::Library::Group->new({ parent_id => $groupA->id,     title => 'Group A2' })->store();
45
my $groupB  = Koha::Library::Group->new({ parent_id => $root_group->id, title => 'Group B' })->store();
45
46
46
my $groupA_library1  = Koha::Library::Group->new({ parent_id => $groupA->id,  branchcode => $library1->{branchcode} })->store();
47
my $groupA_library1  = Koha::Library::Group->new({ parent_id => $groupA->id,  branchcode => $library1->{branchcode} })->store();
48
my $groupB_library1  = Koha::Library::Group->new({ parent_id => $groupB->id,  branchcode => $library1->{branchcode} })->store();
47
my $groupA1_library2 = Koha::Library::Group->new({ parent_id => $groupA1->id, branchcode => $library2->{branchcode} })->store();
49
my $groupA1_library2 = Koha::Library::Group->new({ parent_id => $groupA1->id, branchcode => $library2->{branchcode} })->store();
48
50
49
my @children = $root_group->children()->as_list();
51
my @children = $root_group->children()->as_list();
Lines 69-74 ok( !$in_list, 'Method libraries_not_direct_children returns all libraries not d Link Here
69
$in_list = any { $_->id eq $groupA1_library2->branchcode } @libraries_not_direct_children;
71
$in_list = any { $_->id eq $groupA1_library2->branchcode } @libraries_not_direct_children;
70
ok( $in_list, 'Method libraries_not_direct_children returns all libraries not direct descendants of group, library 2 is in the list');
72
ok( $in_list, 'Method libraries_not_direct_children returns all libraries not direct descendants of group, library 2 is in the list');
71
73
74
subtest 'Koha::Library->library_groups' => sub {
75
    plan tests => 4;
76
    my $library3 = Koha::Libraries->find( $library3->{branchcode} );
77
    my $groups = $library3->library_groups;
78
    is( ref( $groups ), 'Koha::Library::Groups', 'Koha::Library->library_groups should return Koha::Library::Groups' );
79
    is( $groups->count, 0, 'Library 3 should not be part of any groups');
80
81
    my $library1 = Koha::Libraries->find( $library1->{branchcode} );
82
    $groups = $library1->library_groups;
83
    is( ref( $groups ), 'Koha::Library::Groups', 'Koha::Library->library_groups should return Koha::Library::Groups' );
84
    is( $groups->count, 2, 'Library 1 should be part of 2 groups' );
85
};
86
72
my $groupX = Koha::Library::Group->new( { title => "Group X" } )->store();
87
my $groupX = Koha::Library::Group->new( { title => "Group X" } )->store();
73
my $groupX_library1 = Koha::Library::Group->new({ parent_id => $groupX->id,  branchcode => $library1->{branchcode} })->store();
88
my $groupX_library1 = Koha::Library::Group->new({ parent_id => $groupX->id,  branchcode => $library1->{branchcode} })->store();
74
my $groupX_library2 = Koha::Library::Group->new({ parent_id => $groupX->id,  branchcode => $library2->{branchcode} })->store();
89
my $groupX_library2 = Koha::Library::Group->new({ parent_id => $groupX->id,  branchcode => $library2->{branchcode} })->store();
75
- 

Return to bug 18403