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