Bug 14168 - enhance streaming cataloging to include youtube
[koha.git] / t / XSLT.t
blob21c2e931f5042d6b69f313eeada437747cbf3ca0
1 #!/usr/bin/perl
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>.
18 use Modern::Perl;
20 use Test::More tests => 8;
21 use File::Temp;
22 use File::Path qw/make_path/;
24 use t::lib::Mocks;
26 BEGIN {
27 my $context_module = t::lib::Mocks::mock_dbh;
28 use_ok('C4::XSLT');
31 my $dir = File::Temp->newdir();
32 my @themes = ('prog', 'test');
33 my @langs = ('en', 'es-ES');
35 # create temporary files to be tested later
36 foreach my $theme (@themes) {
37 foreach my $lang (@langs) {
38 make_path("$dir/$theme/$lang/xslt");
39 open my $fh, '>', "$dir/$theme/$lang/xslt/my_file.xslt";
40 print $fh "Theme $theme, language $lang";
41 close $fh;
45 sub find_and_slurp {
46 my ($dir, $theme, $lang) = @_;
48 my $filename = C4::XSLT::_get_best_default_xslt_filename($dir, $theme, $lang, 'my_file.xslt');
49 open my $fh, '<', $filename;
50 my $str = <$fh>;
51 close $fh;
52 return $str;
55 # These tests verify that we're finding the right XSLT file when present,
56 # and falling back to the right XSLT file when an exact match is not present.
57 is(find_and_slurp($dir, 'test', 'en' ), 'Theme test, language en', 'Found test/en');
58 is(find_and_slurp($dir, 'test', 'es-ES'), 'Theme test, language es-ES', 'Found test/es-ES');
59 is(find_and_slurp($dir, 'prog', 'en', ), 'Theme prog, language en', 'Found test/en');
60 is(find_and_slurp($dir, 'prog', 'es-ES'), 'Theme prog, language es-ES', 'Found test/es-ES');
61 is(find_and_slurp($dir, 'test', 'fr-FR'), 'Theme test, language en', 'Fell back to test/en for test/fr-FR');
62 is(find_and_slurp($dir, 'nope', 'es-ES'), 'Theme prog, language es-ES', 'Fell back to prog/es-ES for nope/es-ES');
63 is(find_and_slurp($dir, 'nope', 'fr-FR'), 'Theme prog, language en', 'Fell back to prog/en for nope/fr-FR');