Bug 15758: Koha::Libraries - Do not select an option if selected is defined
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 8 Feb 2016 17:17:31 +0000 (17:17 +0000)
committerKyle M Hall <kyle@bywatersolutions.com>
Thu, 8 Sep 2016 14:36:05 +0000 (14:36 +0000)
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>
Koha/Template/Plugin/Branches.pm
t/db_dependent/Template/Plugin/Branches.t

index e7cbd7e..3f62f1e 100644 (file)
@@ -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;
         }
index 8fcc15f..24b6e6c 100644 (file)
@@ -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();