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 => 6;
29 use_ok( 'C4::Templates' );
30 can_ok( 'C4::Templates',
41 my $query = CGI->new();
42 my $columns = C4::Templates::GetColumnDefs( $query );
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');
51 subtest 'Testing themelanguage' => sub {
54 my $module_language = Test::MockModule->new('C4::Languages');
56 $module_language->mock(
59 return $testing_language;
64 my $htdocs = C4::Context->config('intrahtdocs');
65 my $section = 'intranet';
66 t::lib::Mocks::mock_preference( 'template', 'prog' );
69 $testing_language = 'en';
70 my ($theme, $lang, $availablethemes) = C4::Templates::themelanguage( $htdocs, 'about.tt', $section, $cgi);
71 is($theme,'prog',"Expected theme: set en - $theme");
72 is($lang,'en','Expected language: set en');
73 cmp_deeply( $availablethemes, [ 'prog' ], 'We only expect one available theme for set en' );
75 # trigger second case.
76 $testing_language = q{};
77 ($theme, $lang, $availablethemes) = C4::Templates::themelanguage($htdocs, 'about.tt', $section, $cgi);
78 is($theme,'prog',"Expected theme: default en - $theme");
79 is($lang,'en','Expected language: default en');
80 cmp_deeply( $availablethemes, [ 'prog' ], 'We only expect one available theme for default en' );
83 my $template = $htdocs . '/prog/en/modules/about.tt';
84 ($theme, $lang, $availablethemes) = C4::Templates::themelanguage($htdocs, $template, $section, $cgi);
85 is($theme,'prog',"Expected defined theme: unset - $theme");
86 is($lang,q{},'Expected language: unset');
87 cmp_deeply( $availablethemes, [ 'prog' ], 'We only expect one available theme for unset' );
90 $template = $htdocs . '/prog/en/kaboom/about.tt';
91 ($theme, $lang, $availablethemes) = C4::Templates::themelanguage($htdocs, $template, $section, $cgi);
92 is($lang,undef,'Expected language: not coded for');
93 is( $availablethemes, undef, 'We do not expect any available themes -- not coded for' );
94 is($theme,undef,"Expected no theme: not coded for");