Bug 25067: Move PO file manipulation code into gulp tasks
[koha-ffzg.git] / t / misc / translator / xgettext-tt2.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 => 36;
10
11 my $tempdir = tempdir(CLEANUP => 1);
12
13 write_file("$tempdir/files", "$Bin/sample.tt");
14
15 my $xgettext_cmd = "$Bin/../../../misc/translator/xgettext-tt2 --from-code=UTF-8 "
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 => '"hello ツ"',
24     },
25     {
26         msgid => '"hello {name}"',
27     },
28     {
29         msgid => '"item"',
30         msgid_plural => '"items"',
31     },
32     {
33         msgid => '"{count} item"',
34         msgid_plural => '"{count} items"',
35     },
36     {
37         msgid => '"hello"',
38         msgctxt => '"context"',
39     },
40     {
41         msgid => '"hello {name}"',
42         msgctxt => '"context"',
43     },
44     {
45         msgid => '"item"',
46         msgid_plural => '"items"',
47         msgctxt => '"context"',
48     },
49     {
50         msgid => '"{count} item"',
51         msgid_plural => '"{count} items"',
52         msgctxt => '"context"',
53     },
54     {
55         msgid => '"status is {status}"',
56     },
57     {
58         msgid => '"active"',
59     },
60     {
61         msgid => '"inactive"',
62     },
63     {
64         msgid => '"Inside block"',
65     },
66 );
67
68 for (my $i = 0; $i < @expected; $i++) {
69     for my $key (qw(msgid msgid_plural msgctxt)) {
70         my $expected = $expected[$i]->{$key};
71         my $expected_str = defined $expected ? $expected : 'not defined';
72         is($pot->[$i + 1]->$key, $expected, "$i: $key is $expected_str");
73     }
74 }