Bug 18036: Perlcritic improve t/db_dependent/Templates.t
[koha.git] / t / db_dependent / Templates.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use CGI;
21
22 use Test::More tests => 6;
23 use Test::Deep;
24 use Test::MockModule;
25
26 use t::lib::Mocks;
27
28 BEGIN {
29     use_ok( 'C4::Templates' );
30     can_ok( 'C4::Templates',
31          qw/ GetColumnDefs
32              getlanguagecookie
33              setlanguagecookie
34              themelanguage
35              gettemplate
36              _get_template_file
37              param
38              output /);
39 }
40
41 my $query   = CGI->new();
42 my $columns = C4::Templates::GetColumnDefs( $query );
43
44 is( ref( $columns ) eq 'HASH', 1, 'GetColumnDefs returns a hashref' );
45 # get the tables names, sorted
46 my @keys = sort keys %{$columns};
47 is( scalar @keys, 6, 'GetColumnDefs correctly returns the 5 tables defined in columns.def' );
48 my @tables = qw( biblio biblioitems borrowers items statistics subscription );
49 cmp_deeply( \@keys, \@tables, 'GetColumnDefs returns the expected tables');
50
51 subtest 'Testing themelanguage for unique themes (BZ 17982)' => sub {
52     plan tests => 1;
53
54     t::lib::Mocks::mock_preference('template', 'prog');
55     my $module_language = Test::MockModule->new('C4::Languages');
56     $module_language->mock( 'getlanguage', sub { return 'en'; } );
57
58     # This only triggers the first uniq but that is sufficient for now
59     cmp_deeply( ( C4::Templates::themelanguage( C4::Context->config('intrahtdocs'), 'about.tt' , 'intranet', 'fake_cgi' ) )[2], [ 'prog' ], 'We only expect one prog here' );
60 };
61
62 1;