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

(-)a/Koha/Template/Plugin/Branches.pm (-2 / +10 lines)
Lines 59-68 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 $search_params = $params->{search_params} || {};
62
63
63
    my $libraries = $unfiltered
64
    my $libraries = $unfiltered
64
      ? Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed
65
      ? Koha::Libraries->search( $search_params, { order_by => ['branchname'] } )->unblessed
65
      : Koha::Libraries->search_filtered( {}, { order_by => ['branchname'] } )->unblessed;
66
      : Koha::Libraries->search_filtered( $search_params, { order_by => ['branchname'] } )->unblessed;
66
67
67
    for my $l ( @$libraries ) {
68
    for my $l ( @$libraries ) {
68
        if (       defined $selected and $l->{branchcode} eq $selected
69
        if (       defined $selected and $l->{branchcode} eq $selected
Lines 75-78 sub all { Link Here
75
    return $libraries;
76
    return $libraries;
76
}
77
}
77
78
79
sub pickup_locations {
80
    my ($self, $params) = @_;
81
    $params->{search_params} ||= {};
82
    $params->{search_params}->{pickup_location} = 1;
83
    return $self->all($params);
84
}
85
78
1;
86
1;
(-)a/t/db_dependent/Template/Plugin/Branches.t (-2 / +15 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->pickup_locations};
80
my $yet_another_library = $builder->build({
81
    source => 'Branch',
82
    value => {
83
        branchcode => 'CANTPICKUP',
84
        pickup_location => 0,
85
    }
86
});
87
is(@{$plugin->pickup_locations}, $pickupable, 'Adding a new library with pickups'
88
   .' disabled does not increase the amount returned by ->pickup_locations');
89
is(@{$plugin->all}, $total+1, 'However, adding a new library increases'
90
   .' the total amount gotten with ->all');
91
78
t::lib::Mocks::mock_preference( 'IndependentBranches', 1 );
92
t::lib::Mocks::mock_preference( 'IndependentBranches', 1 );
79
$libraries = $plugin->all();
93
$libraries = $plugin->all();
80
is( scalar(@$libraries), 1, 'If IndependentBranches is set, only 1 library should be returned' );
94
is( scalar(@$libraries), 1, 'If IndependentBranches is set, only 1 library should be returned' );
81
- 

Return to bug 7534