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

(-)a/Koha/Template/Plugin/Branches.pm (-3 / +7 lines)
Lines 59-69 sub all { Link Here
59
    my ( $self, $params ) = @_;
59
    my ( $self, $params ) = @_;
60
    my $selected = $params->{selected};
60
    my $selected = $params->{selected};
61
    my $unfiltered = $params->{unfiltered} || 0;
61
    my $unfiltered = $params->{unfiltered} || 0;
62
    my $only_from_group = $params->{only_from_group} || 0;
62
    my $search_params = $params->{search_params} || {};
63
64
    if ( !$unfiltered ) {
65
        $search_params->{only_from_group} = $params->{only_from_group} || 0;
66
    }
63
67
64
    my $libraries = $unfiltered
68
    my $libraries = $unfiltered
65
      ? Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed
69
      ? Koha::Libraries->search( $search_params, { order_by => ['branchname'] } )->unblessed
66
      : Koha::Libraries->search_filtered( { only_from_group => $only_from_group }, { order_by => ['branchname'] } )->unblessed;
70
      : Koha::Libraries->search_filtered( $search_params, { order_by => ['branchname'] } )->unblessed;
67
71
68
    for my $l ( @$libraries ) {
72
    for my $l ( @$libraries ) {
69
        if (       defined $selected and $l->{branchcode} eq $selected
73
        if (       defined $selected and $l->{branchcode} eq $selected
(-)a/t/db_dependent/Template/Plugin/Branches.t (-2 / +16 lines)
Lines 16-22 Link Here
16
16
17
use Modern::Perl;
17
use Modern::Perl;
18
18
19
use Test::More tests => 15;
19
use Test::More tests => 17;
20
20
21
use C4::Context;
21
use C4::Context;
22
use Koha::Database;
22
use Koha::Database;
Lines 75-80 is( grep ( { $_->{branchcode} eq 'ANOTHERLIB' and $_->{selected} == 1 } @$librar Link Here
75
$libraries = $plugin->all( { selected => '' } );
75
$libraries = $plugin->all( { selected => '' } );
76
is( grep ( { exists $_->{selected} } @$libraries ), 0, 'With selected parameter set to an empty string, no library should be preselected' );
76
is( grep ( { exists $_->{selected} } @$libraries ), 0, 'With selected parameter set to an empty string, no library should be preselected' );
77
77
78
my $total = @{$plugin->all};
79
my $pickupable = @{$plugin->all( { search_params => { pickup_location => 1 } }) };
80
my $yet_another_library = $builder->build({
81
    source => 'Branch',
82
    value => {
83
        branchcode => 'CANTPICKUP',
84
        pickup_location => 0,
85
    }
86
});
87
is(@{$plugin->all( { search_params => { pickup_location => 1 } }) }, $pickupable,
88
   'Adding a new library with pickups'
89
   .' disabled does not increase the amount returned by ->pickup_locations');
90
is(@{$plugin->all}, $total+1, 'However, adding a new library increases'
91
   .' the total amount gotten with ->all');
92
78
t::lib::Mocks::mock_preference( 'IndependentBranches', 1 );
93
t::lib::Mocks::mock_preference( 'IndependentBranches', 1 );
79
$libraries = $plugin->all();
94
$libraries = $plugin->all();
80
is( scalar(@$libraries), 1, 'If IndependentBranches is set, only 1 library should be returned' );
95
is( scalar(@$libraries), 1, 'If IndependentBranches is set, only 1 library should be returned' );
81
- 

Return to bug 7534