Bug 3609 Fix fr-FR user permissions
[koha.git] / xt / syspref.t
blobfb444212d367c04286baae192660dca9930be034
1 #!/usr/bin/perl
3 # Copyright (C) 2009 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 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.
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.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
20 use strict;
21 use warnings;
23 use Test::More qw(no_plan);
25 use C4::Context;
27 my $root_dir = C4::Context->config( 'intranetdir' ) . '/installer/data/mysql';
28 my $base_syspref_file = "en/mandatory/sysprefs.sql";
29 my @trans_syspref_files = qw(
30 fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql
31 uk-UA/mandatory/system_preferences_optimal.sql
32 ru-RU/mandatory/system_preferences_optimal.sql
33 pl-PL/mandatory/sysprefs.sql
36 ok(
37 open( my $ref_fh, "<$root_dir/$base_syspref_file" ),
38 "Open reference syspref file $root_dir/$base_syspref_file" );
39 my $ref_syspref = get_syspref_from_file( $ref_fh );
40 my @ref_sysprefs = sort { lc $a cmp lc $b } keys %$ref_syspref;
41 cmp_ok(
42 $#ref_sysprefs, '>=', 0,
43 "Found " . ($#ref_sysprefs + 1) . " sysprefs" );
45 foreach my $file_name ( @trans_syspref_files ) {
46 compare_syspref( $file_name );
51 # Get sysprefs from SQL file populating sysprefs table with INSERT statement.
53 # Exemple:
54 # INSERT INTO `systempreferences` (variable,value,explanation,options,type)
55 # VALUES('AmazonLocale','US','Use to set the Locale of your Amazon.com Web Services',
56 # 'US|CA|DE|FR|JP|UK','Choice')
58 sub get_syspref_from_file {
59 my $fh = shift;
60 my %syspref;
61 while ( <$fh> ) {
62 next if /^--/; # Comment line
63 #/VALUES.*\(\'([\w\-:]+)\'/;
64 /\(\'([\w\-:]+)\'/;
65 my $variable = $1;
66 next unless $variable;
67 $syspref{$variable} = 1;
69 return \%syspref;
73 sub compare_syspref {
74 my $trans_file = shift;
75 ok(
76 open( my $trans_fh, "<$root_dir/$trans_file" ),
77 "Open translated sysprefs file $root_dir/$trans_file" );
78 my $trans_syspref = get_syspref_from_file( $trans_fh );
79 my @trans_sysprefs = sort { lc $a cmp lc $b } keys %$trans_syspref;
80 cmp_ok(
81 $#trans_sysprefs, '>=', 0,
82 "Found " . ($#trans_sysprefs + 1) . " sysprefs" );
84 my @to_add_sysprefs;
85 foreach ( @ref_sysprefs ) {
86 push @to_add_sysprefs, $_ if ! $trans_syspref->{$_};
88 if ( $#to_add_sysprefs >= 0 ) {
89 fail( 'No syspref to add') or diag( "Sysprefs to add in $trans_file: " . join(', ', @to_add_sysprefs ) );
91 else {
92 pass( 'No syspref to add' );
95 my @to_delete_sysprefs;
96 foreach ( @trans_sysprefs ) {
97 push @to_delete_sysprefs, $_ if ! $ref_syspref->{$_};
99 if ( $#to_delete_sysprefs >= 0 ) {
100 fail( 'No syspref to delete' );
101 diag( "Sysprefs to delete in $trans_file: " . join(', ', @to_delete_sysprefs ) );
102 diag( 'Warning: Some of those sysprefs may rather have to be added to English sysprefs' );
104 else {
105 pass( 'No syspref to delete' );
110 =head1 NAME
112 syspref.t
114 =head1 DESCRIPTION
116 This test identifies incoherences between translated sysprefs files
117 and the reference file.
119 Koha sysprefs are loaded to sypref table from a text SQL file during
120 Koha installation by web installer. The reference file is the one
121 provided for English (en) installation :
123 <koha_root>/installer/data/mysql/en/mandatory/sysprefs.sql
125 Alternatives files are provided for other languages. Those files
126 are difficult to keep syncrhonized with reference file.
128 =head1 USAGE
130 prove -v syspref.t
132 =cut