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