From feb01aacc37568e3591a41d17dea1316099eab8c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 26 May 2016 15:17:36 +0100 Subject: [PATCH] Bug 16554: DO NOT PUSH - test for all sample files You will need to create a koha_test_installer DB before --- t/db_dependent/Test_installer.t | 60 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 t/db_dependent/Test_installer.t diff --git a/t/db_dependent/Test_installer.t b/t/db_dependent/Test_installer.t new file mode 100644 index 0000000..00f3a44 --- /dev/null +++ b/t/db_dependent/Test_installer.t @@ -0,0 +1,60 @@ +#!/usr/bin/perl + +use Modern::Perl; + +use Test::More; #tests => XXX; +use File::Find; +use File::Slurp; +use List::MoreUtils qw( uniq ); +use t::lib::Mocks; +use C4::Installer; + +my $db_name = 'koha_test_installer'; +t::lib::Mocks::mock_config('database', $db_name); +my $user = C4::Context->config('user'); +my $pass = C4::Context->config('pass'); +my $schema = Koha::Database->new->schema; + +my $sample_dir = C4::Context->config('intranetdir') . '/installer/data/mysql/'; +my @global_files = ( + $sample_dir . 'audio_alerts.sql', + $sample_dir . 'sysprefs.sql', + $sample_dir . 'userflags.sql', + $sample_dir . 'userpermissions.sql', + $sample_dir . 'mandatory/subtag_registry.sql', +); +my $kohastructure = $sample_dir . '/kohastructure.sql'; + +for my $lang ( qw ( de-DE en es-ES fr-CA fr-FR it-IT nb-NO pl-PL ru-RU uk-UA ) ) { + for my $marcflavour ( qw( marc21 unimarc ) ) { + say "loading kohastructure for $lang | not $marcflavour"; + recreate_db( $db_name ); + my $error = C4::Installer->new->load_sql( $kohastructure ); + my @sample_files = @global_files; + + find( sub { + push @sample_files, $File::Find::name if $_ =~ m|\.sql$|; + }, $sample_dir . '/' . $lang . '/' + ); + my $i = 1; + for my $sql_file ( @sample_files ) { + print $i++ . "/" . scalar @sample_files . "\r"; flush STDOUT; + next if $sql_file =~ $marcflavour; + #my $content = read_file( $sql_file ); + #my @tables = uniq map { $_ =~ s/insert\s*(ignore)?\s*into\s*`?(\w+)`?.*/$2/xmsi; $_ } grep {/insert\s*(ignore)?\s*into/xmsi} split '\n', $content; + my $error = C4::Installer->new->load_sql( $sql_file ); + warn $error if $error; + } + } +} + +sub recreate_db { + my $dbname = shift; + my $dbh = C4::Context->dbh; + eval { $dbh->do(qq|DROP DATABASE $dbname|) }; + + $dbh->do(qq|CREATE DATABASE $dbname CHARACTER SET utf8 COLLATE utf8_bin|); + + # Force C4::Context to recreate a new db handler + $dbh->disconnect; +} -- 2.8.1