From 7a729c2b0a9a1a8329ac02a253a2dc09ab61b431 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Fri, 9 May 2008 18:08:13 -0500 Subject: [PATCH] test suite: new tests for installer Added tests of loading the DB initialization and sampple data SQL scripts for every language and MARC flavour combination defined in installer/data/{dbms}. Errors that the new test class should catch include: * SQL syntax errors in kohastructure.sql * SQL errors in the sample data For each language and MARC flavour combination, all mandatory and optional scripts are loaded. As of this commit, several errors are reported by this test class; these will be fixed separately. Signed-off-by: Joshua Ferraro --- t/lib/KohaTest/Installer.pm | 40 ++++++++++++++ t/lib/KohaTest/Installer/SqlScripts.pm | 76 ++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 t/lib/KohaTest/Installer.pm create mode 100644 t/lib/KohaTest/Installer/SqlScripts.pm diff --git a/t/lib/KohaTest/Installer.pm b/t/lib/KohaTest/Installer.pm new file mode 100644 index 0000000000..97d4ebb2a0 --- /dev/null +++ b/t/lib/KohaTest/Installer.pm @@ -0,0 +1,40 @@ +package KohaTest::Installer; +use base qw( KohaTest ); + +use strict; +use warnings; + +use Test::More; +use C4::Languages; +use C4::Installer; + +sub testing_class { 'C4::Installer' }; + +sub methods : Test( 1 ) { + my $self = shift; + my @methods = qw( + new + marcflavour_list + marc_framework_sql_list + sample_data_sql_list + sql_file_list + load_db_schema + load_sql_in_order + set_marcflavour_syspref + set_indexing_engine + set_version_syspref + load_sql + ); + can_ok( $self->testing_class, @methods ); +} + +# ensure that we have a fresh, empty database +# after running through the installer tests +sub shutdown_50_init_db : Tests( shutdown ) { + my $self = shift; + + KohaTest::clear_test_database(); + KohaTest::create_test_database(); +} + +1; diff --git a/t/lib/KohaTest/Installer/SqlScripts.pm b/t/lib/KohaTest/Installer/SqlScripts.pm new file mode 100644 index 0000000000..592bd3391c --- /dev/null +++ b/t/lib/KohaTest/Installer/SqlScripts.pm @@ -0,0 +1,76 @@ +package KohaTest::Installer::SqlScripts; +use base qw( KohaTest::Installer ); + +use strict; +use warnings; + +use Test::More; +use C4::Languages; +use C4::Installer; + +sub startup_50_get_installer : Test( startup => 1 ) { + my $self = shift; + my $installer = C4::Installer->new(); + is(ref($installer), "C4::Installer", "created installer"); + $self->{installer} = $installer; +} + +sub installer_all_sample_data : Tests { + my $self = shift; + + skip "did not create installer" unless ref($self->{installer}) eq 'C4::Installer'; + + my $all_languages = getAllLanguages(); + # find the available directory names + my $dir=C4::Context->config('intranetdir')."/installer/data/" . + (C4::Context->config("db_scheme") ? C4::Context->config("db_scheme") : "mysql") . "/"; + opendir (MYDIR,$dir); + my @languages = grep { !/^\.|CVS/ && -d "$dir/$_"} readdir(MYDIR); + closedir MYDIR; + + cmp_ok(scalar(@languages), '>', 0, "at least one framework language defined"); + + foreach my $lang_code (@languages) { + SKIP: { + my $marc_flavours = $self->{installer}->marcflavour_list($lang_code); + ok(defined($marc_flavours), "at least one MARC flavour for $lang_code"); + skip "no MARC flavours for $lang_code" unless defined($marc_flavours); + + foreach my $flavour (@$marc_flavours) { + SKIP: { + $self->clear_test_database(); + my $schema_error = $self->{installer}->load_db_schema(); + is($schema_error, "", "no errors during schema load"); + skip "error during schema load" if $schema_error ne ""; + + my $list = $self->{installer}->sql_file_list($lang_code, $flavour, { optional => 1, mandatory => 1 }); + my $sql_count = scalar(@$list); + cmp_ok($sql_count, '>', 0, "at least one SQL init file for $lang_code, $flavour"); + skip "no SQL init files defined for $lang_code, $flavour" unless $sql_count > 0; + + my ($fwk_language, $installed_list) = $self->{installer}->load_sql_in_order($all_languages, @$list); + + # extract list of files + my @file_list = map { map { $_ } @{ $_->{fwklist} } } @$installed_list; + my $num_processed = scalar(@file_list); + cmp_ok($num_processed, '==', $sql_count, "processed all sql scripts for $lang_code, $flavour"); + + my %sql_to_load = map { my $file = $_; $file =~ s!^(.*)(/|\\)!!; $file => 1 } @$list; + foreach my $sql (@file_list) { + ok(exists($sql_to_load{ $sql->{fwkname} }), "SQL script $sql->{fwkname} is on list"); + delete $sql_to_load{ $sql->{fwkname} }; + is($sql->{error}, "", "no errors when loading $sql->{fwkname}"); + } + ok(not(%sql_to_load), "no SQL scripts for $lang_code, $flavour left unloaded"); + } + } + } + } +} + +sub shutdown_50_clear_installer : Tests( shutdown ) { + my $self = shift; + delete $self->{installer}; +} + +1; -- 2.39.5