1 package KohaTest::Installer::SqlScripts;
2 use base qw( KohaTest::Installer );
11 sub startup_50_get_installer : Test( startup => 1 ) {
13 my $installer = C4::Installer->new();
14 is(ref($installer), "C4::Installer", "created installer");
15 $self->{installer} = $installer;
18 sub installer_all_sample_data : Tests {
21 skip "did not create installer" unless ref($self->{installer}) eq 'C4::Installer';
23 my $all_languages = getAllLanguages();
24 # find the available directory names
25 my $dir=C4::Context->config('intranetdir')."/installer/data/" .
26 (C4::Context->config("db_scheme") ? C4::Context->config("db_scheme") : "mysql") . "/";
28 my @languages = grep { !/^\.|CVS/ && -d "$dir/$_"} readdir(MYDIR);
31 cmp_ok(scalar(@languages), '>', 0, "at least one framework language defined");
33 foreach my $lang_code (@languages) {
35 my $marc_flavours = $self->{installer}->marcflavour_list($lang_code);
36 ok(defined($marc_flavours), "at least one MARC flavour for $lang_code");
37 skip "no MARC flavours for $lang_code" unless defined($marc_flavours);
39 foreach my $flavour (@$marc_flavours) {
41 $self->clear_test_database();
42 my $schema_error = $self->{installer}->load_db_schema();
43 is($schema_error, "", "no errors during schema load");
44 skip "error during schema load" if $schema_error ne "";
46 my $list = $self->{installer}->sql_file_list($lang_code, $flavour, { optional => 1, mandatory => 1 });
47 my $sql_count = scalar(@$list);
48 cmp_ok($sql_count, '>', 0, "at least one SQL init file for $lang_code, $flavour");
49 skip "no SQL init files defined for $lang_code, $flavour" unless $sql_count > 0;
51 my ($fwk_language, $installed_list) = $self->{installer}->load_sql_in_order($all_languages, @$list);
53 # extract list of files
54 my @file_list = map { map { $_ } @{ $_->{fwklist} } } @$installed_list;
55 my $num_processed = scalar(@file_list);
56 cmp_ok($num_processed, '==', $sql_count, "processed all sql scripts for $lang_code, $flavour");
58 my %sql_to_load = map { my $file = $_; $file =~ s!^(.*)(/|\\)!!; $file => 1 } @$list;
59 foreach my $sql (@file_list) {
60 ok(exists($sql_to_load{ $sql->{fwkname} }), "SQL script $sql->{fwkname} is on list");
61 delete $sql_to_load{ $sql->{fwkname} };
62 is($sql->{error}, "", "no errors when loading $sql->{fwkname}");
64 ok(not(%sql_to_load), "no SQL scripts for $lang_code, $flavour left unloaded");
71 sub shutdown_50_clear_installer : Tests( shutdown ) {
73 delete $self->{installer};