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" );
37 my $ref_syspref = get_syspref_from_file
($ref_fh);
38 my @ref_sysprefs = sort { lc $a cmp lc $b } keys %$ref_syspref;
40 cmp_ok
( $#ref_sysprefs, '>=', 0,
41 "Found " . ( $#ref_sysprefs + 1 ) . " sysprefs" );
44 check_db
($ref_syspref);
47 # Get sysprefs from SQL file populating sysprefs table with INSERT statement.
50 # INSERT INTO `systempreferences` (variable,value,explanation,options,type)
51 # VALUES('AmazonLocale','US','Use to set the Locale of your Amazon.com Web Services',
52 # 'US|CA|DE|FR|JP|UK','Choice')
54 sub get_syspref_from_file
{
58 next if /^--/; # Comment line
60 if ( $_ =~ /\([\s]*\'([\w\-:]+)\'/ ) {
63 $syspref{$variable} = $query;
73 # Checking the number of sysprefs in the database
74 my $query = "SELECT COUNT(*) FROM systempreferences";
75 my $sth = $dbh->prepare($query);
77 my $res = $sth->fetchrow_arrayref;
78 my $dbcount = $res->[0];
80 cmp_ok
( $dbcount, ">=", scalar( keys %$sysprefs ),
81 "There are at least as many sysprefs in the database as in the sysprefs.sql"
85 # Checking for missing sysprefs in the database
86 $query = "SELECT COUNT(*) FROM systempreferences WHERE variable=?";
87 $sth = $dbh->prepare($query);
88 foreach ( keys %$sysprefs ) {
90 my $res = $sth->fetchrow_arrayref;
91 my $count = $res->[0];
93 is
( $count, 1, "Syspref $_ exists in the database" );
97 print $sysprefs->{$_};
109 This test checks for missing sysprefs in the database.
111 Sysprefs are gathered from the installation file. The database is
112 then queried to check if all the sysprefs are in it.
116 prove -v xt/check_sysprefs.t
118 If you want to display the missing sysprefs as sql inserts :
119 perl check_sysprefs.t --showsql