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

(-)a/xt/check_sysprefs.t (-131 lines)
Lines 1-131 Link Here
1
#!/usr/bin/perl 
2
3
# Copyright (C) 2010 BibLibre
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 Getopt::Long;
24
use C4::Context;
25
26
27
# When this option is set, no tests are performed.
28
# The missing sysprefs are displayed as sql inserts instead.
29
our $showsql = 0;
30
GetOptions ('showsql' => \$showsql);
31
32
33
use Test::More qw(no_plan); 
34
our $dbh     = C4::Context->dbh;
35
my $root_dir = C4::Context->config( 'intranetdir' ) . '/installer/data/mysql';
36
my $base_syspref_file = "en/mandatory/sysprefs.sql";
37
38
39
open( my $ref_fh, "<$root_dir/$base_syspref_file" );
40
my $ref_syspref = get_syspref_from_file( $ref_fh );
41
my @ref_sysprefs = sort { lc $a cmp lc $b } keys %$ref_syspref;
42
if (!$showsql) {
43
    cmp_ok(
44
	$#ref_sysprefs, '>=', 0,
45
	"Found " . ($#ref_sysprefs + 1) . " sysprefs"
46
    );
47
}
48
49
check_db($ref_syspref);
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
        my $query = $_;
66
        if ($_ =~ /\([\s]*\'([\w\-:]+)\'/) {
67
            my $variable = $1;
68
            if ($variable) {
69
                $syspref{$variable} = $query;
70
            }
71
        }
72
    }
73
    return \%syspref;
74
}
75
76
77
sub check_db {
78
    my $sysprefs = shift;
79
80
    # Checking the number of sysprefs in the database
81
    my $query = "SELECT COUNT(*) FROM systempreferences";
82
    my $sth = $dbh->prepare($query);
83
    $sth->execute;
84
    my $res = $sth->fetchrow_arrayref;
85
    my $dbcount = $res->[0];
86
    if (!$showsql) {
87
	cmp_ok (
88
	    $dbcount, ">=", scalar(keys %$sysprefs), "There are at least as many sysprefs in the database as in the sysprefs.sql"
89
	);
90
    }
91
92
    # Checking for missing sysprefs in the database
93
    $query = "SELECT COUNT(*) FROM systempreferences WHERE variable=?";
94
    $sth = $dbh->prepare($query);
95
    foreach (keys %$sysprefs) {
96
	$sth->execute($_);
97
	my $res = $sth->fetchrow_arrayref;
98
	my $count = $res->[0];
99
	if (!$showsql) {
100
	    is(
101
		$count, 1, "Syspref $_ exists in the database"
102
	    );
103
	} else {
104
	    if ($count != 1) {
105
		print $sysprefs->{$_};
106
	    }
107
	}
108
    }
109
}
110
111
112
=head1 NAME
113
114
syspref.t
115
116
=head1 DESCRIPTION
117
118
This test checks for missing sysprefs in the database.
119
120
Sysprefs are gathered from the installation file. The database is 
121
then queried to check if all the sysprefs are in it.
122
123
=head1 USAGE
124
125
prove -v check_sysprefs.t
126
127
If you want to display the missing sysprefs as sql inserts : 
128
perl check_sysprefs.t --showsql
129
130
=cut
131
(-)a/xt/syspref.t (-139 lines)
Lines 1-138 Link Here
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
    es-ES/mandatory/sysprefs.sql
37
);
38
39
ok(
40
    open( my $ref_fh, "<$root_dir/$base_syspref_file" ),
41
    "Open reference syspref file $root_dir/$base_syspref_file" );
42
my $ref_syspref = get_syspref_from_file( $ref_fh );
43
my @ref_sysprefs = sort { lc $a cmp lc $b } keys %$ref_syspref;
44
cmp_ok(
45
    $#ref_sysprefs, '>=', 0,
46
    "Found " . ($#ref_sysprefs + 1) . " sysprefs" );
47
48
foreach my $file_name ( @trans_syspref_files ) {
49
    compare_syspref( $file_name );
50
}
51
52
53
#
54
# Get sysprefs from SQL file populating sysprefs table with INSERT statement.
55
#
56
# Exemple:
57
# INSERT INTO `systempreferences` (variable,value,explanation,options,type) 
58
# VALUES('AmazonLocale','US','Use to set the Locale of your Amazon.com Web Services',
59
# 'US|CA|DE|FR|JP|UK','Choice')
60
#
61
sub get_syspref_from_file {
62
    my $fh = shift;
63
    my %syspref;
64
    while ( <$fh> ) {
65
        next if /^--/; # Comment line
66
        #/VALUES.*\(\'([\w\-:]+)\'/;
67
        /\(\'([\w\-:]+)\'/;
68
        my $variable = $1;
69
        next unless $variable;
70
        # lowercase syspref - at present, systempreference lookup is not case-sensitive
71
        $variable = lc $variable;
72
        $syspref{$variable} = 1;
73
    }
74
    return \%syspref;
75
}
76
77
78
sub compare_syspref {
79
    my $trans_file = shift;
80
    ok(
81
       open( my $trans_fh, "<$root_dir/$trans_file" ),
82
       "Open translated sysprefs file $root_dir/$trans_file" );
83
    my $trans_syspref = get_syspref_from_file( $trans_fh );
84
    my @trans_sysprefs = sort { lc $a cmp lc $b } keys %$trans_syspref;
85
    cmp_ok(
86
        $#trans_sysprefs, '>=', 0,
87
        "Found " . ($#trans_sysprefs + 1) . " sysprefs" );
88
89
    my @to_add_sysprefs;
90
    foreach ( @ref_sysprefs ) {
91
       push @to_add_sysprefs, $_ if ! $trans_syspref->{$_};
92
    }
93
    if ( $#to_add_sysprefs >= 0 ) {
94
	fail("Sysprefs to add in $trans_file: " . join(', ', @to_add_sysprefs ) );
95
    }
96
    else {
97
        pass( 'No syspref to add' );
98
    }
99
100
    my @to_delete_sysprefs;
101
    foreach ( @trans_sysprefs ) {
102
       push @to_delete_sysprefs, $_ if ! $ref_syspref->{$_};
103
    }
104
    if ( $#to_delete_sysprefs >= 0 ) {
105
        fail( 'sysprefs to delete' );
106
        diag( "Sysprefs to delete in $trans_file: " . join(', ', @to_delete_sysprefs ) );
107
        diag( 'Warning: Some of those sysprefs may rather have to be added to English sysprefs' );
108
    }
109
    else {
110
        pass( 'No syspref to delete' );
111
    }
112
}
113
114
115
=head1 NAME
116
117
syspref.t
118
119
=head1 DESCRIPTION
120
121
This test identifies incoherences between translated sysprefs files
122
and the reference file.
123
124
Koha sysprefs are loaded to sypref table from a text SQL file during
125
Koha installation by web installer. The reference file is the one
126
provided for English (en) installation :
127
128
  <koha_root>/installer/data/mysql/en/mandatory/sysprefs.sql
129
130
Alternatives files are provided for other languages. Those files
131
are difficult to keep syncrhonized with reference file.
132
133
=head1 USAGE
134
135
prove -v syspref.t
136
137
=cut
138
139
- 

Return to bug 6537