Revision bbc0a6b8
Von Moritz Bunkus vor fast 8 Jahren hinzugefügt
t/Support/TestSetup.pm | ||
---|---|---|
48 | 48 |
|
49 | 49 |
$SIG{__DIE__} = sub { Carp::confess( @_ ) } if $::lx_office_conf{debug}->{backtrace_on_die}; |
50 | 50 |
|
51 |
Support::TestSetup::create_form_template_provider(); |
|
52 |
|
|
51 | 53 |
return 1; |
52 | 54 |
} |
53 | 55 |
|
54 |
sub templates_cache_writable { |
|
55 |
my $dir = $::lx_office_conf{paths}->{userspath} . '/templates-cache'; |
|
56 |
return 1 if -w $dir; |
|
57 |
|
|
58 |
# Try actually creating a file. Due to ACLs this might be possible |
|
59 |
# even if the basic Unix permissions and Perl's -w test say |
|
60 |
# otherwise. |
|
61 |
my $file = "${dir}/.writetest"; |
|
62 |
my $out = IO::File->new($file, "w") || return 0; |
|
63 |
$out->close; |
|
64 |
unlink $file; |
|
56 |
sub create_form_template_provider { |
|
57 |
$::form->template(Template->new(template_config())) || die; |
|
58 |
} |
|
65 | 59 |
|
66 |
return 1; |
|
60 |
sub template_config { |
|
61 |
return { |
|
62 |
INTERPOLATE => 0, |
|
63 |
EVAL_PERL => 0, |
|
64 |
ABSOLUTE => 1, |
|
65 |
CACHE_SIZE => 0, |
|
66 |
PLUGIN_BASE => 'SL::Template::Plugin', |
|
67 |
INCLUDE_PATH => '.:templates/webpages/', |
|
68 |
COMPILE_DIR => 'users/templates-cache-for-tests', |
|
69 |
COMPILE_EXT => '.tcc', |
|
70 |
ENCODING => 'utf8', |
|
71 |
}; |
|
67 | 72 |
} |
68 | 73 |
|
69 | 74 |
1; |
t/controllers/base/render.t | ||
---|---|---|
1 | 1 |
use strict; |
2 | 2 |
use Test::Exception; |
3 |
use Test::More; |
|
3 |
use Test::More tests => 19;
|
|
4 | 4 |
use Test::Output; |
5 | 5 |
|
6 | 6 |
use lib 't'; |
... | ... | |
14 | 14 |
|
15 | 15 |
Support::TestSetup::login(); |
16 | 16 |
|
17 |
if (!Support::TestSetup::templates_cache_writable()) { |
|
18 |
plan skip_all => 'Cache dir not writable for this test'; |
|
19 |
} else { |
|
20 |
plan tests => 19; |
|
21 |
} |
|
22 |
|
|
23 | 17 |
sub reset_test_env { |
24 | 18 |
$ENV{HTTP_USER_AGENT} = 'Perl Tests'; |
25 | 19 |
|
t/presenter/base/render.t | ||
---|---|---|
1 | 1 |
use strict; |
2 | 2 |
use Test::Exception; |
3 |
use Test::More; |
|
3 |
use Test::More tests => 11;
|
|
4 | 4 |
|
5 | 5 |
use lib 't'; |
6 | 6 |
use Support::TestSetup; |
... | ... | |
9 | 9 |
|
10 | 10 |
Support::TestSetup::login(); |
11 | 11 |
|
12 |
if (!Support::TestSetup::templates_cache_writable()) { |
|
13 |
plan skip_all => 'Cache dir not writable for this test'; |
|
14 |
} else { |
|
15 |
plan tests => 11; |
|
16 |
} |
|
17 |
|
|
18 | 12 |
my $pr = SL::Presenter->get; |
19 | 13 |
|
20 | 14 |
# Passing invalid parameters: |
t/template_syntax.t | ||
---|---|---|
3 | 3 |
use lib 't'; |
4 | 4 |
|
5 | 5 |
use Support::Templates; |
6 |
use Support::TestSetup; |
|
6 | 7 |
|
7 | 8 |
use File::Spec; |
8 | 9 |
use File::Slurp; |
... | ... | |
12 | 13 |
|
13 | 14 |
my $template_path = 'templates/webpages/'; |
14 | 15 |
|
15 |
my $provider = Template::Provider->new({ |
|
16 |
INTERPOLATE => 0, |
|
17 |
EVAL_PERL => 0, |
|
18 |
ABSOLUTE => 1, |
|
19 |
CACHE_SIZE => 0, |
|
20 |
PLUGIN_BASE => 'SL::Template::Plugin', |
|
21 |
INCLUDE_PATH => '.:' . $template_path, |
|
22 |
COMPILE_DIR => 'users/templates-cache-for-tests', |
|
23 |
}); |
|
16 |
my $provider = Template::Provider->new(Support::TestSetup::template_config()); |
|
24 | 17 |
|
25 | 18 |
foreach my $ref (@Support::Templates::referenced_files) { |
26 | 19 |
my $file = "${template_path}${ref}.html"; |
Auch abrufbar als: Unified diff
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.