X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fpost.t;h=54e21c6fedf3003548de17ab6b76324b8bc0c5be;hb=24ecd3bd2cf188c1909b62228a55dd6b5eca3d2e;hp=09818581b545f029c615dbf70451d6f04a99c0dc;hpb=1bba6f8837b67795b5a9c215e9158d4defa81461;p=catagits%2FWeb-Simple.git diff --git a/t/post.t b/t/post.t index 0981858..54e21c6 100644 --- a/t/post.t +++ b/t/post.t @@ -20,6 +20,13 @@ use Test::More qw(no_plan); [ $_[1]->reason || $_[1]->filename ], ] }, + sub (POST + %* + %biff=) { + $_[1]->{bar} ||= 'EMPTY'; + [ 200, + [ "Content-type" => "text/plain" ], + [ join(' ',@{$_[1]}{qw(biff bong)}) ] + ] + }, } } @@ -28,26 +35,26 @@ use HTTP::Request::Common qw(GET POST); my $app = PostTest->new; sub run_request { $app->run_test_request(@_); } -my $get = run_request(GET => 'http://localhost/'); +my $get = run_request(GET 'http://localhost/'); cmp_ok($get->code, '==', 404, '404 on GET'); -my $no_body = run_request(POST => 'http://localhost/'); +my $no_body = run_request(POST 'http://localhost/'); cmp_ok($no_body->code, '==', 404, '404 with empty body'); -my $no_foo = run_request(POST => 'http://localhost/' => [ bar => 'BAR' ]); +my $no_foo = run_request(POST 'http://localhost/' => [ bar => 'BAR' ]); cmp_ok($no_foo->code, '==', 404, '404 with no foo param'); -my $no_bar = run_request(POST => 'http://localhost/' => [ foo => 'FOO' ]); +my $no_bar = run_request(POST 'http://localhost/' => [ foo => 'FOO' ]); cmp_ok($no_bar->code, '==', 200, '200 with only foo param'); is($no_bar->content, 'FOO EMPTY', 'bar defaulted'); my $both = run_request( - POST => 'http://localhost/' => [ foo => 'FOO', bar => 'BAR' ] + POST 'http://localhost/' => [ foo => 'FOO', bar => 'BAR' ] ); cmp_ok($both->code, '==', 200, '200 with both params'); @@ -67,8 +74,21 @@ cmp_ok($upload->code, '==', 200, '200 with multipart'); is($upload->content, 'FOO BAR', 'both params returned'); +my $upload_splat = run_request( + POST 'http://localhost' + => Content_Type => 'form-data' + => Content => [ + biff => 'frew', + bong => 'fru' + ] +); + +cmp_ok($upload_splat->code, '==', 200, '200 with multipart'); + +is($upload_splat->content, 'frew fru', 'both params returned'); + my $upload_wrongtype = run_request( - POST => 'http://localhost' + POST 'http://localhost' => [ baz => 'fleem' ] );