Bug 19185: Fix language selection
[koha.git] / t / lib / Bootstrap.pm
1 package t::lib::Bootstrap;
2
3 use Modern::Perl;
4
5 use DBI;
6 use File::Temp qw( tempfile );
7 use XML::LibXML;
8
9 our ( $database, $database_test );
10 sub import {
11     my ($self, %args) = @_;
12
13     require C4::Context;
14     C4::Context->import;
15
16     my $host = C4::Context->config('hostname');
17     my $port = C4::Context->config('port');
18     $database_test = C4::Context->config("database_test") or die "Config entry 'database_test' does not exist";
19     $database = C4::Context->config('database');
20     die "Entries 'database_test' and 'database' have the same value in your config"
21         if $database_test eq $database;
22     my $user = C4::Context->config('user');
23     my $pass = C4::Context->config('pass');
24
25     my $dbh = DBI->connect("dbi:mysql:;host=$host;port=$port", $user, $pass, {
26         RaiseError => 1,
27         PrintError => 0,
28     });
29
30     $dbh->do("DROP DATABASE IF EXISTS $database_test");
31     $dbh->do("CREATE DATABASE $database_test");
32
33 }
34
35 END {
36     my $dbh = C4::Context->dbh;
37     $dbh->do("DROP DATABASE IF EXISTS $database_test")
38       if $database_test && $database_test ne $database;
39     Koha::Caches->get_instance()->flush_all;
40     Koha::Caches->get_instance('config')->flush_all;
41 };
42
43 1;