Lines 1-130
Link Here
|
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 |
); |
29 |
|
30 |
ok( |
31 |
open( my $ref_fh, "<", "$root_dir/$base_notices_file" ), |
32 |
"Open reference sample notices file $root_dir/$base_notices_file" ); |
33 |
my $ref_notice = get_notices_from_yml_file( $ref_fh ); |
34 |
my @ref_notices = sort { lc $a cmp lc $b } keys %$ref_notice; |
35 |
cmp_ok( |
36 |
$#ref_notices, '>=', 0, |
37 |
"Found " . ($#ref_notices + 1) . " sample notices" ); |
38 |
|
39 |
foreach my $file_name ( @trans_notices_files ) { |
40 |
compare_notices( $file_name ); |
41 |
} |
42 |
|
43 |
|
44 |
# |
45 |
# Get sample notices from SQL file populating letters table with INSERT |
46 |
# statement. |
47 |
# |
48 |
sub get_notices_from_sql_file { |
49 |
my $fh = shift; |
50 |
my %notice; |
51 |
while ( <$fh> ) { |
52 |
next unless /, *'([\_A-Z_]*)'/; |
53 |
$notice{$1} = 1; |
54 |
} |
55 |
return \%notice; |
56 |
} |
57 |
sub get_notices_from_yml_file { |
58 |
my $fh = shift; |
59 |
my %notice; |
60 |
while ( <$fh> ) { |
61 |
next unless /^\s+code:\s([\_A-Z_]*)$/; |
62 |
$notice{$1} = 1; |
63 |
} |
64 |
return \%notice; |
65 |
} |
66 |
|
67 |
|
68 |
|
69 |
sub compare_notices { |
70 |
my $trans_file = shift; |
71 |
ok( |
72 |
open( my $trans_fh,"<", "$root_dir/$trans_file" ), |
73 |
"Open translated sample notices file $root_dir/$trans_file" ); |
74 |
my $trans_notice = get_notices_from_sql_file( $trans_fh ); |
75 |
my @trans_notices = sort { lc $a cmp lc $b } keys %$trans_notice; |
76 |
cmp_ok( |
77 |
$#trans_notices, '>=', 0, |
78 |
"Found " . ($#trans_notices + 1) . " notices" ); |
79 |
my @to_add_notices; |
80 |
foreach ( @ref_notices ) { |
81 |
push @to_add_notices, $_ if ! $trans_notice->{$_}; |
82 |
} |
83 |
if ( $#to_add_notices >= 0 ) { |
84 |
fail( 'No sample notice to add') or diag( "Sample notices to add in $trans_file: " . join(', ', @to_add_notices ) ); |
85 |
} |
86 |
else { |
87 |
pass( 'No sample notice to add' ); |
88 |
} |
89 |
|
90 |
my @to_delete_notices; |
91 |
foreach ( @trans_notices ) { |
92 |
push @to_delete_notices, $_ if ! $ref_notice->{$_}; |
93 |
} |
94 |
if ( $#to_delete_notices >= 0 ) { |
95 |
fail( 'No sample notice to delete' ); |
96 |
diag( "Sample notices to delete in $trans_file: " . join(', ', @to_delete_notices ) ); |
97 |
diag( 'Warning: Some of those sample notices may rather have to be added to English notice' ); |
98 |
} |
99 |
else { |
100 |
pass( 'No sample notices to delete' ); |
101 |
} |
102 |
} |
103 |
|
104 |
|
105 |
=head1 NAME |
106 |
|
107 |
sample_notices.t |
108 |
|
109 |
=head1 DESCRIPTION |
110 |
|
111 |
This test identifies incoherences between translated sample notices and the |
112 |
'en' reference file. |
113 |
|
114 |
Koha sample notices are loaded to 'letter' table from a text SQL file |
115 |
during Koha installation by web installer. The reference file is the one |
116 |
provided for English (en) installation : |
117 |
|
118 |
<koha_root>/installer/data/mysql/en/mandatory/sample_notices.sql |
119 |
|
120 |
Alternatives files are provided for other languages. Those files are difficult |
121 |
to keep synchronized with reference file. This could be an functional issue |
122 |
since some Koha operation depend on notice existence, for example Print Slip in |
123 |
Circulation. |
124 |
|
125 |
=head1 USAGE |
126 |
|
127 |
prove -v sample_notices.t |
128 |
prove sample_notices.t |
129 |
|
130 |
=cut |
131 |
- |