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