2 use warnings FATAL => 'all';
4 use Test::More qw(no_plan);
7 use Web::Simple 'PostTest';
11 $_[1]->{bar} ||= 'EMPTY';
13 [ "Content-type" => "text/plain" ],
14 [ join(' ',@{$_[1]}{qw(foo bar)}) ]
19 [ "Content-type" => "text/plain" ],
20 [ $_[1]->reason || $_[1]->filename ],
23 sub (POST + %* + %biff=) {
24 $_[1]->{bar} ||= 'EMPTY';
26 [ "Content-type" => "text/plain" ],
27 [ join(' ',@{$_[1]}{qw(biff bong)}) ]
33 use HTTP::Request::Common qw(GET POST);
35 my $app = PostTest->new;
36 sub run_request { $app->run_test_request(@_); }
38 my $get = run_request(GET 'http://localhost/');
40 cmp_ok($get->code, '==', 404, '404 on GET');
42 my $no_body = run_request(POST 'http://localhost/');
44 cmp_ok($no_body->code, '==', 404, '404 with empty body');
46 my $no_foo = run_request(POST 'http://localhost/' => [ bar => 'BAR' ]);
48 cmp_ok($no_foo->code, '==', 404, '404 with no foo param');
50 my $no_bar = run_request(POST 'http://localhost/' => [ foo => 'FOO' ]);
52 cmp_ok($no_bar->code, '==', 200, '200 with only foo param');
54 is($no_bar->content, 'FOO EMPTY', 'bar defaulted');
56 my $both = run_request(
57 POST 'http://localhost/' => [ foo => 'FOO', bar => 'BAR' ]
60 cmp_ok($both->code, '==', 200, '200 with both params');
62 is($both->content, 'FOO BAR', 'both params returned');
64 my $upload = run_request(
65 POST 'http://localhost'
66 => Content_Type => 'form-data'
73 cmp_ok($upload->code, '==', 200, '200 with multipart');
75 is($upload->content, 'FOO BAR', 'both params returned');
77 my $upload_splat = run_request(
78 POST 'http://localhost'
79 => Content_Type => 'form-data'
86 cmp_ok($upload_splat->code, '==', 200, '200 with multipart');
88 is($upload_splat->content, 'frew fru', 'both params returned');
90 my $upload_wrongtype = run_request(
91 POST 'http://localhost'
96 $upload_wrongtype->content,
97 'field baz exists with value fleem but body was not multipart/form-data',
98 'error points out wrong body type'
101 my $upload_notupload = run_request(
102 POST 'http://localhost'
103 => Content_Type => 'form-data'
104 => Content => [ baz => 'fleem' ]
108 $upload_notupload->content,
109 'field baz exists with value fleem but was not an upload',
110 'error points out field was not an upload'
113 my $upload_isupload = run_request(
114 POST 'http://localhost'
115 => Content_Type => 'form-data'
119 Content => 'test content', 'Content-Type' => 'text/plain'
125 $upload_isupload->content,
127 'Actual upload returns filename ok'