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

(-)a/Koha/Template/Plugin/Branches.pm (-8 / +10 lines)
Lines 30-48 use Koha::Libraries; Link Here
30
sub GetName {
30
sub GetName {
31
    my ( $self, $branchcode ) = @_;
31
    my ( $self, $branchcode ) = @_;
32
32
33
    my $query = "SELECT branchname FROM branches WHERE branchcode = ?";
33
    my $l = Koha::Libraries->find($branchcode);
34
    my $sth   = C4::Context->dbh->prepare($query);
34
    return $l ? $l->branchname : q{};
35
    $sth->execute($branchcode);
36
    my $b = $sth->fetchrow_hashref();
37
    return $b ? $b->{'branchname'} : q{};
38
}
35
}
39
36
40
sub GetLoggedInBranchcode {
37
sub GetLoggedInBranchcode {
41
    my ($self) = @_;
38
    my ($self) = @_;
42
39
43
    return C4::Context->userenv ?
40
    return C4::Context::mybranch;
44
        C4::Context->userenv->{'branch'} :
41
}
45
        '';
42
43
sub GetLoggedInBranchname {
44
    my ($self) = @_;
45
46
    my $code = $self->GetLoggedInBranchcode;
47
    return $code ? $self->GetName($code) : q{};
46
}
48
}
47
49
48
sub GetURL {
50
sub GetURL {
(-)a/t/db_dependent/Template/Plugin/Branches.t (-6 / +6 lines)
Lines 38-44 my $builder = t::lib::TestBuilder->new; Link Here
38
38
39
subtest 'all() tests' => sub {
39
subtest 'all() tests' => sub {
40
40
41
    plan tests => 16;
41
    plan tests => 18;
42
42
43
    $schema->storage->txn_begin;
43
    $schema->storage->txn_begin;
44
44
Lines 46-51 subtest 'all() tests' => sub { Link Here
46
        source => 'Branch',
46
        source => 'Branch',
47
        value => {
47
        value => {
48
            branchcode => 'MYLIBRARY',
48
            branchcode => 'MYLIBRARY',
49
            branchname => 'My sweet library'
49
        }
50
        }
50
    });
51
    });
51
    my $another_library = $builder->build({
52
    my $another_library = $builder->build({
Lines 67-78 subtest 'all() tests' => sub { Link Here
67
    $name = $plugin->GetName(undef);
68
    $name = $plugin->GetName(undef);
68
    is($name, '', 'received empty string as name of NULL/undefined library code');
69
    is($name, '', 'received empty string as name of NULL/undefined library code');
69
70
70
    $library = $plugin->GetLoggedInBranchcode();
71
    is($plugin->GetLoggedInBranchcode(), '', 'no active library code if there is no active user session');
71
    is($library, '', 'no active library if there is no active user session');
72
    is($plugin->GetLoggedInBranchname(), '', 'no active library name if there is no active user session');
72
73
73
    t::lib::Mocks::mock_userenv({ branchcode => 'MYLIBRARY' });
74
    t::lib::Mocks::mock_userenv({ branchcode => 'MYLIBRARY' });
74
    $library = $plugin->GetLoggedInBranchcode();
75
    is($plugin->GetLoggedInBranchcode(), 'MYLIBRARY', 'GetLoggedInBranchcode() returns active library code');
75
    is($library, 'MYLIBRARY', 'GetLoggedInBranchcode() returns active library');
76
    is($plugin->GetLoggedInBranchname(), 'My sweet library', 'GetLoggedInBranchname() returns active library name');
76
77
77
    t::lib::Mocks::mock_preference( 'IndependentBranches', 0 );
78
    t::lib::Mocks::mock_preference( 'IndependentBranches', 0 );
78
    my $libraries = $plugin->all();
79
    my $libraries = $plugin->all();
79
- 

Return to bug 25765