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