Merge branch 'master' of vc.linet-services.de:public/lx-office-erp
[kivitendo-erp.git] / t / Support / TestSetup.pm
1 package Support::TestSetup;
2
3 use strict;
4
5 use Data::Dumper;
6 use CGI qw( -no_xhtml);
7 use SL::Auth;
8 use SL::Form;
9 use SL::Locale;
10 use SL::LXDebug;
11 use Data::Dumper;
12 use SL::LxOfficeConf;
13 use SL::InstanceConfiguration;
14
15 sub _login {
16   my $login = shift;
17
18   die 'need login' unless $login;
19
20   package main;
21
22   $::lxdebug       = LXDebug->new(file => \*STDERR);
23   $::locale        = Locale->new($::lx_office_conf{system}->{language});
24   $::form          = Form->new;
25   $::auth          = SL::Auth->new;
26   $::instance_conf = SL::InstanceConfiguration->new;
27   $::request       = { cgi => CGI->new({}) };
28
29   die 'cannot reach auth db'               unless $::auth->session_tables_present;
30
31   $::auth->restore_session;
32
33   require "bin/mozilla/common.pl";
34
35   die "cannot find user $login"            unless %::myconfig = $::auth->read_user(login => $login);
36
37   $::form->{login} = $login; # normaly implicit at login
38
39   die "cannot find locale for user $login" unless $::locale   = Locale->new($::myconfig{countrycode});
40
41   $::instance_conf->init;
42
43   return 1;
44 }
45
46 sub login {
47   SL::LxOfficeConf->read;
48
49   my $login        = shift || $::lx_office_conf{testing}{login}        || 'demo';
50   _login($login);
51 }
52
53 1;