steal some code from CGI::Compile, 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 Catalyst::Test 'TestCGIBin';
11use HTTP::Request::Common;
12
46a4350c 13# this should be ignored
14$ENV{MOD_PERL} = "mod_perl/2.0";
15
9cc2dd4c 16my $response = request POST '/my-bin/path/test.pl', [
21a20b7e 17 foo => 'bar',
18 bar => 'baz'
19];
20
21is($response->content, 'foo:bar bar:baz', 'POST to Perl CGI File');
22
06d193b4 23$response = request '/my-bin/path/test.pl?foo=bar&bar=baz';
24
25is($response->content, 'foo:bar bar:baz',
26 'Perl CGI File invoked with query params');
27
bdb35995 28$response = request POST '/my-bin/exit.pl', [
29 name => 'world',
30];
31
32is($response->content, 'hello world', 'POST to Perl CGI with exit()');
33
34$response = request POST '/my-bin/exit.pl', [
35 name => 'world',
36 exit => 17,
37];
38
39is($response->code, 500, 'POST to Perl CGI with nonzero exit()');
40
21a20b7e 41$response = request POST '/cgihandler/mtfnpy', [
42 foo => 'bar',
43 bar => 'baz'
44];
45
46is($response->content, 'foo:bar bar:baz',
47 'POST to Perl CGI File through a forward via cgi_action');
48
63096ad1 49$response = request '/my-bin/path/testdata.pl';
fbaba9dd 50is($response->content, "testing\n",
51 'scripts with __DATA__ sections work');
52
f410f043 53$response = request '/my-bin/pathinfo.pl/path/info';
54is($response->content, '/path/info',
55 'PATH_INFO works');
56
d5ba2ab2 57my %orig_sig = %SIG;
58
59ok request '/my-bin/sigs.pl';
60
61is_deeply \%SIG, \%orig_sig, '%SIG is preserved';
62
21a20b7e 63SKIP: {
64 skip "Can't run shell scripts on non-*nix", 1
65 if $^O eq 'MSWin32' || $^O eq 'VMS';
66
5709e6bd 67# for some reason the +x is not preserved in the dist
68 system "chmod +x $Bin/lib/TestCGIBin/root/cgi-bin/test.sh";
69
9cc2dd4c 70 is(get('/my-bin/test.sh'), "Hello!\n", 'Non-Perl CGI File');
21a20b7e 71}
d5ba2ab2 72
73done_testing;