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

(-)a/Koha/Template/Plugin/Branches.pm (-2 / +2 lines)
Lines 65-72 sub all { Link Here
65
      : Koha::Libraries->search_filtered( {}, { order_by => ['branchname'] } )->unblessed;
65
      : Koha::Libraries->search_filtered( {}, { order_by => ['branchname'] } )->unblessed;
66
66
67
    for my $l ( @$libraries ) {
67
    for my $l ( @$libraries ) {
68
        if (       $selected and $l->{branchcode} eq $selected
68
        if (       defined $selected and $l->{branchcode} eq $selected
69
            or not $selected and C4::Context->userenv and $l->{branchcode} eq C4::Context->userenv->{branch}
69
            or not defined $selected and C4::Context->userenv and $l->{branchcode} eq C4::Context->userenv->{branch}
70
        ) {
70
        ) {
71
            $l->{selected} = 1;
71
            $l->{selected} = 1;
72
        }
72
        }
(-)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