Browse Source

Bug 15758: Koha::Libraries - Do not select an option if selected is defined

This will certainly need a few more tweaks.

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
16.11.x
Jonathan Druart 8 years ago
committed by Kyle M Hall
parent
commit
f1e5d61b46
  1. 4
      Koha/Template/Plugin/Branches.pm
  2. 4
      t/db_dependent/Template/Plugin/Branches.t

4
Koha/Template/Plugin/Branches.pm

@ -69,8 +69,8 @@ sub all {
: Koha::Libraries->search_filtered( {}, { order_by => ['branchname'] } )->unblessed;
for my $l ( @$libraries ) {
if ( $selected and $l->{branchcode} eq $selected
or not $selected and C4::Context->userenv and $l->{branchcode} eq C4::Context->userenv->{branch}
if ( defined $selected and $l->{branchcode} eq $selected
or not defined $selected and C4::Context->userenv and $l->{branchcode} eq C4::Context->userenv->{branch}
) {
$l->{selected} = 1;
}

4
t/db_dependent/Template/Plugin/Branches.t

@ -16,7 +16,7 @@
use Modern::Perl;
use Test::More tests => 14;
use Test::More tests => 15;
use C4::Context;
use Koha::Database;
@ -71,6 +71,8 @@ is( grep ( { $_->{branchcode} eq 'ANOTHERLIB' and not exists $_->{selected} } @$
$libraries = $plugin->all( { selected => 'ANOTHERLIB' } );
is( grep ( { $_->{branchcode} eq 'MYLIBRARY' and not exists $_->{selected} } @$libraries ), 1, 'With selected parameter, my library should not be preselected' );
is( grep ( { $_->{branchcode} eq 'ANOTHERLIB' and $_->{selected} == 1 } @$libraries ), 1, 'With selected parameter, other library should be preselected' );
$libraries = $plugin->all( { selected => '' } );
is( grep ( { exists $_->{selected} } @$libraries ), 0, 'With selected parameter set to an empty string, no library should be preselected' );
C4::Context->set_preference( 'IndependentBranches', 1 );
$libraries = $plugin->all();

Loading…
Cancel
Save