View | Details | Raw Unified | Return to bug 13199
Collapse All | Expand All

(-)a/xt/sample_notices.t (-1 / +129 lines)
Line 0 Link Here
0
- 
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 under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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.sql";
26
my @trans_notices_files = qw(
27
    fr-FR/1-Obligatoire/sample_notices.sql
28
    de-DE/mandatory/sample_notices.sql
29
    es-ES/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_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_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
65
66
sub compare_notices {
67
    my $trans_file = shift;
68
    ok(
69
       open( my $trans_fh, "<$root_dir/$trans_file" ),
70
       "Open translated sample notices file $root_dir/$trans_file" );
71
    my $trans_notice = get_notices_from_file( $trans_fh );
72
    use YAML;
73
    my @trans_notices = sort { lc $a cmp lc $b } keys %$trans_notice;
74
    cmp_ok(
75
        $#trans_notices, '>=', 0,
76
        "Found " . ($#trans_notices + 1) . " notices" );
77
    my @to_add_notices;
78
    foreach ( @ref_notices ) {
79
       push @to_add_notices, $_ if ! $trans_notice->{$_};
80
    }
81
    if ( $#to_add_notices >= 0 ) {
82
        fail( 'No sample notice to add') or diag( "Sample notices to add in $trans_file: " . join(', ', @to_add_notices ) );
83
    }
84
    else {
85
        pass( 'No sample notice to add' );
86
    }
87
88
    my @to_delete_notices;
89
    foreach ( @trans_notices ) {
90
       push @to_delete_notices, $_ if ! $ref_notice->{$_};
91
    }
92
    if ( $#to_delete_notices >= 0 ) {
93
        fail( 'No sample notice to delete' );
94
        diag( "Sample notices to delete in $trans_file: " . join(', ', @to_delete_notices ) );
95
        diag( 'Warning: Some of those sample notices may rather have to be added to English notice' );
96
    }
97
    else {
98
        pass( 'No sample notices to delete' );
99
    }
100
}
101
102
103
=head1 NAME
104
105
sample_notices.t
106
107
=head1 DESCRIPTION
108
109
This test identifies incoherences between translated sample notices and the
110
'en' reference file.
111
112
Koha sample notices are loaded to 'letter' table from a text SQL file
113
during Koha installation by web installer. The reference file is the one
114
provided for English (en) installation :
115
116
  <koha_root>/installer/data/mysql/en/mandatory/sample_notices.sql
117
118
Alternatives files are provided for other languages. Those files are difficult
119
to keep synchronized with reference file. This could be an functional issue
120
since some Koha operation depend on notice existence, for example Print Slip in
121
Circulation.
122
123
=head1 USAGE
124
125
 prove -v sample_notices.t
126
 prove sample_notices.t
127
128
=cut
129

Return to bug 13199