Bug 24897: (RM follow-up) Drop tests for es-ES notices
[koha.git] / xt / sample_notices.t
1 #!/usr/bin/perl
2
3 # Copyright (C) 2014 Tamil s.a.r.l.
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21 use Test::More qw(no_plan);
22
23
24 my $root_dir = 'installer/data/mysql';
25 my $base_notices_file = "en/mandatory/sample_notices.yml";
26 my @trans_notices_files = qw(
27     fr-FR/1-Obligatoire/sample_notices.sql
28     fr-CA/obligatoire/sample_notices.sql
29     de-DE/mandatory/sample_notices.sql
30     it-IT/necessari/notices.sql
31     nb-NO/1-Obligatorisk/sample_notices.sql
32     pl-PL/mandatory/sample_notices.sql
33     ru-RU/mandatory/sample_notices.sql
34     uk-UA/mandatory/sample_notices.sql
35 );
36
37 ok(
38     open( my $ref_fh, "<", "$root_dir/$base_notices_file" ),
39     "Open reference sample notices file $root_dir/$base_notices_file" );
40 my $ref_notice = get_notices_from_yml_file( $ref_fh );
41 my @ref_notices = sort { lc $a cmp lc $b } keys %$ref_notice;
42 cmp_ok(
43     $#ref_notices, '>=', 0,
44     "Found " . ($#ref_notices + 1) . " sample notices" );
45
46 foreach my $file_name ( @trans_notices_files ) {
47     compare_notices( $file_name );
48 }
49
50
51 #
52 # Get sample notices from SQL file populating letters table with INSERT
53 # statement.
54 #
55 sub get_notices_from_sql_file {
56     my $fh = shift;
57     my %notice;
58     while ( <$fh> ) {
59         next unless /, *'([\_A-Z_]*)'/;
60         $notice{$1} = 1;
61     }
62     return \%notice;
63 }
64 sub get_notices_from_yml_file {
65     my $fh = shift;
66     my %notice;
67     while ( <$fh> ) {
68         next unless /^\s+code:\s([\_A-Z_]*)$/;
69         $notice{$1} = 1;
70     }
71     return \%notice;
72 }
73
74
75
76 sub compare_notices {
77     my $trans_file = shift;
78     ok(
79        open( my $trans_fh,"<", "$root_dir/$trans_file" ),
80        "Open translated sample notices file $root_dir/$trans_file" );
81     my $trans_notice = get_notices_from_sql_file( $trans_fh );
82     use YAML;
83     my @trans_notices = sort { lc $a cmp lc $b } keys %$trans_notice;
84     cmp_ok(
85         $#trans_notices, '>=', 0,
86         "Found " . ($#trans_notices + 1) . " notices" );
87     my @to_add_notices;
88     foreach ( @ref_notices ) {
89        push @to_add_notices, $_ if ! $trans_notice->{$_};
90     }
91     if ( $#to_add_notices >= 0 ) {
92         fail( 'No sample notice to add') or diag( "Sample notices to add in $trans_file: " . join(', ', @to_add_notices ) );
93     }
94     else {
95         pass( 'No sample notice to add' );
96     }
97
98     my @to_delete_notices;
99     foreach ( @trans_notices ) {
100        push @to_delete_notices, $_ if ! $ref_notice->{$_};
101     }
102     if ( $#to_delete_notices >= 0 ) {
103         fail( 'No sample notice to delete' );
104         diag( "Sample notices to delete in $trans_file: " . join(', ', @to_delete_notices ) );
105         diag( 'Warning: Some of those sample notices may rather have to be added to English notice' );
106     }
107     else {
108         pass( 'No sample notices to delete' );
109     }
110 }
111
112
113 =head1 NAME
114
115 sample_notices.t
116
117 =head1 DESCRIPTION
118
119 This test identifies incoherences between translated sample notices and the
120 'en' reference file.
121
122 Koha sample notices are loaded to 'letter' table from a text SQL file
123 during Koha installation by web installer. The reference file is the one
124 provided for English (en) installation :
125
126   <koha_root>/installer/data/mysql/en/mandatory/sample_notices.sql
127
128 Alternatives files are provided for other languages. Those files are difficult
129 to keep synchronized with reference file. This could be an functional issue
130 since some Koha operation depend on notice existence, for example Print Slip in
131 Circulation.
132
133 =head1 USAGE
134
135  prove -v sample_notices.t
136  prove sample_notices.t
137
138 =cut