fix fail with HTTP::Request::AsCGI 1.2 and Perl < 5.8.9, release
[catagits/Catalyst-Controller-WrapCGI.git] / t / cgibin.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use FindBin '$Bin';
7 use lib "$Bin/lib";
8
9 use Test::More;
10 use HTTP::Request::Common;
11
12 my %orig_sig;
13 BEGIN {
14     %orig_sig = %SIG;
15 # perl < 5.8.9 won't set a %SIG entry to undef, it sets it to ''
16     %orig_sig = map { defined $_ ? $_ : '' } %orig_sig
17         if $] < 5.008009;
18 }
19
20 use Catalyst::Test 'TestCGIBin';
21
22 # this should be ignored
23 $ENV{MOD_PERL} = "mod_perl/2.0";
24
25 is_deeply \%SIG, \%orig_sig, '%SIG is preserved on compile';
26
27 my $response = request POST '/my-bin/path/test.pl', [
28     foo => 'bar',
29     bar => 'baz'
30 ];
31
32 is($response->content, 'foo:bar bar:baz', 'POST to Perl CGI File');
33
34 $response = request '/my-bin/path/test.pl?foo=bar&bar=baz';
35
36 is($response->content, 'foo:bar bar:baz',
37     'Perl CGI File invoked with query params');
38
39 $response = request POST '/my-bin/exit.pl', [
40     name => 'world',
41 ];
42
43 is($response->content, 'hello world', 'POST to Perl CGI with exit()');
44
45 $response = request POST '/my-bin/exit.pl', [
46     name => 'world',
47     exit => 17,
48 ];
49
50 is($response->code, 500, 'POST to Perl CGI with nonzero exit()');
51
52 $response = request POST '/cgihandler/mtfnpy', [
53     foo => 'bar',
54     bar => 'baz'
55 ];
56
57 is($response->content, 'foo:bar bar:baz',
58     'POST to Perl CGI File through a forward via cgi_action');
59
60 $response = request '/my-bin/path/testdata.pl';
61 is($response->content, "testing\n",
62     'scripts with __DATA__ sections work');
63
64 $response = request '/my-bin/pathinfo.pl/path/info';
65 is($response->content, '/path/info',
66     'PATH_INFO works');
67
68 ok request '/my-bin/sigs.pl';
69
70 is_deeply \%SIG, \%orig_sig, '%SIG is preserved';
71
72 SKIP: {
73     skip "Can't run shell scripts on non-*nix", 1
74         if $^O eq 'MSWin32' || $^O eq 'VMS';
75
76 # for some reason the +x is not preserved in the dist
77     system "chmod +x $Bin/lib/TestCGIBin/root/cgi-bin/test.sh";
78     system "chmod +x $Bin/lib/TestCGIBin/root/cgi-bin/exit_nonzero.sh";
79
80     is(get('/my-bin/test.sh'), "Hello!\n", 'Non-Perl CGI File');
81
82     $response = request GET '/my-bin/exit_nonzero.sh';
83     is $response->code, 500, 'Non-Perl CGI with non-zero exit dies';
84 }
85
86 done_testing;