: 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;
}
use Modern::Perl;
-use Test::More tests => 14;
+use Test::More tests => 15;
use C4::Context;
use Koha::Database;
$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();