|
Lines 22-48
use Modern::Perl;
Link Here
|
| 22 |
use Carp; |
22 |
use Carp; |
| 23 |
use Getopt::Long; |
23 |
use Getopt::Long; |
| 24 |
use C4::Context; |
24 |
use C4::Context; |
|
|
25 |
use Array::Utils qw(array_minus); |
| 25 |
|
26 |
|
| 26 |
# When this option is set, no tests are performed. |
27 |
# When this option is set, no tests are performed. |
| 27 |
# The missing sysprefs are displayed as sql inserts instead. |
28 |
# The missing sysprefs are displayed as sql inserts instead. |
| 28 |
our $showsql = 0; |
29 |
our $showsql = 0; |
| 29 |
GetOptions( 'showsql' => \$showsql ); |
30 |
GetOptions( 'showsql' => \$showsql ); |
| 30 |
|
31 |
|
| 31 |
use Test::More qw(no_plan); |
32 |
use Test::More tests => 2; |
|
|
33 |
|
| 32 |
our $dbh = C4::Context->dbh; |
34 |
our $dbh = C4::Context->dbh; |
| 33 |
my $root_dir = C4::Context->config('intranetdir') . '/installer/data/mysql/mandatory'; |
35 |
my $intranetdir = C4::Context->config('intranetdir'); |
|
|
36 |
my $root_dir = $intranetdir . '/installer/data/mysql/mandatory'; |
| 34 |
my $base_syspref_file = "sysprefs.sql"; |
37 |
my $base_syspref_file = "sysprefs.sql"; |
| 35 |
|
38 |
|
| 36 |
open my $ref_fh, '<', "$root_dir/$base_syspref_file" or croak "Can't open '$root_dir/$base_syspref_file': $!"; |
39 |
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); |
40 |
my $ref_syspref = get_syspref_from_file($ref_fh); |
| 38 |
my @ref_sysprefs = sort { lc $a cmp lc $b } keys %$ref_syspref; |
41 |
my @ref_sysprefs = sort { lc $a cmp lc $b } keys %$ref_syspref; |
| 39 |
my $num_sysprefs = scalar @ref_sysprefs; |
42 |
my $num_sysprefs = scalar @ref_sysprefs; |
| 40 |
if ( !$showsql ) { |
|
|
| 41 |
cmp_ok( $num_sysprefs, '>', 0, |
| 42 |
"Found $num_sysprefs sysprefs" ); |
| 43 |
} |
| 44 |
|
43 |
|
| 45 |
check_db($ref_syspref); |
44 |
subtest 'Compare database with sysprefs.sql file' => sub { |
|
|
45 |
if ( !$showsql ) { |
| 46 |
cmp_ok( |
| 47 |
$num_sysprefs, '>', 0, |
| 48 |
"Found $num_sysprefs sysprefs" |
| 49 |
); |
| 50 |
} |
| 51 |
|
| 52 |
check_db($ref_syspref); |
| 53 |
}; |
| 54 |
|
| 55 |
subtest 'Compare sysprefs.sql with YAML files' => sub { |
| 56 |
plan tests => 2; |
| 57 |
|
| 58 |
my $yaml_prefs = get_syspref_from_yaml(); |
| 59 |
my @yaml_mod = @$yaml_prefs; |
| 60 |
@yaml_mod = grep !/marcflavour/, @yaml_mod; # Added by web installer |
| 61 |
|
| 62 |
my @sysprefs_mod = @ref_sysprefs; |
| 63 |
@sysprefs_mod = grep !/ElasticsearchIndexStatus_authorities/, @sysprefs_mod; # Not to be changed manually |
| 64 |
@sysprefs_mod = grep !/ElasticsearchIndexStatus_biblios/, @sysprefs_mod; # Not to be changed manually |
| 65 |
@sysprefs_mod = grep !/OPACdidyoumean/, @sysprefs_mod; # Separate configuration page |
| 66 |
@sysprefs_mod = grep !/UsageStatsID/, @sysprefs_mod; # Separate configuration page |
| 67 |
@sysprefs_mod = grep !/UsageStatsLastUpdateTime/, @sysprefs_mod; # Separate configuration page |
| 68 |
@sysprefs_mod = grep !/UsageStatsPublicID/, @sysprefs_mod; # Separate configuration page |
| 69 |
|
| 70 |
my @missing_yaml = array_minus( @sysprefs_mod, @yaml_mod ); |
| 71 |
is( scalar @missing_yaml, 0, "No system preference entries missing from sysprefs.sql" ); |
| 72 |
if ( scalar @missing_yaml > 0 ) { |
| 73 |
print "System preferences missing from YAML:\n * " . join( "\n * ", @missing_yaml ) . "\n"; |
| 74 |
} |
| 75 |
|
| 76 |
my @missing_sysprefs = array_minus( @yaml_mod, @sysprefs_mod ); |
| 77 |
is( scalar @missing_sysprefs, 0, "No system preference entries missing from YAML files" ); |
| 78 |
if ( scalar @missing_sysprefs > 0 ) { |
| 79 |
print "System preferences missing from sysprefs.sql:\n * " . join( "\n * ", @missing_sysprefs ) . "\n"; |
| 80 |
} |
| 81 |
}; |
| 82 |
|
| 46 |
|
83 |
|
| 47 |
# |
84 |
# |
| 48 |
# Get sysprefs from SQL file populating sysprefs table with INSERT statement. |
85 |
# Get sysprefs from SQL file populating sysprefs table with INSERT statement. |
|
Lines 68-73
sub get_syspref_from_file {
Link Here
|
| 68 |
return \%syspref; |
105 |
return \%syspref; |
| 69 |
} |
106 |
} |
| 70 |
|
107 |
|
|
|
108 |
# Get system preferences from YAML files |
| 109 |
sub get_syspref_from_yaml { |
| 110 |
my @prefs; |
| 111 |
foreach my $file ( glob( $intranetdir . "/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/*.pref" ) ) { |
| 112 |
if ( open( my $fh, '<:encoding(UTF-8)', $file ) ) { |
| 113 |
while ( my $row = <$fh> ) { |
| 114 |
chomp $row; |
| 115 |
my $pref; |
| 116 |
if ( $row =~ /pref: (.*)/ ) { |
| 117 |
$pref = $1; |
| 118 |
$pref =~ s/["']//ig; |
| 119 |
push @prefs, $pref; |
| 120 |
} |
| 121 |
} |
| 122 |
} else { |
| 123 |
warn "Could not open file '$file' $!"; |
| 124 |
} |
| 125 |
} |
| 126 |
return \@prefs; |
| 127 |
} |
| 128 |
|
| 71 |
sub check_db { |
129 |
sub check_db { |
| 72 |
my $sysprefs = shift; |
130 |
my $sysprefs = shift; |
| 73 |
|
131 |
|
|
Lines 107-116
syspref.t
Link Here
|
| 107 |
|
165 |
|
| 108 |
=head1 DESCRIPTION |
166 |
=head1 DESCRIPTION |
| 109 |
|
167 |
|
| 110 |
This test checks for missing sysprefs in the database. |
168 |
This test checks for missing system preferences in the database |
|
|
169 |
and the sysprefs.sql file. |
| 111 |
|
170 |
|
| 112 |
Sysprefs are gathered from the installation file. The database is |
171 |
System prefereces are gathered from the installation and YAML files. |
| 113 |
then queried to check if all the sysprefs are in it. |
172 |
The database is then queried to check if all the system preferneces are |
|
|
173 |
in it. |
| 114 |
|
174 |
|
| 115 |
=head1 USAGE |
175 |
=head1 USAGE |
| 116 |
|
176 |
|
| 117 |
- |
|
|