]> wagnertech.de Git - kivitendo-erp.git/blob - t/Support/TestSetup.pm
TestSetup auf clients angepasst
[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::Layout::None;
13 use SL::LxOfficeConf;
14 use SL::InstanceConfiguration;
15 use SL::Request;
16
17 sub _login {
18   my ($client, $login) = @_;
19
20   die 'need client and login' unless $client && $login;
21
22   package main;
23
24   $::lxdebug       = LXDebug->new(target => LXDebug::STDERR_TARGET);
25   $::lxdebug->disable_sub_tracing;
26   $::locale        = Locale->new($::lx_office_conf{system}->{language});
27   $::form          = Form->new;
28   $::auth          = SL::Auth->new;
29   die "Cannot find client with ID or name '$client'" if !$::auth->set_client($client);
30
31   $::instance_conf = SL::InstanceConfiguration->new;
32   $::request       = SL::Request->new( cgi => CGI->new({}), layout => SL::Layout::None->new );
33
34   die 'cannot reach auth db'               unless $::auth->session_tables_present;
35
36   $::auth->restore_session;
37
38   require "bin/mozilla/common.pl";
39
40   die "cannot find user $login"            unless %::myconfig = $::auth->read_user(login => $login);
41
42   $::form->{login} = $login; # normaly implicit at login
43
44   die "cannot find locale for user $login" unless $::locale   = Locale->new($::myconfig{countrycode});
45
46   $::instance_conf->init;
47
48   return 1;
49 }
50
51 sub login {
52   SL::LxOfficeConf->read;
53
54   my $login        = shift || $::lx_office_conf{testing}{login}        || 'demo';
55   my $client        = shift || $::lx_office_conf{testing}{client}      || '';
56   _login($client, $login);
57 }
58
59 1;