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 ],
26 use HTTP::Request::Common qw(GET POST);
28 my $app = PostTest->new;
29 sub run_request { $app->run_test_request(@_); }
31 my $get = run_request(GET 'http://localhost/');
33 cmp_ok($get->code, '==', 404, '404 on GET');
35 my $no_body = run_request(POST 'http://localhost/');
37 cmp_ok($no_body->code, '==', 404, '404 with empty body');
39 my $no_foo = run_request(POST 'http://localhost/' => [ bar => 'BAR' ]);
41 cmp_ok($no_foo->code, '==', 404, '404 with no foo param');
43 my $no_bar = run_request(POST 'http://localhost/' => [ foo => 'FOO' ]);
45 cmp_ok($no_bar->code, '==', 200, '200 with only foo param');
47 is($no_bar->content, 'FOO EMPTY', 'bar defaulted');
49 my $both = run_request(
50 POST 'http://localhost/' => [ foo => 'FOO', bar => 'BAR' ]
53 cmp_ok($both->code, '==', 200, '200 with both params');
55 is($both->content, 'FOO BAR', 'both params returned');
57 my $upload = run_request(
58 POST 'http://localhost'
59 => Content_Type => 'form-data'
66 cmp_ok($upload->code, '==', 200, '200 with multipart');
68 is($upload->content, 'FOO BAR', 'both params returned');
70 my $upload_wrongtype = run_request(
71 POST 'http://localhost'
76 $upload_wrongtype->content,
77 'field baz exists with value fleem but body was not multipart/form-data',
78 'error points out wrong body type'
81 my $upload_notupload = run_request(
82 POST 'http://localhost'
83 => Content_Type => 'form-data'
84 => Content => [ baz => 'fleem' ]
88 $upload_notupload->content,
89 'field baz exists with value fleem but was not an upload',
90 'error points out field was not an upload'
93 my $upload_isupload = run_request(
94 POST 'http://localhost'
95 => Content_Type => 'form-data'
99 Content => 'test content', 'Content-Type' => 'text/plain'
105 $upload_isupload->content,
107 'Actual upload returns filename ok'