Bug 24461: Add to_api_mapping to Koha::Acquisition::BasketGroup
[koha.git] / xt / sample_notices.t
blobde4004a602ba5ef171b3bb8dabd92bb4a7753b49
1 #!/usr/bin/perl
3 # Copyright (C) 2014 Tamil s.a.r.l.
5 # This file is part of Koha.
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.
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.
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>.
20 use Modern::Perl;
21 use Test::More qw(no_plan);
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 es-ES/mandatory/sample_notices.sql
31 it-IT/necessari/notices.sql
32 nb-NO/1-Obligatorisk/sample_notices.sql
33 pl-PL/mandatory/sample_notices.sql
34 ru-RU/mandatory/sample_notices.sql
35 uk-UA/mandatory/sample_notices.sql
38 ok(
39 open( my $ref_fh, "<", "$root_dir/$base_notices_file" ),
40 "Open reference sample notices file $root_dir/$base_notices_file" );
41 my $ref_notice = get_notices_from_yml_file( $ref_fh );
42 my @ref_notices = sort { lc $a cmp lc $b } keys %$ref_notice;
43 cmp_ok(
44 $#ref_notices, '>=', 0,
45 "Found " . ($#ref_notices + 1) . " sample notices" );
47 foreach my $file_name ( @trans_notices_files ) {
48 compare_notices( $file_name );
53 # Get sample notices from SQL file populating letters table with INSERT
54 # statement.
56 sub get_notices_from_sql_file {
57 my $fh = shift;
58 my %notice;
59 while ( <$fh> ) {
60 next unless /, *'([\_A-Z_]*)'/;
61 $notice{$1} = 1;
63 return \%notice;
65 sub get_notices_from_yml_file {
66 my $fh = shift;
67 my %notice;
68 while ( <$fh> ) {
69 next unless /^\s+code:\s([\_A-Z_]*)$/;
70 $notice{$1} = 1;
72 return \%notice;
77 sub compare_notices {
78 my $trans_file = shift;
79 ok(
80 open( my $trans_fh,"<", "$root_dir/$trans_file" ),
81 "Open translated sample notices file $root_dir/$trans_file" );
82 my $trans_notice = get_notices_from_sql_file( $trans_fh );
83 use YAML;
84 my @trans_notices = sort { lc $a cmp lc $b } keys %$trans_notice;
85 cmp_ok(
86 $#trans_notices, '>=', 0,
87 "Found " . ($#trans_notices + 1) . " notices" );
88 my @to_add_notices;
89 foreach ( @ref_notices ) {
90 push @to_add_notices, $_ if ! $trans_notice->{$_};
92 if ( $#to_add_notices >= 0 ) {
93 fail( 'No sample notice to add') or diag( "Sample notices to add in $trans_file: " . join(', ', @to_add_notices ) );
95 else {
96 pass( 'No sample notice to add' );
99 my @to_delete_notices;
100 foreach ( @trans_notices ) {
101 push @to_delete_notices, $_ if ! $ref_notice->{$_};
103 if ( $#to_delete_notices >= 0 ) {
104 fail( 'No sample notice to delete' );
105 diag( "Sample notices to delete in $trans_file: " . join(', ', @to_delete_notices ) );
106 diag( 'Warning: Some of those sample notices may rather have to be added to English notice' );
108 else {
109 pass( 'No sample notices to delete' );
114 =head1 NAME
116 sample_notices.t
118 =head1 DESCRIPTION
120 This test identifies incoherences between translated sample notices and the
121 'en' reference file.
123 Koha sample notices are loaded to 'letter' table from a text SQL file
124 during Koha installation by web installer. The reference file is the one
125 provided for English (en) installation :
127 <koha_root>/installer/data/mysql/en/mandatory/sample_notices.sql
129 Alternatives files are provided for other languages. Those files are difficult
130 to keep synchronized with reference file. This could be an functional issue
131 since some Koha operation depend on notice existence, for example Print Slip in
132 Circulation.
134 =head1 USAGE
136 prove -v sample_notices.t
137 prove sample_notices.t
139 =cut