]> wagnertech.de Git - kivitendo-erp.git/commitdiff
Tests: Template-Objekt in Form für Test-Cache-Verzeichnis anlegen
authorMoritz Bunkus <m.bunkus@linet-services.de>
Fri, 10 Feb 2017 14:26:51 +0000 (15:26 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Fri, 10 Feb 2017 14:26:51 +0000 (15:26 +0100)
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.

t/Support/TestSetup.pm
t/controllers/base/render.t
t/presenter/base/render.t
t/template_syntax.t

index 037cfb547e7b06a08e857863792776c8f6fd7f61..2894cbb2fcbfc97de4509e86fdcf7aa1c7d16ca5 100644 (file)
@@ -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;
index 3d5bad0e5c856d447c50a68b74531502e6f981ee..753c1cb52cff9f2ac16a7e3fde70144049cbc305 100644 (file)
@@ -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';
 
index 4e389f9b027250c7b22ca2eb0ef9a814533a3490..1809a971d718427498cc072695b36140dcf3e596 100644 (file)
@@ -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:
index b63d6bb17b198387e99059835e7e6a93e7717222..f31c4e5ecdf243e9ab5ef811c0f8688d6e0a6e45 100644 (file)
@@ -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";