|
Lines 23-54
use warnings;
Link Here
|
| 23 |
use Getopt::Long; |
23 |
use Getopt::Long; |
| 24 |
use C4::Context; |
24 |
use C4::Context; |
| 25 |
|
25 |
|
| 26 |
|
|
|
| 27 |
# When this option is set, no tests are performed. |
26 |
# When this option is set, no tests are performed. |
| 28 |
# The missing sysprefs are displayed as sql inserts instead. |
27 |
# The missing sysprefs are displayed as sql inserts instead. |
| 29 |
our $showsql = 0; |
28 |
our $showsql = 0; |
| 30 |
GetOptions ('showsql' => \$showsql); |
29 |
GetOptions( 'showsql' => \$showsql ); |
| 31 |
|
|
|
| 32 |
|
30 |
|
| 33 |
use Test::More qw(no_plan); |
31 |
use Test::More qw(no_plan); |
| 34 |
our $dbh = C4::Context->dbh; |
32 |
our $dbh = C4::Context->dbh; |
| 35 |
my $root_dir = C4::Context->config( 'intranetdir' ) . '/installer/data/mysql'; |
33 |
my $root_dir = C4::Context->config('intranetdir') . '/installer/data/mysql'; |
| 36 |
my $base_syspref_file = "sysprefs.sql"; |
34 |
my $base_syspref_file = "sysprefs.sql"; |
| 37 |
|
35 |
|
| 38 |
|
|
|
| 39 |
open( my $ref_fh, "<$root_dir/$base_syspref_file" ); |
36 |
open( my $ref_fh, "<$root_dir/$base_syspref_file" ); |
| 40 |
my $ref_syspref = get_syspref_from_file( $ref_fh ); |
37 |
my $ref_syspref = get_syspref_from_file($ref_fh); |
| 41 |
my @ref_sysprefs = sort { lc $a cmp lc $b } keys %$ref_syspref; |
38 |
my @ref_sysprefs = sort { lc $a cmp lc $b } keys %$ref_syspref; |
| 42 |
if (!$showsql) { |
39 |
if ( !$showsql ) { |
| 43 |
cmp_ok( |
40 |
cmp_ok( $#ref_sysprefs, '>=', 0, |
| 44 |
$#ref_sysprefs, '>=', 0, |
41 |
"Found " . ( $#ref_sysprefs + 1 ) . " sysprefs" ); |
| 45 |
"Found " . ($#ref_sysprefs + 1) . " sysprefs" |
|
|
| 46 |
); |
| 47 |
} |
42 |
} |
| 48 |
|
43 |
|
| 49 |
check_db($ref_syspref); |
44 |
check_db($ref_syspref); |
| 50 |
|
45 |
|
| 51 |
|
|
|
| 52 |
# |
46 |
# |
| 53 |
# Get sysprefs from SQL file populating sysprefs table with INSERT statement. |
47 |
# Get sysprefs from SQL file populating sysprefs table with INSERT statement. |
| 54 |
# |
48 |
# |
|
Lines 60-69
check_db($ref_syspref);
Link Here
|
| 60 |
sub get_syspref_from_file { |
54 |
sub get_syspref_from_file { |
| 61 |
my $fh = shift; |
55 |
my $fh = shift; |
| 62 |
my %syspref; |
56 |
my %syspref; |
| 63 |
while ( <$fh> ) { |
57 |
while (<$fh>) { |
| 64 |
next if /^--/; # Comment line |
58 |
next if /^--/; # Comment line |
| 65 |
my $query = $_; |
59 |
my $query = $_; |
| 66 |
if ($_ =~ /\([\s]*\'([\w\-:]+)\'/) { |
60 |
if ( $_ =~ /\([\s]*\'([\w\-:]+)\'/ ) { |
| 67 |
my $variable = $1; |
61 |
my $variable = $1; |
| 68 |
if ($variable) { |
62 |
if ($variable) { |
| 69 |
$syspref{$variable} = $query; |
63 |
$syspref{$variable} = $query; |
|
Lines 73-114
sub get_syspref_from_file {
Link Here
|
| 73 |
return \%syspref; |
67 |
return \%syspref; |
| 74 |
} |
68 |
} |
| 75 |
|
69 |
|
| 76 |
|
|
|
| 77 |
sub check_db { |
70 |
sub check_db { |
| 78 |
my $sysprefs = shift; |
71 |
my $sysprefs = shift; |
| 79 |
|
72 |
|
| 80 |
# Checking the number of sysprefs in the database |
73 |
# Checking the number of sysprefs in the database |
| 81 |
my $query = "SELECT COUNT(*) FROM systempreferences"; |
74 |
my $query = "SELECT COUNT(*) FROM systempreferences"; |
| 82 |
my $sth = $dbh->prepare($query); |
75 |
my $sth = $dbh->prepare($query); |
| 83 |
$sth->execute; |
76 |
$sth->execute; |
| 84 |
my $res = $sth->fetchrow_arrayref; |
77 |
my $res = $sth->fetchrow_arrayref; |
| 85 |
my $dbcount = $res->[0]; |
78 |
my $dbcount = $res->[0]; |
| 86 |
if (!$showsql) { |
79 |
if ( !$showsql ) { |
| 87 |
cmp_ok ( |
80 |
cmp_ok( $dbcount, ">=", scalar( keys %$sysprefs ), |
| 88 |
$dbcount, ">=", scalar(keys %$sysprefs), "There are at least as many sysprefs in the database as in the sysprefs.sql" |
81 |
"There are at least as many sysprefs in the database as in the sysprefs.sql" |
| 89 |
); |
82 |
); |
| 90 |
} |
83 |
} |
| 91 |
|
84 |
|
| 92 |
# Checking for missing sysprefs in the database |
85 |
# Checking for missing sysprefs in the database |
| 93 |
$query = "SELECT COUNT(*) FROM systempreferences WHERE variable=?"; |
86 |
$query = "SELECT COUNT(*) FROM systempreferences WHERE variable=?"; |
| 94 |
$sth = $dbh->prepare($query); |
87 |
$sth = $dbh->prepare($query); |
| 95 |
foreach (keys %$sysprefs) { |
88 |
foreach ( keys %$sysprefs ) { |
| 96 |
$sth->execute($_); |
89 |
$sth->execute($_); |
| 97 |
my $res = $sth->fetchrow_arrayref; |
90 |
my $res = $sth->fetchrow_arrayref; |
| 98 |
my $count = $res->[0]; |
91 |
my $count = $res->[0]; |
| 99 |
if (!$showsql) { |
92 |
if ( !$showsql ) { |
| 100 |
is( |
93 |
is( $count, 1, "Syspref $_ exists in the database" ); |
| 101 |
$count, 1, "Syspref $_ exists in the database" |
94 |
} |
| 102 |
); |
95 |
else { |
| 103 |
} else { |
96 |
if ( $count != 1 ) { |
| 104 |
if ($count != 1) { |
97 |
print $sysprefs->{$_}; |
| 105 |
print $sysprefs->{$_}; |
98 |
} |
| 106 |
} |
99 |
} |
| 107 |
} |
|
|
| 108 |
} |
100 |
} |
| 109 |
} |
101 |
} |
| 110 |
|
102 |
|
| 111 |
|
|
|
| 112 |
=head1 NAME |
103 |
=head1 NAME |
| 113 |
|
104 |
|
| 114 |
syspref.t |
105 |
syspref.t |
| 115 |
- |
|
|