From 414f8f3c575ccf8aed1828b8acec3038352cf95f Mon Sep 17 00:00:00 2001 From: Magnus Enger Date: Sat, 6 Aug 2011 01:40:44 +0200 Subject: [PATCH 4/5] Bug 6537 - Remove syspref-related tests in xt/ As far as I can see, the previous patches for this bug makes the syspref tests obsolete, and this patch removes them: xt/syspref.t xt/check_sysprefs.t --- xt/check_sysprefs.t | 131 ------------------------------------------------ xt/syspref.t | 138 --------------------------------------------------- 2 files changed, 0 insertions(+), 269 deletions(-) delete mode 100755 xt/check_sysprefs.t delete mode 100755 xt/syspref.t diff --git a/xt/check_sysprefs.t b/xt/check_sysprefs.t deleted file mode 100755 index f9bbd9d..0000000 --- a/xt/check_sysprefs.t +++ /dev/null @@ -1,131 +0,0 @@ -#!/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 Koha; 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 = "en/mandatory/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 check_sysprefs.t - -If you want to display the missing sysprefs as sql inserts : -perl check_sysprefs.t --showsql - -=cut - diff --git a/xt/syspref.t b/xt/syspref.t deleted file mode 100755 index acadc55..0000000 --- a/xt/syspref.t +++ /dev/null @@ -1,138 +0,0 @@ -#!/usr/bin/perl - -# Copyright (C) 2009 Tamil s.a.r.l. -# -# 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 Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -use strict; -use warnings; - -use Test::More qw(no_plan); - -use C4::Context; - -my $root_dir = 'installer/data/mysql'; -my $base_syspref_file = "en/mandatory/sysprefs.sql"; -my @trans_syspref_files = qw( - de-DE/mandatory/sysprefs.sql - it-IT/necessari/sysprefs.sql - fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql - uk-UA/mandatory/system_preferences_full_optimal_for_install_only.sql - ru-RU/mandatory/system_preferences_full_optimal_for_install_only.sql - pl-PL/mandatory/sysprefs.sql - es-ES/mandatory/sysprefs.sql -); - -ok( - open( my $ref_fh, "<$root_dir/$base_syspref_file" ), - "Open reference syspref file $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; -cmp_ok( - $#ref_sysprefs, '>=', 0, - "Found " . ($#ref_sysprefs + 1) . " sysprefs" ); - -foreach my $file_name ( @trans_syspref_files ) { - compare_syspref( $file_name ); -} - - -# -# 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 - #/VALUES.*\(\'([\w\-:]+)\'/; - /\(\'([\w\-:]+)\'/; - my $variable = $1; - next unless $variable; - # lowercase syspref - at present, systempreference lookup is not case-sensitive - $variable = lc $variable; - $syspref{$variable} = 1; - } - return \%syspref; -} - - -sub compare_syspref { - my $trans_file = shift; - ok( - open( my $trans_fh, "<$root_dir/$trans_file" ), - "Open translated sysprefs file $root_dir/$trans_file" ); - my $trans_syspref = get_syspref_from_file( $trans_fh ); - my @trans_sysprefs = sort { lc $a cmp lc $b } keys %$trans_syspref; - cmp_ok( - $#trans_sysprefs, '>=', 0, - "Found " . ($#trans_sysprefs + 1) . " sysprefs" ); - - my @to_add_sysprefs; - foreach ( @ref_sysprefs ) { - push @to_add_sysprefs, $_ if ! $trans_syspref->{$_}; - } - if ( $#to_add_sysprefs >= 0 ) { - fail("Sysprefs to add in $trans_file: " . join(', ', @to_add_sysprefs ) ); - } - else { - pass( 'No syspref to add' ); - } - - my @to_delete_sysprefs; - foreach ( @trans_sysprefs ) { - push @to_delete_sysprefs, $_ if ! $ref_syspref->{$_}; - } - if ( $#to_delete_sysprefs >= 0 ) { - fail( 'sysprefs to delete' ); - diag( "Sysprefs to delete in $trans_file: " . join(', ', @to_delete_sysprefs ) ); - diag( 'Warning: Some of those sysprefs may rather have to be added to English sysprefs' ); - } - else { - pass( 'No syspref to delete' ); - } -} - - -=head1 NAME - -syspref.t - -=head1 DESCRIPTION - -This test identifies incoherences between translated sysprefs files -and the reference file. - -Koha sysprefs are loaded to sypref table from a text SQL file during -Koha installation by web installer. The reference file is the one -provided for English (en) installation : - - /installer/data/mysql/en/mandatory/sysprefs.sql - -Alternatives files are provided for other languages. Those files -are difficult to keep syncrhonized with reference file. - -=head1 USAGE - -prove -v syspref.t - -=cut - -- 1.7.4.1