3 # This file is part of Koha.
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.
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.
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>.
22 use Test::More tests => 7;
30 use_ok( 'C4::Templates' );
31 can_ok( 'C4::Templates',
42 my $query = CGI->new();
43 my $columns = C4::Templates::GetColumnDefs( $query );
45 is( ref( $columns ) eq 'HASH', 1, 'GetColumnDefs returns a hashref' );
46 # get the tables names, sorted
47 my @keys = sort keys %{$columns};
48 is( scalar @keys, 6, 'GetColumnDefs correctly returns the 5 tables defined in columns.def' );
49 my @tables = qw( biblio biblioitems borrowers items statistics subscription );
50 cmp_deeply( \@keys, \@tables, 'GetColumnDefs returns the expected tables');
52 subtest 'Testing themelanguage' => sub {
55 my $module_language = Test::MockModule->new('C4::Languages');
57 $module_language->mock(
60 return $testing_language;
65 my $htdocs = C4::Context->config('intrahtdocs');
66 my $section = 'intranet';
67 t::lib::Mocks::mock_preference( 'template', 'prog' );
70 $testing_language = 'en';
71 my ($theme, $lang, $availablethemes) = C4::Templates::themelanguage( $htdocs, 'about.tt', $section, $cgi);
72 is($theme,'prog',"Expected theme: set en - $theme");
73 is($lang,'en','Expected language: set en');
74 cmp_deeply( $availablethemes, [ 'prog' ], 'We only expect one available theme for set en' );
76 # trigger second case.
77 $testing_language = q{};
78 ($theme, $lang, $availablethemes) = C4::Templates::themelanguage($htdocs, 'about.tt', $section, $cgi);
79 is($theme,'prog',"Expected theme: default en - $theme");
80 is($lang,'en','Expected language: default en');
81 cmp_deeply( $availablethemes, [ 'prog' ], 'We only expect one available theme for default en' );
84 my $template = $htdocs . '/prog/en/modules/about.tt';
85 ($theme, $lang, $availablethemes) = C4::Templates::themelanguage($htdocs, $template, $section, $cgi);
86 is($theme,'prog',"Expected defined theme: unset - $theme");
87 is($lang,q{},'Expected language: unset');
88 cmp_deeply( $availablethemes, [ 'prog' ], 'We only expect one available theme for unset' );
91 $template = $htdocs . '/prog/en/kaboom/about.tt';
92 ($theme, $lang, $availablethemes) = C4::Templates::themelanguage($htdocs, $template, $section, $cgi);
93 is($lang,undef,'Expected language: not coded for');
94 is( $availablethemes, undef, 'We do not expect any available themes -- not coded for' );
95 is($theme,undef,"Expected no theme: not coded for");
100 subtest 'Testing gettemplate' => sub {
104 warning_like { eval { $template = C4::Templates::gettemplate( '/etc/passwd', 'opac', CGI->new, 1 ) }; warn $@ if $@; } qr/bad template/, 'Bad template check';
105 is( $template ? $template->output: '', '', 'Check output' );