Bugzilla – Attachment 10814 Details for
Bug 8353
Add test to compare system preferences in db to syspref.sql
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 8353: Adds a test to check for missing sysprefs in the database
Bug-8353-Adds-a-test-to-check-for-missing-sysprefs.patch (text/plain), 4.71 KB, created by
Jared Camins-Esakov
on 2012-07-13 12:12:10 UTC
(
hide
)
Description:
Bug 8353: Adds a test to check for missing sysprefs in the database
Filename:
MIME Type:
Creator:
Jared Camins-Esakov
Created:
2012-07-13 12:12:10 UTC
Size:
4.71 KB
patch
obsolete
>From 20d4ec408c5e624ec8c8b35e966fba8ef6a2290f Mon Sep 17 00:00:00 2001 >From: Henri-Damien LAURENT <henridamien.laurent@biblibre.com> >Date: Tue, 19 Jan 2010 12:26:24 +0100 >Subject: [PATCH] Bug 8353: Adds a test to check for missing sysprefs in the database >Content-Type: text/plain; charset="UTF-8" > >Adds a non-test mode (--showsql option) that displays the missing >sysprefs as sql inserts. Some sysprefs were missed from the syspref >file due to extra spaces in the insert : fixed. The test now checks if >there are at least as many sysprefs in the database as in the syspref >file (instead of checking for the exact number) > >Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com> >Cherrypicked from BibLibre master, rebased onto current master, and >corrected typos, 2012-07-03 > >Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com> >--- > t/db_dependent/check_sysprefs.t | 130 +++++++++++++++++++++++++++++++++++++++ > 1 files changed, 130 insertions(+), 0 deletions(-) > create mode 100755 t/db_dependent/check_sysprefs.t > >diff --git a/t/db_dependent/check_sysprefs.t b/t/db_dependent/check_sysprefs.t >new file mode 100755 >index 0000000..6c8540e >--- /dev/null >+++ b/t/db_dependent/check_sysprefs.t >@@ -0,0 +1,130 @@ >+#!/usr/bin/perl >+ >+# Copyright (C) 2010 BibLibre >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 2 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with this program; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use strict; >+use warnings; >+ >+use Getopt::Long; >+use C4::Context; >+ >+ >+# 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); >+our $dbh = C4::Context->dbh; >+my $root_dir = C4::Context->config( 'intranetdir' ) . '/installer/data/mysql'; >+my $base_syspref_file = "sysprefs.sql"; >+ >+ >+open( my $ref_fh, "<$root_dir/$base_syspref_file" ); >+my $ref_syspref = get_syspref_from_file( $ref_fh ); >+my @ref_sysprefs = sort { lc $a cmp lc $b } keys %$ref_syspref; >+if (!$showsql) { >+ cmp_ok( >+ $#ref_sysprefs, '>=', 0, >+ "Found " . ($#ref_sysprefs + 1) . " sysprefs" >+ ); >+} >+ >+check_db($ref_syspref); >+ >+ >+# >+# Get sysprefs from SQL file populating sysprefs table with INSERT statement. >+# >+# Exemple: >+# INSERT INTO `systempreferences` (variable,value,explanation,options,type) >+# VALUES('AmazonLocale','US','Use to set the Locale of your Amazon.com Web Services', >+# 'US|CA|DE|FR|JP|UK','Choice') >+# >+sub get_syspref_from_file { >+ my $fh = shift; >+ my %syspref; >+ while ( <$fh> ) { >+ next if /^--/; # Comment line >+ my $query = $_; >+ if ($_ =~ /\([\s]*\'([\w\-:]+)\'/) { >+ my $variable = $1; >+ if ($variable) { >+ $syspref{$variable} = $query; >+ } >+ } >+ } >+ return \%syspref; >+} >+ >+ >+sub check_db { >+ my $sysprefs = shift; >+ >+ # Checking the number of sysprefs in the database >+ my $query = "SELECT COUNT(*) FROM systempreferences"; >+ my $sth = $dbh->prepare($query); >+ $sth->execute; >+ my $res = $sth->fetchrow_arrayref; >+ my $dbcount = $res->[0]; >+ if (!$showsql) { >+ cmp_ok ( >+ $dbcount, ">=", scalar(keys %$sysprefs), "There are at least as many sysprefs in the database as in the sysprefs.sql" >+ ); >+ } >+ >+ # Checking for missing sysprefs in the database >+ $query = "SELECT COUNT(*) FROM systempreferences WHERE variable=?"; >+ $sth = $dbh->prepare($query); >+ foreach (keys %$sysprefs) { >+ $sth->execute($_); >+ my $res = $sth->fetchrow_arrayref; >+ my $count = $res->[0]; >+ if (!$showsql) { >+ is( >+ $count, 1, "Syspref $_ exists in the database" >+ ); >+ } else { >+ if ($count != 1) { >+ print $sysprefs->{$_}; >+ } >+ } >+ } >+} >+ >+ >+=head1 NAME >+ >+syspref.t >+ >+=head1 DESCRIPTION >+ >+This test checks for missing sysprefs in the database. >+ >+Sysprefs are gathered from the installation file. The database is >+then queried to check if all the sysprefs are in it. >+ >+=head1 USAGE >+ >+prove -v xt/check_sysprefs.t >+ >+If you want to display the missing sysprefs as sql inserts : >+perl check_sysprefs.t --showsql >+ >+=cut >-- >1.7.2.5
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 8353
:
10628
|
10748
|
10813
| 10814 |
10815
|
10816