|
Lines 19-38
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use File::Slurp qw(read_file); |
|
|
| 23 |
use C4::Context; |
| 24 |
use Array::Utils qw(array_minus); |
22 |
use Array::Utils qw(array_minus); |
| 25 |
|
23 |
|
| 26 |
use Test::NoWarnings; |
24 |
use Test::NoWarnings; |
| 27 |
use Test::More tests => 3; |
25 |
use Test::More tests => 3; |
| 28 |
|
26 |
|
|
|
27 |
use C4::Context; |
| 28 |
|
| 29 |
use Koha::Devel::Sysprefs; |
| 30 |
|
| 29 |
our $dbh = C4::Context->dbh; |
31 |
our $dbh = C4::Context->dbh; |
| 30 |
my $intranetdir = C4::Context->config('intranetdir'); |
32 |
my $intranetdir = C4::Context->config('intranetdir'); |
| 31 |
my $root_dir = $intranetdir . '/installer/data/mysql/mandatory'; |
|
|
| 32 |
my $syspref_filepath = "$root_dir/sysprefs.sql"; |
| 33 |
|
33 |
|
| 34 |
my @lines = read_file($syspref_filepath) or die "Can't open $syspref_filepath: $!"; |
34 |
my @sysprefs_in_file = Koha::Devel::Sysprefs->new->get_sysprefs_from_file(); |
| 35 |
my @sysprefs_in_file = get_sysprefs_from_file(@lines); |
|
|
| 36 |
|
35 |
|
| 37 |
subtest 'Compare database with sysprefs.sql file' => sub { |
36 |
subtest 'Compare database with sysprefs.sql file' => sub { |
| 38 |
ok( scalar(@sysprefs_in_file), "Found sysprefs" ); |
37 |
ok( scalar(@sysprefs_in_file), "Found sysprefs" ); |
|
Lines 70-130
subtest 'Compare sysprefs.sql with YAML files' => sub {
Link Here
|
| 70 |
} |
69 |
} |
| 71 |
}; |
70 |
}; |
| 72 |
|
71 |
|
| 73 |
# Get sysprefs from SQL file populating sysprefs table with INSERT statement. |
|
|
| 74 |
# |
| 75 |
# Example: |
| 76 |
# INSERT INTO `systempreferences` (variable,value,explanation,options,type) |
| 77 |
# VALUES('AmazonLocale','US','Use to set the Locale of your Amazon.com Web Services', |
| 78 |
# 'US|CA|DE|FR|JP|UK','Choice') |
| 79 |
# |
| 80 |
sub get_sysprefs_from_file { |
| 81 |
my @lines = @_; |
| 82 |
my @sysprefs; |
| 83 |
for my $line (@lines) { |
| 84 |
chomp $line; |
| 85 |
next if $line =~ /^INSERT INTO /; # first line |
| 86 |
next if $line =~ /^;$/; # last line |
| 87 |
next if $line =~ /^--/; # Comment line |
| 88 |
if ( |
| 89 |
$line =~ m/ |
| 90 |
'(?<variable>[^'\\]*(?:\\.[^'\\]*)*)',\s* |
| 91 |
'(?<value>[^'\\]*(?:\\.[^'\\]*)*)',\s* |
| 92 |
(?<options>NULL|'(?<options_content>[^'\\]*(?:\\.[^'\\]*)*)'),\s* |
| 93 |
(?<explanation>NULL|'(?<explanation_content>[^'\\]*(?:\\.[^'\\]*)*)'),\s* |
| 94 |
(?<type>NULL|'(?<type_content>[^'\\]*(?:\\.[^'\\]*)*)') |
| 95 |
/xms |
| 96 |
) |
| 97 |
{ |
| 98 |
my $variable = $+{variable}; |
| 99 |
my $value = $+{value}; |
| 100 |
my $options = $+{options_content}; |
| 101 |
my $explanation = $+{explanation_content}; |
| 102 |
my $type = $+{type_content}; |
| 103 |
|
| 104 |
if ($options) { |
| 105 |
$options =~ s/\\'/'/g; |
| 106 |
$options =~ s/\\\\/\\/g; |
| 107 |
} |
| 108 |
if ($explanation) { |
| 109 |
$explanation =~ s/\\'/'/g; |
| 110 |
$explanation =~ s/\\n/\n/g; |
| 111 |
} |
| 112 |
|
| 113 |
# FIXME Explode if already exists? |
| 114 |
push @sysprefs, { |
| 115 |
variable => $variable, |
| 116 |
value => $value, |
| 117 |
options => $options, |
| 118 |
explanation => $explanation, |
| 119 |
type => $type, |
| 120 |
}; |
| 121 |
} else { |
| 122 |
die "$line does not match"; |
| 123 |
} |
| 124 |
} |
| 125 |
return @sysprefs; |
| 126 |
} |
| 127 |
|
| 128 |
# Get system preferences from YAML files |
72 |
# Get system preferences from YAML files |
| 129 |
sub get_syspref_from_yaml { |
73 |
sub get_syspref_from_yaml { |
| 130 |
my @prefs; |
74 |
my @prefs; |
| 131 |
- |
|
|