From: Moritz Bunkus Date: Fri, 10 Feb 2017 14:26:51 +0000 (+0100) Subject: Tests: Template-Objekt in Form für Test-Cache-Verzeichnis anlegen X-Git-Tag: release-3.5.4~1496 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=bbc0a6b813f1f67756d1c3fd0dbc83a6dc836110;p=kivitendo-erp.git Tests: Template-Objekt in Form für Test-Cache-Verzeichnis anlegen Dient dafür, Dateizugriffsprobleme wegen Berechtigungen zu vermeiden: »users/templates-cache« wird normalerweise vom Webserveruser erzeugt und beschrieben, die darin liegenden Dateien haben mode 0600. Tests werden hingegen als normale User ausgeführt und haben damit nicht mal Leserechte auf die Dateien in »users/templates-cache«. Das Template-Objekt wird direkt in $::form abgelegt, wodurch dann auch reguläre Routinen wie SL::Presenter::Base->render ins richtige Verzeichnis schreiben. Damit müssen auch keine Render-Tests mehr übersprungen werden, falls keine Schreibrechte auf das Haupt-Cache-Verzeichnis »users/templates-cache« besteht. --- diff --git a/t/Support/TestSetup.pm b/t/Support/TestSetup.pm index 037cfb547..2894cbb2f 100644 --- a/t/Support/TestSetup.pm +++ b/t/Support/TestSetup.pm @@ -48,22 +48,27 @@ sub login { $SIG{__DIE__} = sub { Carp::confess( @_ ) } if $::lx_office_conf{debug}->{backtrace_on_die}; + Support::TestSetup::create_form_template_provider(); + return 1; } -sub templates_cache_writable { - my $dir = $::lx_office_conf{paths}->{userspath} . '/templates-cache'; - return 1 if -w $dir; - - # Try actually creating a file. Due to ACLs this might be possible - # even if the basic Unix permissions and Perl's -w test say - # otherwise. - my $file = "${dir}/.writetest"; - my $out = IO::File->new($file, "w") || return 0; - $out->close; - unlink $file; +sub create_form_template_provider { + $::form->template(Template->new(template_config())) || die; +} - return 1; +sub template_config { + return { + INTERPOLATE => 0, + EVAL_PERL => 0, + ABSOLUTE => 1, + CACHE_SIZE => 0, + PLUGIN_BASE => 'SL::Template::Plugin', + INCLUDE_PATH => '.:templates/webpages/', + COMPILE_DIR => 'users/templates-cache-for-tests', + COMPILE_EXT => '.tcc', + ENCODING => 'utf8', + }; } 1; diff --git a/t/controllers/base/render.t b/t/controllers/base/render.t index 3d5bad0e5..753c1cb52 100644 --- a/t/controllers/base/render.t +++ b/t/controllers/base/render.t @@ -1,6 +1,6 @@ use strict; use Test::Exception; -use Test::More; +use Test::More tests => 19; use Test::Output; use lib 't'; @@ -14,12 +14,6 @@ no warnings 'uninitialized'; Support::TestSetup::login(); -if (!Support::TestSetup::templates_cache_writable()) { - plan skip_all => 'Cache dir not writable for this test'; -} else { - plan tests => 19; -} - sub reset_test_env { $ENV{HTTP_USER_AGENT} = 'Perl Tests'; diff --git a/t/presenter/base/render.t b/t/presenter/base/render.t index 4e389f9b0..1809a971d 100644 --- a/t/presenter/base/render.t +++ b/t/presenter/base/render.t @@ -1,6 +1,6 @@ use strict; use Test::Exception; -use Test::More; +use Test::More tests => 11; use lib 't'; use Support::TestSetup; @@ -9,12 +9,6 @@ use SL::Presenter; Support::TestSetup::login(); -if (!Support::TestSetup::templates_cache_writable()) { - plan skip_all => 'Cache dir not writable for this test'; -} else { - plan tests => 11; -} - my $pr = SL::Presenter->get; # Passing invalid parameters: diff --git a/t/template_syntax.t b/t/template_syntax.t index b63d6bb17..f31c4e5ec 100644 --- a/t/template_syntax.t +++ b/t/template_syntax.t @@ -3,6 +3,7 @@ use strict; use lib 't'; use Support::Templates; +use Support::TestSetup; use File::Spec; use File::Slurp; @@ -12,15 +13,7 @@ use Test::More tests => ( scalar(@referenced_files)); my $template_path = 'templates/webpages/'; -my $provider = Template::Provider->new({ - INTERPOLATE => 0, - EVAL_PERL => 0, - ABSOLUTE => 1, - CACHE_SIZE => 0, - PLUGIN_BASE => 'SL::Template::Plugin', - INCLUDE_PATH => '.:' . $template_path, - COMPILE_DIR => 'users/templates-cache-for-tests', -}); +my $provider = Template::Provider->new(Support::TestSetup::template_config()); foreach my $ref (@Support::Templates::referenced_files) { my $file = "${template_path}${ref}.html";