fixing the translatable-template.t to handle localized setups
[koha.git] / xt / author / translatable-templates.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 =head2 translate-templates.t
7
8 This test verifies that all staff and OPAC template
9 files can be processed by the string extractor
10 without error; such errors usually indicate a 
11 construct that the extractor cannot parse.
12
13 =cut
14
15 use Test::More tests => 2;
16 use File::Temp qw/tempdir/;
17 use IPC::Open3;
18 use File::Spec;
19 use Symbol qw(gensym);
20 use utf8;
21
22 my $po_dir = tempdir(CLEANUP => 1);
23
24 chdir "misc/translator"; # for now, tmpl_process3.pl works only if run from its directory
25 test_string_extraction("opac",     "../../koha-tmpl/opac-tmpl/prog/en",     $po_dir);
26 test_string_extraction("intranet", "../../koha-tmpl/intranet-tmpl/prog/en", $po_dir);
27
28 sub test_string_extraction {
29     my $module       = shift;
30     my $template_dir = shift;
31     my $po_dir       = shift;
32
33     my $command = "./tmpl_process3.pl create -i $template_dir -s $po_dir/$module.po -r --pedantic-warnings";
34    
35     open (NULL, ">", File::Spec->devnull);
36     print NULL "foo"; # avoid warning;
37     my $pid = open3(gensym, ">&NULL", \*PH, $command); 
38     my @warnings;
39     while (<PH>) {
40         # ignore some noise on STDERR
41         # the output of msmerge, that consist in .... followed by a "done" (localized), followed by a .
42         # The "done" localized can include diacritics, so ignoring the whole word
43         # FIXME PP: the flow is not correct UTF8, testing \p{IsLetter} does not work, but I think this regexp will do the job
44         next if (/^\.+ .*\.$/);
45         # other Koha-specific catses that should not worry us
46         next if /^Warning: Can't determine original templates' charset/;
47         next if /^Warning: Charset Out defaulting to/;
48         next if /^Removing empty file /;
49         next if /^I UTF-8 O UTF-8 at /;
50         push @warnings, $_;
51     }
52     waitpid($pid, 0);
53
54     ok($#warnings == -1, "$module templates are translatable") or diag join("\n", @warnings, '');
55 }