Lines 6-14
Link Here
|
6 |
use strict; |
6 |
use strict; |
7 |
use warnings; |
7 |
use warnings; |
8 |
|
8 |
|
9 |
use Test::More tests => 1; |
9 |
use Test::More tests => 8; |
|
|
10 |
use File::Temp; |
11 |
use File::Path qw/make_path/; |
10 |
|
12 |
|
11 |
BEGIN { |
13 |
BEGIN { |
12 |
use_ok('C4::XSLT'); |
14 |
use_ok('C4::XSLT'); |
13 |
} |
15 |
} |
14 |
|
16 |
|
15 |
- |
17 |
my $dir = File::Temp->newdir(); |
|
|
18 |
my @themes = ('prog', 'test'); |
19 |
my @langs = ('en', 'es-ES'); |
20 |
|
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; |
28 |
} |
29 |
} |
30 |
|
31 |
sub find_and_slurp { |
32 |
my ($dir, $theme, $lang) = @_; |
33 |
|
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; |
39 |
} |
40 |
|
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'); |