Bug 17829: Move GetMember to Koha::Patron
[koha.git] / t / XSLT.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 use Test::More;
20
21 use File::Temp;
22 use File::Path qw/make_path/;
23
24 use t::lib::Mocks;
25
26 use Module::Load::Conditional qw/check_install/;
27
28 BEGIN {
29     if ( check_install( module => 'Test::DBIx::Class' ) ) {
30         plan tests => 9;
31     } else {
32         plan skip_all => "Need Test::DBIx::Class"
33     }
34
35     use_ok('C4::XSLT');
36 };
37
38 use Test::DBIx::Class;
39
40 my $dir = File::Temp->newdir();
41 my @themes = ('prog', 'test');
42 my @langs = ('en', 'es-ES');
43
44 # create temporary files to be tested later
45 foreach my $theme (@themes) {
46     foreach my $lang (@langs) {
47         make_path("$dir/$theme/$lang/xslt");
48         open my $fh, '>', "$dir/$theme/$lang/xslt/my_file.xslt";
49         print $fh "Theme $theme, language $lang";
50         close $fh;
51     }
52 }
53
54 sub find_and_slurp {
55     my ($dir, $theme, $lang) = @_;
56
57     my $filename = C4::XSLT::_get_best_default_xslt_filename($dir, $theme, $lang, 'my_file.xslt');
58     open my $fh, '<', $filename;
59     my $str = <$fh>;
60     close $fh;
61     return $str;
62 }
63
64 # These tests verify that we're finding the right XSLT file when present,
65 # and falling back to the right XSLT file when an exact match is not present.
66 is(find_and_slurp($dir, 'test', 'en'   ), 'Theme test, language en',    'Found test/en');
67 is(find_and_slurp($dir, 'test', 'es-ES'), 'Theme test, language es-ES', 'Found test/es-ES');
68 is(find_and_slurp($dir, 'prog', 'en',  ), 'Theme prog, language en',    'Found test/en');
69 is(find_and_slurp($dir, 'prog', 'es-ES'), 'Theme prog, language es-ES', 'Found test/es-ES');
70 is(find_and_slurp($dir, 'test', 'fr-FR'), 'Theme test, language en',    'Fell back to test/en for test/fr-FR');
71 is(find_and_slurp($dir, 'nope', 'es-ES'), 'Theme prog, language es-ES', 'Fell back to prog/es-ES for nope/es-ES');
72 is(find_and_slurp($dir, 'nope', 'fr-FR'), 'Theme prog, language en',    'Fell back to prog/en for nope/fr-FR');
73
74 my $matching_string = q{<syspref name="singleBranchMode">0</syspref>};
75 my $sysprefs_xml = C4::XSLT::get_xslt_sysprefs();
76 ok( $sysprefs_xml =~ m/$matching_string/, 'singleBranchMode has a value of 0');
77
78 1;