epic-s6ts
[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 IO::File;
8 use SL::Auth;
9 use SL::Form;
10 use SL::Locale;
11 use SL::LXDebug;
12 use Data::Dumper;
13 use SL::Layout::None;
14 use SL::LxOfficeConf;
15 use SL::InstanceConfiguration;
16 use SL::Request;
17
18 sub login {
19   $Data::Dumper::Sortkeys = 1;
20   $Data::Dumper::Indent   = 2;
21
22   SL::LxOfficeConf->read;
23
24   my $client = 'Unit-Tests';
25   my $login  = 'unittests';
26
27   package main;
28
29   $::lxdebug       = LXDebug->new(target => LXDebug::STDERR_TARGET);
30   $::lxdebug->disable_sub_tracing;
31   $::locale        = Locale->new($::lx_office_conf{system}->{language});
32   $::form          = Support::TestSetup->create_new_form;
33   $::auth          = SL::Auth->new(unit_tests_database => 1);
34   die "Cannot find client with ID or name '$client'" if !$::auth->set_client($client);
35
36   $::instance_conf = SL::InstanceConfiguration->new;
37   $::request       = Support::TestSetup->create_new_request;
38
39   die 'cannot reach auth db'               unless $::auth->session_tables_present;
40
41   $::auth->restore_session;
42
43   require "bin/mozilla/common.pl";
44
45   die "cannot find user $login"            unless %::myconfig = $::auth->read_user(login => $login);
46
47   die "cannot find locale for user $login" unless $::locale   = Locale->new($::myconfig{countrycode});
48
49   $SIG{__DIE__} = sub { Carp::confess( @_ ) } if $::lx_office_conf{debug}->{backtrace_on_die};
50
51
52   return 1;
53 }
54
55 sub create_new_form { Form->new('') }
56
57 sub create_new_request {
58   my $self = shift;
59
60   my $request = SL::Request->new(
61     cgi    => CGI->new({}),
62     layout => SL::Layout::None->new,
63     @_,
64   );
65
66   $request->presenter->{template} = Template->new(template_config()) || die;
67
68   return $request;
69 }
70
71 sub template_config {
72   return {
73     INTERPOLATE  => 0,
74     EVAL_PERL    => 0,
75     ABSOLUTE     => 1,
76     CACHE_SIZE   => 0,
77     PLUGIN_BASE  => 'SL::Template::Plugin',
78     INCLUDE_PATH => '.:templates/webpages/',
79     COMPILE_DIR  => 'users/templates-cache-for-tests',
80     COMPILE_EXT  => '.tcc',
81     ENCODING     => 'utf8',
82   };
83 }
84
85 1;