Bug 12803 - Add ability to skip closed libraries when generating the holds queue
[koha.git] / t / db_dependent / Koha_template_plugin_Branches.t
1 #!/usr/bin/perl
2
3 # Copyright 2013-2014 Equinox Software, Inc.
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, see <http://www.gnu.org/licenses>.
18
19 use Modern::Perl;
20
21 use Test::More tests => 7;
22
23 use C4::Context;
24 use Koha::Database;
25
26 use t::lib::TestBuilder;
27
28 BEGIN {
29     use_ok('Koha::Template::Plugin::Branches');
30 }
31
32 my $schema = Koha::Database->schema;
33 $schema->storage->txn_begin;
34 my $builder = t::lib::TestBuilder->new;
35 my $library = $builder->build({
36     source => 'Branch',
37 });
38
39 my $plugin = Koha::Template::Plugin::Branches->new();
40 ok($plugin, "initialized Branches plugin");
41
42 my $name = $plugin->GetName($library->{branchcode});
43 is($name, $library->{branchname}, 'retrieved expected name for library');
44
45 $name = $plugin->GetName('__ANY__');
46 is($name, '', 'received empty string as name of the "__ANY__" placeholder library code');
47
48 $name = $plugin->GetName(undef);
49 is($name, '', 'received empty string as name of NULL/undefined library code');
50
51 $library = $plugin->GetLoggedInBranchcode();
52 is($library, '', 'no active library if there is no active user session');
53
54 C4::Context->_new_userenv('DUMMY_SESSION_ID');
55 C4::Context->set_userenv(123, 'userid', 'usercnum', 'First name', 'Surname', 'MYLIBRARY', 'My Library', 0);
56 $library = $plugin->GetLoggedInBranchcode();
57 is($library, 'MYLIBRARY', 'GetLoggedInBranchcode() returns active library');