3 # Copyright (C) 2010 BibLibre
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
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
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 # When this option is set, no tests are performed.
27 # The missing sysprefs are displayed as sql inserts instead.
29 GetOptions
( 'showsql' => \
$showsql );
31 use Test
::More
qw(no_plan);
32 our $dbh = C4
::Context
->dbh;
33 my $root_dir = C4
::Context
->config('intranetdir') . '/installer/data/mysql';
34 my $base_syspref_file = "sysprefs.sql";
36 open my $ref_fh, '<', "$root_dir/$base_syspref_file" or croak
"Can't open '$root_dir/$base_syspref_file': $!";
37 my $ref_syspref = get_syspref_from_file
($ref_fh);
38 my @ref_sysprefs = sort { lc $a cmp lc $b } keys %$ref_syspref;
39 my $num_sysprefs = scalar @ref_sysprefs;
41 cmp_ok
( $num_sysprefs, '>', 0,
42 "Found $num_sysprefs sysprefs" );
45 check_db
($ref_syspref);
48 # Get sysprefs from SQL file populating sysprefs table with INSERT statement.
51 # INSERT INTO `systempreferences` (variable,value,explanation,options,type)
52 # VALUES('AmazonLocale','US','Use to set the Locale of your Amazon.com Web Services',
53 # 'US|CA|DE|FR|JP|UK','Choice')
55 sub get_syspref_from_file
{
59 next if /^--/; # Comment line
61 if ( $_ =~ /\([\s]*\'([\w\-:]+)\'/ ) {
64 $syspref{$variable} = $query;
74 # Checking the number of sysprefs in the database
75 my $query = "SELECT COUNT(*) FROM systempreferences";
76 my $sth = $dbh->prepare($query);
78 my $res = $sth->fetchrow_arrayref;
79 my $dbcount = $res->[0];
81 cmp_ok
( $dbcount, ">=", scalar( keys %$sysprefs ),
82 "There are at least as many sysprefs in the database as in the sysprefs.sql"
86 # Checking for missing sysprefs in the database
87 $query = "SELECT COUNT(*) FROM systempreferences WHERE variable=?";
88 $sth = $dbh->prepare($query);
89 foreach ( keys %$sysprefs ) {
91 my $res = $sth->fetchrow_arrayref;
92 my $count = $res->[0];
94 is
( $count, 1, "Syspref $_ exists in the database" );
98 print $sysprefs->{$_};
110 This test checks for missing sysprefs in the database.
112 Sysprefs are gathered from the installation file. The database is
113 then queried to check if all the sysprefs are in it.
117 prove -v xt/check_sysprefs.t
119 If you want to display the missing sysprefs as sql inserts :
120 perl check_sysprefs.t --showsql