From f0e770b3fb406b09e7ed1327d7afc664430ed9a1 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 8 Feb 2016 17:17:31 +0000 Subject: [PATCH] Bug 15758: Koha::Libraries - Do not select an option if selected is defined This will certainly need a few more tweaks. --- Koha/Template/Plugin/Branches.pm | 4 ++-- t/db_dependent/Koha_template_plugin_Branches.t | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Koha/Template/Plugin/Branches.pm b/Koha/Template/Plugin/Branches.pm index b41d3e4..3d17edc 100644 --- a/Koha/Template/Plugin/Branches.pm +++ b/Koha/Template/Plugin/Branches.pm @@ -65,8 +65,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; } diff --git a/t/db_dependent/Koha_template_plugin_Branches.t b/t/db_dependent/Koha_template_plugin_Branches.t index 2241c3a..8639614 100644 --- a/t/db_dependent/Koha_template_plugin_Branches.t +++ b/t/db_dependent/Koha_template_plugin_Branches.t @@ -18,7 +18,7 @@ use Modern::Perl; -use Test::More tests => 14; +use Test::More tests => 15; use C4::Context; use Koha::Database; @@ -73,6 +73,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(); -- 2.1.0