View | Details | Raw Unified | Return to bug 15758
Collapse All | Expand All

(-)a/Koha/Template/Plugin/Branches.pm (-2 / +2 lines)
Lines 69-76 sub all { Link Here
69
      : Koha::Libraries->search_filtered( {}, { order_by => ['branchname'] } )->unblessed;
69
      : Koha::Libraries->search_filtered( {}, { order_by => ['branchname'] } )->unblessed;
70
70
71
    for my $l ( @$libraries ) {
71
    for my $l ( @$libraries ) {
72
        if (       $selected and $l->{branchcode} eq $selected
72
        if (       defined $selected and $l->{branchcode} eq $selected
73
            or not $selected and C4::Context->userenv and $l->{branchcode} eq C4::Context->userenv->{branch}
73
            or not defined $selected and C4::Context->userenv and $l->{branchcode} eq C4::Context->userenv->{branch}
74
        ) {
74
        ) {
75
            $l->{selected} = 1;
75
            $l->{selected} = 1;
76
        }
76
        }
(-)a/t/db_dependent/Template/Plugin/Branches.t (-2 / +3 lines)
Lines 16-22 Link Here
16
16
17
use Modern::Perl;
17
use Modern::Perl;
18
18
19
use Test::More tests => 14;
19
use Test::More tests => 15;
20
20
21
use C4::Context;
21
use C4::Context;
22
use Koha::Database;
22
use Koha::Database;
Lines 71-76 is( grep ( { $_->{branchcode} eq 'ANOTHERLIB' and not exists $_->{selected} } @$ Link Here
71
$libraries = $plugin->all( { selected => 'ANOTHERLIB' } );
71
$libraries = $plugin->all( { selected => 'ANOTHERLIB' } );
72
is( grep ( { $_->{branchcode} eq 'MYLIBRARY'  and not exists $_->{selected} } @$libraries ), 1, 'With selected parameter, my library should not be preselected' );
72
is( grep ( { $_->{branchcode} eq 'MYLIBRARY'  and not exists $_->{selected} } @$libraries ), 1, 'With selected parameter, my library should not be preselected' );
73
is( grep ( { $_->{branchcode} eq 'ANOTHERLIB' and $_->{selected} == 1 } @$libraries ),       1, 'With selected parameter, other library should be preselected' );
73
is( grep ( { $_->{branchcode} eq 'ANOTHERLIB' and $_->{selected} == 1 } @$libraries ),       1, 'With selected parameter, other library should be preselected' );
74
$libraries = $plugin->all( { selected => '' } );
75
is( grep ( { exists $_->{selected} } @$libraries ), 0, 'With selected parameter set to an empty string, no library should be preselected' );
74
76
75
C4::Context->set_preference( 'IndependentBranches', 1 );
77
C4::Context->set_preference( 'IndependentBranches', 1 );
76
$libraries = $plugin->all();
78
$libraries = $plugin->all();
77
- 

Return to bug 15758