Bug 7180: (follow-up) fix getAuthValueDropbox should display the selected value
[koha.git] / t / XSLT.t
blob64cd597ff33245d331b5e8d0aa6fc51e7f4d08d1
1 #!/usr/bin/perl
3 # This Koha test module is a stub!
4 # Add more tests here!!!
6 use strict;
7 use warnings;
9 use Test::More tests => 8;
10 use File::Temp;
11 use File::Path qw/make_path/;
13 BEGIN {
14 use_ok('C4::XSLT');
17 my $dir = File::Temp->newdir();
18 my @themes = ('prog', 'test');
19 my @langs = ('en', 'es-ES');
21 # create temporary files to be tested later
22 foreach my $theme (@themes) {
23 foreach my $lang (@langs) {
24 make_path("$dir/$theme/$lang/xslt");
25 open my $fh, '>', "$dir/$theme/$lang/xslt/my_file.xslt";
26 print $fh "Theme $theme, language $lang";
27 close $fh;
31 sub find_and_slurp {
32 my ($dir, $theme, $lang) = @_;
34 my $filename = C4::XSLT::_get_best_default_xslt_filename($dir, $theme, $lang, 'my_file.xslt');
35 open my $fh, '<', $filename;
36 my $str = <$fh>;
37 close $fh;
38 return $str;
41 # These tests verify that we're finding the right XSLT file when present,
42 # and falling back to the right XSLT file when an exact match is not present.
43 is(find_and_slurp($dir, 'test', 'en' ), 'Theme test, language en', 'Found test/en');
44 is(find_and_slurp($dir, 'test', 'es-ES'), 'Theme test, language es-ES', 'Found test/es-ES');
45 is(find_and_slurp($dir, 'prog', 'en', ), 'Theme prog, language en', 'Found test/en');
46 is(find_and_slurp($dir, 'prog', 'es-ES'), 'Theme prog, language es-ES', 'Found test/es-ES');
47 is(find_and_slurp($dir, 'test', 'fr-FR'), 'Theme test, language en', 'Fell back to test/en for test/fr-FR');
48 is(find_and_slurp($dir, 'nope', 'es-ES'), 'Theme prog, language es-ES', 'Fell back to prog/es-ES for nope/es-ES');
49 is(find_and_slurp($dir, 'nope', 'fr-FR'), 'Theme prog, language en', 'Fell back to prog/en for nope/fr-FR');