@@ -, +, @@ Koha::Template::Plugin::Branches->pickup_locations --- Koha/Template/Plugin/Branches.pm | 12 ++++++++++-- t/db_dependent/Template/Plugin/Branches.t | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) --- a/Koha/Template/Plugin/Branches.pm +++ a/Koha/Template/Plugin/Branches.pm @@ -59,10 +59,11 @@ sub all { my ( $self, $params ) = @_; my $selected = $params->{selected}; my $unfiltered = $params->{unfiltered} || 0; + my $search_params = $params->{search_params} || {}; my $libraries = $unfiltered - ? Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed - : Koha::Libraries->search_filtered( {}, { order_by => ['branchname'] } )->unblessed; + ? Koha::Libraries->search( $search_params, { order_by => ['branchname'] } )->unblessed + : Koha::Libraries->search_filtered( $search_params, { order_by => ['branchname'] } )->unblessed; for my $l ( @$libraries ) { if ( defined $selected and $l->{branchcode} eq $selected @@ -75,4 +76,11 @@ sub all { return $libraries; } +sub pickup_locations { + my ($self, $params) = @_; + $params->{search_params} ||= {}; + $params->{search_params}->{pickup_location} = 1; + return $self->all($params); +} + 1; --- a/t/db_dependent/Template/Plugin/Branches.t +++ a/t/db_dependent/Template/Plugin/Branches.t @@ -16,7 +16,7 @@ use Modern::Perl; -use Test::More tests => 15; +use Test::More tests => 17; use C4::Context; use Koha::Database; @@ -75,6 +75,20 @@ is( grep ( { $_->{branchcode} eq 'ANOTHERLIB' and $_->{selected} == 1 } @$librar $libraries = $plugin->all( { selected => '' } ); is( grep ( { exists $_->{selected} } @$libraries ), 0, 'With selected parameter set to an empty string, no library should be preselected' ); +my $total = @{$plugin->all}; +my $pickupable = @{$plugin->pickup_locations}; +my $yet_another_library = $builder->build({ + source => 'Branch', + value => { + branchcode => 'CANTPICKUP', + pickup_location => 0, + } +}); +is(@{$plugin->pickup_locations}, $pickupable, 'Adding a new library with pickups' + .' disabled does not increase the amount returned by ->pickup_locations'); +is(@{$plugin->all}, $total+1, 'However, adding a new library increases' + .' the total amount gotten with ->all'); + t::lib::Mocks::mock_preference( 'IndependentBranches', 1 ); $libraries = $plugin->all(); is( scalar(@$libraries), 1, 'If IndependentBranches is set, only 1 library should be returned' ); --