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