Bug 25067: Move PO file manipulation code into gulp tasks
[koha.git] / t / misc / translator / xgettext-pref.t
1 #!/usr/bin/perl
2
3 use Modern::Perl;
4
5 use File::Slurp;
6 use File::Temp qw(tempdir);
7 use FindBin qw($Bin);
8 use Locale::PO;
9 use Test::More tests => 16;
10
11 my $tempdir = tempdir(CLEANUP => 1);
12
13 write_file("$tempdir/files", "$Bin/sample.pref");
14
15 my $xgettext_cmd = "$Bin/../../../misc/translator/xgettext-pref "
16     . "-o $tempdir/Koha.pot -f $tempdir/files";
17
18 system($xgettext_cmd);
19 my $pot = Locale::PO->load_file_asarray("$tempdir/Koha.pot");
20
21 my @expected = (
22     {
23         msgid => '"sample.pref"',
24     },
25     {
26         msgid => '"sample.pref Subsection"',
27     },
28     {
29         msgid => '"sample.pref#MultiplePref# Bar"',
30     },
31     {
32         msgid => '"sample.pref#MultiplePref# Baz"',
33     },
34     {
35         msgid => '"sample.pref#MultiplePref# Foo ツ"',
36     },
37     {
38         msgid => '"sample.pref#SamplePref# Do"',
39     },
40     {
41         msgid => '"sample.pref#SamplePref# Do not do"',
42     },
43     {
44         msgid => '"sample.pref#SamplePref# that thing"',
45     },
46 );
47
48 for (my $i = 0; $i < @expected; $i++) {
49     for my $key (qw(msgid msgctxt)) {
50         my $expected = $expected[$i]->{$key};
51         my $expected_str = defined $expected ? $expected : 'not defined';
52         is($pot->[$i + 1]->$key, $expected, "$i: $key is $expected_str");
53     }
54 }