Fix for Bug 5679 - funds planning showing strange borders
[koha.git] / xt / syspref.t
1 #!/usr/bin/perl 
2
3 # Copyright (C) 2009 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 strict;
21 use warnings;
22
23 use Test::More qw(no_plan);
24
25 use C4::Context;
26
27 my $root_dir = 'installer/data/mysql';
28 my $base_syspref_file = "en/mandatory/sysprefs.sql";
29 my @trans_syspref_files = qw(
30     de-DE/mandatory/sysprefs.sql
31     it-IT/necessari/sysprefs.sql
32     fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql
33     uk-UA/mandatory/system_preferences_full_optimal_for_install_only.sql
34     ru-RU/mandatory/system_preferences_full_optimal_for_install_only.sql
35     pl-PL/mandatory/sysprefs.sql
36 );
37
38 ok(
39     open( my $ref_fh, "<$root_dir/$base_syspref_file" ),
40     "Open reference syspref file $root_dir/$base_syspref_file" );
41 my $ref_syspref = get_syspref_from_file( $ref_fh );
42 my @ref_sysprefs = sort { lc $a cmp lc $b } keys %$ref_syspref;
43 cmp_ok(
44     $#ref_sysprefs, '>=', 0,
45     "Found " . ($#ref_sysprefs + 1) . " sysprefs" );
46
47 foreach my $file_name ( @trans_syspref_files ) {
48     compare_syspref( $file_name );
49 }
50
51
52 #
53 # Get sysprefs from SQL file populating sysprefs table with INSERT statement.
54 #
55 # Exemple:
56 # INSERT INTO `systempreferences` (variable,value,explanation,options,type) 
57 # VALUES('AmazonLocale','US','Use to set the Locale of your Amazon.com Web Services',
58 # 'US|CA|DE|FR|JP|UK','Choice')
59 #
60 sub get_syspref_from_file {
61     my $fh = shift;
62     my %syspref;
63     while ( <$fh> ) {
64         next if /^--/; # Comment line
65         #/VALUES.*\(\'([\w\-:]+)\'/;
66         /\(\'([\w\-:]+)\'/;
67         my $variable = $1;
68         next unless $variable;
69         # lowercase syspref - at present, systempreference lookup is not case-sensitive
70         $variable = lc $variable;
71         $syspref{$variable} = 1;
72     }
73     return \%syspref;
74 }
75
76
77 sub compare_syspref {
78     my $trans_file = shift;
79     ok(
80        open( my $trans_fh, "<$root_dir/$trans_file" ),
81        "Open translated sysprefs file $root_dir/$trans_file" );
82     my $trans_syspref = get_syspref_from_file( $trans_fh );
83     my @trans_sysprefs = sort { lc $a cmp lc $b } keys %$trans_syspref;
84     cmp_ok(
85         $#trans_sysprefs, '>=', 0,
86         "Found " . ($#trans_sysprefs + 1) . " sysprefs" );
87
88     my @to_add_sysprefs;
89     foreach ( @ref_sysprefs ) {
90        push @to_add_sysprefs, $_ if ! $trans_syspref->{$_};
91     }
92     if ( $#to_add_sysprefs >= 0 ) {
93         fail("Sysprefs to add in $trans_file: " . join(', ', @to_add_sysprefs ) );
94     }
95     else {
96         pass( 'No syspref to add' );
97     }
98
99     my @to_delete_sysprefs;
100     foreach ( @trans_sysprefs ) {
101        push @to_delete_sysprefs, $_ if ! $ref_syspref->{$_};
102     }
103     if ( $#to_delete_sysprefs >= 0 ) {
104         fail( 'sysprefs to delete' );
105         diag( "Sysprefs to delete in $trans_file: " . join(', ', @to_delete_sysprefs ) );
106         diag( 'Warning: Some of those sysprefs may rather have to be added to English sysprefs' );
107     }
108     else {
109         pass( 'No syspref to delete' );
110     }
111 }
112
113
114 =head1 NAME
115
116 syspref.t
117
118 =head1 DESCRIPTION
119
120 This test identifies incoherences between translated sysprefs files
121 and the reference file.
122
123 Koha sysprefs are loaded to sypref table from a text SQL file during
124 Koha installation by web installer. The reference file is the one
125 provided for English (en) installation :
126
127   <koha_root>/installer/data/mysql/en/mandatory/sysprefs.sql
128
129 Alternatives files are provided for other languages. Those files
130 are difficult to keep syncrhonized with reference file.
131
132 =head1 USAGE
133
134 prove -v syspref.t
135
136 =cut
137