From: Sven Schöling Date: Wed, 26 Oct 2011 12:58:15 +0000 (+0200) Subject: Loginmechanismus für Testscripte X-Git-Tag: release-2.7.0beta1~207 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=1d64d7e59fe964edde711f52beeb291e092459ab;p=kivitendo-erp.git Loginmechanismus für Testscripte --- diff --git a/config/lx_office.conf.default b/config/lx_office.conf.default index b0c3e66e5..d84b1c951 100644 --- a/config/lx_office.conf.default +++ b/config/lx_office.conf.default @@ -178,6 +178,11 @@ history_file = users/console_history # to the lx-office log will be put here if triggered from the console log_file = /tmp/lxoffice_console_debug.log +[testing] + +# autologin to use if none is given +login = demo + [debug] # Use DBIx::Log4perl for logging DBI calls. The string LXDEBUGFILE # will be replaced by the file name configured for $::lxdebug. diff --git a/t/Support/TestSetup.pm b/t/Support/TestSetup.pm new file mode 100644 index 000000000..c23b4fd7f --- /dev/null +++ b/t/Support/TestSetup.pm @@ -0,0 +1,52 @@ +package Support::TestSetup; + +use strict; + +use Data::Dumper; +use CGI qw( -no_xhtml); +use SL::Auth; +use SL::Form; +use SL::Locale; +use SL::LXDebug; +use Data::Dumper; +use SL::LxOfficeConf; +use SL::InstanceConfiguration; +SL::LxOfficeConf->read; + +sub _login { + my $login = shift; + + die 'need login' unless $login; + + package main; + + $::lxdebug = LXDebug->new(file => \*STDERR); + $::locale = Locale->new($::lx_office_conf{system}->{language}); + $::form = Form->new; + $::auth = SL::Auth->new; + $::instance_conf = SL::InstanceConfiguration->new; + $::request = { cgi => CGI->new({}) }; + + die 'cannot reach auth db' unless $::auth->session_tables_present; + + $::auth->restore_session; + + require "bin/mozilla/common.pl"; + + die "cannot find user $login" unless %::myconfig = $::auth->read_user($login); + + $::form->{login} = $login; # normaly implicit at login + + die "cannot find locale for user $login" unless $::locale = Locale->new($::myconfig{countrycode}); + + $::instance_conf->init; + + return 1; +} + +sub login { + my $login = shift || $::lx_office_conf{testing}{login} || 'demo'; + _login($login); +} + +1;