Bugzilla – Attachment 160978 Details for
Bug 34979
System preferences missing from sysprefs.sql
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34979: Add unit test for comparing YAMl files with sysprefs.sql
Bug-34979-Add-unit-test-for-comparing-YAMl-files-w.patch (text/plain), 5.24 KB, created by
Katrin Fischer
on 2024-01-12 15:09:57 UTC
(
hide
)
Description:
Bug 34979: Add unit test for comparing YAMl files with sysprefs.sql
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2024-01-12 15:09:57 UTC
Size:
5.24 KB
patch
obsolete
>From 2aca4a013dff17934be4e272f846d980dbb89a33 Mon Sep 17 00:00:00 2001 >From: Katrin Fischer <katrin.fischer.83@web.de> >Date: Sun, 7 Jan 2024 21:54:29 +0000 >Subject: [PATCH] Bug 34979: Add unit test for comparing YAMl files with > sysprefs.sql > >The unit tests will help to detect any discrepancies >and missing entries in the YAML and sysprefs.sql files. > >To test: >* Apply only this patch >* prove -v t/db_dependent/check_sysprefs.t >* It will fail. >* Apply other patches >* Run database update >* Re-run test. It should pass now. >* Recreate your database or reset_all with patches applied. >* System preferences should be installed correctly. >* Test should still pass. > >Signed-off-by: David Nind <david@davidnind.com> >--- > t/db_dependent/check_sysprefs.t | 82 ++++++++++++++++++++++++++++----- > 1 file changed, 71 insertions(+), 11 deletions(-) > >diff --git a/t/db_dependent/check_sysprefs.t b/t/db_dependent/check_sysprefs.t >index 1a83baf176..019f6b0b83 100755 >--- a/t/db_dependent/check_sysprefs.t >+++ b/t/db_dependent/check_sysprefs.t >@@ -22,27 +22,64 @@ use Modern::Perl; > use Carp; > use Getopt::Long; > use C4::Context; >+use Array::Utils qw(array_minus); > > # When this option is set, no tests are performed. > # The missing sysprefs are displayed as sql inserts instead. > our $showsql = 0; > GetOptions( 'showsql' => \$showsql ); > >-use Test::More qw(no_plan); >+use Test::More tests => 2; >+ > our $dbh = C4::Context->dbh; >-my $root_dir = C4::Context->config('intranetdir') . '/installer/data/mysql/mandatory'; >+my $intranetdir = C4::Context->config('intranetdir'); >+my $root_dir = $intranetdir . '/installer/data/mysql/mandatory'; > my $base_syspref_file = "sysprefs.sql"; > > open my $ref_fh, '<', "$root_dir/$base_syspref_file" or croak "Can't open '$root_dir/$base_syspref_file': $!"; >-my $ref_syspref = get_syspref_from_file($ref_fh); >+my $ref_syspref = get_syspref_from_file($ref_fh); > my @ref_sysprefs = sort { lc $a cmp lc $b } keys %$ref_syspref; > my $num_sysprefs = scalar @ref_sysprefs; >-if ( !$showsql ) { >- cmp_ok( $num_sysprefs, '>', 0, >- "Found $num_sysprefs sysprefs" ); >-} > >-check_db($ref_syspref); >+subtest 'Compare database with sysprefs.sql file' => sub { >+ if ( !$showsql ) { >+ cmp_ok( >+ $num_sysprefs, '>', 0, >+ "Found $num_sysprefs sysprefs" >+ ); >+ } >+ >+ check_db($ref_syspref); >+}; >+ >+subtest 'Compare sysprefs.sql with YAML files' => sub { >+ plan tests => 2; >+ >+ my $yaml_prefs = get_syspref_from_yaml(); >+ my @yaml_mod = @$yaml_prefs; >+ @yaml_mod = grep !/marcflavour/, @yaml_mod; # Added by web installer >+ >+ my @sysprefs_mod = @ref_sysprefs; >+ @sysprefs_mod = grep !/ElasticsearchIndexStatus_authorities/, @sysprefs_mod; # Not to be changed manually >+ @sysprefs_mod = grep !/ElasticsearchIndexStatus_biblios/, @sysprefs_mod; # Not to be changed manually >+ @sysprefs_mod = grep !/OPACdidyoumean/, @sysprefs_mod; # Separate configuration page >+ @sysprefs_mod = grep !/UsageStatsID/, @sysprefs_mod; # Separate configuration page >+ @sysprefs_mod = grep !/UsageStatsLastUpdateTime/, @sysprefs_mod; # Separate configuration page >+ @sysprefs_mod = grep !/UsageStatsPublicID/, @sysprefs_mod; # Separate configuration page >+ >+ my @missing_yaml = array_minus( @sysprefs_mod, @yaml_mod ); >+ is( scalar @missing_yaml, 0, "No system preference entries missing from sysprefs.sql" ); >+ if ( scalar @missing_yaml > 0 ) { >+ print "System preferences missing from YAML:\n * " . join( "\n * ", @missing_yaml ) . "\n"; >+ } >+ >+ my @missing_sysprefs = array_minus( @yaml_mod, @sysprefs_mod ); >+ is( scalar @missing_sysprefs, 0, "No system preference entries missing from YAML files" ); >+ if ( scalar @missing_sysprefs > 0 ) { >+ print "System preferences missing from sysprefs.sql:\n * " . join( "\n * ", @missing_sysprefs ) . "\n"; >+ } >+}; >+ > > # > # Get sysprefs from SQL file populating sysprefs table with INSERT statement. >@@ -68,6 +105,27 @@ sub get_syspref_from_file { > return \%syspref; > } > >+# Get system preferences from YAML files >+sub get_syspref_from_yaml { >+ my @prefs; >+ foreach my $file ( glob( $intranetdir . "/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/*.pref" ) ) { >+ if ( open( my $fh, '<:encoding(UTF-8)', $file ) ) { >+ while ( my $row = <$fh> ) { >+ chomp $row; >+ my $pref; >+ if ( $row =~ /pref: (.*)/ ) { >+ $pref = $1; >+ $pref =~ s/["']//ig; >+ push @prefs, $pref; >+ } >+ } >+ } else { >+ warn "Could not open file '$file' $!"; >+ } >+ } >+ return \@prefs; >+} >+ > sub check_db { > my $sysprefs = shift; > >@@ -107,10 +165,12 @@ syspref.t > > =head1 DESCRIPTION > >-This test checks for missing sysprefs in the database. >+This test checks for missing system preferences in the database >+and the sysprefs.sql file. > >-Sysprefs are gathered from the installation file. The database is >-then queried to check if all the sysprefs are in it. >+System prefereces are gathered from the installation and YAML files. >+The database is then queried to check if all the system preferneces are >+in it. > > =head1 USAGE > >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 34979
:
160614
|
160615
|
160616
|
160617
|
160618
|
160619
|
160978
|
160979
|
160980
|
160981
|
160997
|
160998
|
160999
|
161000
|
161227
|
161228
|
161229
|
161230
|
161418
|
161419
|
161420
|
161421