t: replace variable root directory in tests
[perl/plp/.git] / t / 50-cgi.t
1 use strict;
2 use warnings;
3
4 use File::Basename qw( dirname );
5 use File::Spec;
6 use Test::More tests => 25;
7
8 use_ok('Test::PLP');
9
10 $PLP::use_cache = 0 if $PLP::use_cache;
11 #TODO: caching on (change file names)
12
13 chdir File::Spec->catdir(dirname($0), '50-cgi')
14         or BAIL_OUT('cannot change to test directory ./50-cgi/');
15
16 # 0*: permission checks using generated dummy files
17 SKIP:
18 for my $file (glob '0*.html') {
19         $file =~ s/[.]html$/.plp/;
20         my ($mode) = $file =~ /^..-(\d*)\b/;
21         eval {
22                 if ($mode eq 404) {
23                         return 1;  # do not create
24                 }
25
26                 # prepare input
27                 open my $out, '>', $file or die "cannot generate source file ($!)\n";
28                 print {$out} 'ok';
29
30                 if ($mode eq 403) {
31                         chmod 0244, $file or die "cannot change permissions ($!)\n";
32                 }
33
34                 return -e $file;
35         } or chomp $@, skip("$file: $@", 1);  # ignore generation failure
36
37         plp_ok($file);
38         eval { unlink $file };  # clean up
39 }
40
41 # 1*-2*: generic tests with standard environment
42 plp_ok($_) for glob '[12]*.html';
43
44 # 3*: error tests depending on warning message
45 SKIP: {
46         my @inctests = glob '3*.html';
47
48         my $INCFILE = File::Spec->rel2abs("./missinginclude");
49         if (open my $dummy, "<", $INCFILE) {  # like PLP::source will
50                 fail("file missinginclude shouldn't exist");
51                 skip("missinginclude tests (3*)", @inctests - 1);
52         }
53         my $INCWARN = qq{Can't open "$INCFILE" ($!)};
54
55         plp_ok($_, INCWARN => $INCWARN) for @inctests;
56 }
57
58 # 4*-6*: apache environment (default)
59 plp_ok($_) for glob '[4-6]*.html';
60
61 #TODO: %fields
62 #TODO: %cookie
63
64 # 7*: multipart posts
65 TODO: {
66         local $TODO = 'future feature';
67         plp_ok($_, -env => {
68                 CONTENT_TYPE => 'multipart/form-data; boundary=knip',
69         }) for glob '7*.html';
70 }
71
72 # 8*: lighttpd environment
73 plp_ok($_, -env => {
74         # lighttpd/1.4.7 CGI environment
75         REQUEST_METHOD => 'GET',
76         REQUEST_URI => "/$_/test/123",
77         QUERY_STRING => 'test=1&test=2',
78         GATEWAY_INTERFACE => 'CGI/1.1',
79         
80         SCRIPT_NAME => "/$_", #XXX: .plp?
81         SCRIPT_FILENAME => "./$_",
82         PATH_INFO => '/test/123',
83         PATH_TRANSLATED => undef,
84         DOCUMENT_ROOT => undef,
85 }) for glob '8*.plp';
86