From 8dae35dc69631f91f8c891ad9b793476e7f3c18a Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Tue, 18 Apr 2017 14:35:22 +0000 Subject: [PATCH] Bug 18446: Compare preferences in .pref files to sysprefs.sql This patch adds a test that reads system preferences from .pref files and checks that they are also defined in sysprefs.sql. To test: 1. prove t/db_dependent/check_sysprefs.t --- t/db_dependent/check_sysprefs.t | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/t/db_dependent/check_sysprefs.t b/t/db_dependent/check_sysprefs.t index b179c4a..880967e 100755 --- a/t/db_dependent/check_sysprefs.t +++ b/t/db_dependent/check_sysprefs.t @@ -44,6 +44,20 @@ if ( !$showsql ) { check_db($ref_syspref); +subtest 'Ensure a preference in .pref file exists in sysprefs.sql' => sub { + my @file_preferences = get_prefs_from_pref_files(); + my $sysprefs = $ref_syspref; + plan tests => 1; + + my @missing_prefs; + foreach my $pref (@file_preferences) { + push @missing_prefs, $pref unless $sysprefs->{$pref}; + } + + is(join(', ',@missing_prefs), '', + 'No preferences are missing from database'); +}; + # # Get sysprefs from SQL file populating sysprefs table with INSERT statement. # @@ -101,6 +115,25 @@ sub check_db { } } +sub get_prefs_from_pref_files { + my $intratmpl = C4::Context->config('intrahtdocs'); + my $dir = "$intratmpl/prog/en/modules/admin/preferences"; + my @file_preferences; + foreach my $fp (glob("$dir/*.pref")) { + open my $fh, "<", $fp or die "can't read open '$fp'"; + while (<$fh>) { + if ($_ =~ /^(?!#).*pref: .*\n/) { + my $pref = $_; + $pref =~ s/"|'//g; # remove " and ' + $pref =~ s/^\s*- pref:\s//; # remove "- pref:" + $pref =~ s/^\s+|\s+$//g; # trim + push @file_preferences, $pref; + } + } + close $fh or die "can't read close '$fp'"; + } + return sort @file_preferences; +} =head1 NAME syspref.t -- 2.7.4