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

(-)a/t/db_dependent/Koha_template_plugin_Branches.t (-2 / +25 lines)
Lines 18-24 Link Here
18
18
19
use Modern::Perl;
19
use Modern::Perl;
20
20
21
use Test::More tests => 7;
21
use Test::More tests => 14;
22
22
23
use C4::Context;
23
use C4::Context;
24
use Koha::Database;
24
use Koha::Database;
Lines 34-39 $schema->storage->txn_begin; Link Here
34
my $builder = t::lib::TestBuilder->new;
34
my $builder = t::lib::TestBuilder->new;
35
my $library = $builder->build({
35
my $library = $builder->build({
36
    source => 'Branch',
36
    source => 'Branch',
37
    value => {
38
        branchcode => 'MYLIBRARY',
39
    }
40
});
41
my $another_library = $builder->build({
42
    source => 'Branch',
43
    value => {
44
        branchcode => 'ANOTHERLIB',
45
    }
37
});
46
});
38
47
39
my $plugin = Koha::Template::Plugin::Branches->new();
48
my $plugin = Koha::Template::Plugin::Branches->new();
Lines 55-57 C4::Context->_new_userenv('DUMMY_SESSION_ID'); Link Here
55
C4::Context->set_userenv(123, 'userid', 'usercnum', 'First name', 'Surname', 'MYLIBRARY', 'My Library', 0);
64
C4::Context->set_userenv(123, 'userid', 'usercnum', 'First name', 'Surname', 'MYLIBRARY', 'My Library', 0);
56
$library = $plugin->GetLoggedInBranchcode();
65
$library = $plugin->GetLoggedInBranchcode();
57
is($library, 'MYLIBRARY', 'GetLoggedInBranchcode() returns active library');
66
is($library, 'MYLIBRARY', 'GetLoggedInBranchcode() returns active library');
58
- 
67
68
C4::Context->set_preference( 'IndependentBranches', 0 );
69
my $libraries = $plugin->all();
70
ok( scalar(@$libraries) > 1, 'If IndependentBranches is not set, all libraries should be returned' );
71
is( grep ( { $_->{branchcode} eq 'MYLIBRARY'  and $_->{selected} == 1 } @$libraries ),       1, 'Without selected parameter, my library should be preselected' );
72
is( grep ( { $_->{branchcode} eq 'ANOTHERLIB' and not exists $_->{selected} } @$libraries ), 1, 'Without selected parameter, other library should not be preselected' );
73
$libraries = $plugin->all( { selected => 'ANOTHERLIB' } );
74
is( grep ( { $_->{branchcode} eq 'MYLIBRARY'  and not exists $_->{selected} } @$libraries ), 1, 'With selected parameter, my library should not be preselected' );
75
is( grep ( { $_->{branchcode} eq 'ANOTHERLIB' and $_->{selected} == 1 } @$libraries ),       1, 'With selected parameter, other library should be preselected' );
76
77
C4::Context->set_preference( 'IndependentBranches', 1 );
78
$libraries = $plugin->all();
79
is( scalar(@$libraries), 1, 'If IndependentBranches is set, only 1 library should be returned' );
80
$libraries = $plugin->all( { unfiltered => 1 } );
81
ok( scalar(@$libraries) > 1, 'If IndependentBranches is set, all libraries should be returned if the unfiltered flag is set' );

Return to bug 15758