From: Torsten Raudssus Date: Thu, 29 Jan 2015 03:48:33 +0000 (+0100) Subject: Fixed test which failed if Plack wasn't installed X-Git-Tag: v1.21^0 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FHTTP-Body.git;a=commitdiff_plain;h=2fdfe663dd87eb0958334590a46e7f76827925a3 Fixed test which failed if Plack wasn't installed --- diff --git a/Changes b/Changes index d1ab121..16aa517 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,9 @@ This file documents the revision history for Perl extension HTTP::Body. {{$NEXT}} + - Fix for failing test if Plack is not installed + +1.20 2015-01-28 16:20:59+01:00 Europe/Berlin -new method 'part_data' which preserves multipart meta information just in cause you have a form upload with unexpected charsets, etc. diff --git a/t/10mixparamcontent.t b/t/10mixparamcontent.t index 726fe0b..e956380 100644 --- a/t/10mixparamcontent.t +++ b/t/10mixparamcontent.t @@ -11,95 +11,101 @@ use HTTP::Message::PSGI (); use File::Spec::Functions; use File::Temp qw/ tempdir /; +SKIP: { + eval { require HTTP::Message::PSGI }; -my $string_for_utf8 = 'test ♥'; -my $string_in_utf8 = Encode::encode('UTF-8',$string_for_utf8); -my $string_for_shiftjis = 'test テスト'; -my $string_in_shiftjis = Encode::encode('SHIFT_JIS',$string_for_shiftjis); -my $path = File::Spec->catfile('t', 'utf8.txt'); + skip "Plack not installed", 13 if $@; -ok my $req = POST '/root/echo_arg', - Content_Type => 'form-data', - Content => [ - arg0 => 'helloworld', - arg1 => [ - undef, '', - 'Content-Type' =>'text/plain; charset=UTF-8', - 'Content' => $string_in_utf8, ], - arg2 => [ - undef, '', - 'Content-Type' =>'text/plain; charset=SHIFT_JIS', - 'Content' => $string_in_shiftjis, ], - arg2 => [ - undef, '', - 'Content-Type' =>'text/plain; charset=SHIFT_JIS', - 'Content' => $string_in_shiftjis, ], - file => [ - "$path", Encode::encode_utf8('♥ttachment.txt'), 'Content-Type' =>'text/html; charset=UTF-8' - ], - ]; + my $string_for_utf8 = 'test ♥'; + my $string_in_utf8 = Encode::encode('UTF-8',$string_for_utf8); + my $string_for_shiftjis = 'test テスト'; + my $string_in_shiftjis = Encode::encode('SHIFT_JIS',$string_for_shiftjis); + my $path = File::Spec->catfile('t', 'utf8.txt'); + ok my $req = POST '/root/echo_arg', + Content_Type => 'form-data', + Content => [ + arg0 => 'helloworld', + arg1 => [ + undef, '', + 'Content-Type' =>'text/plain; charset=UTF-8', + 'Content' => $string_in_utf8, ], + arg2 => [ + undef, '', + 'Content-Type' =>'text/plain; charset=SHIFT_JIS', + 'Content' => $string_in_shiftjis, ], + arg2 => [ + undef, '', + 'Content-Type' =>'text/plain; charset=SHIFT_JIS', + 'Content' => $string_in_shiftjis, ], + file => [ + "$path", Encode::encode_utf8('♥ttachment.txt'), 'Content-Type' =>'text/html; charset=UTF-8' + ], + ]; -ok my $env = HTTP::Message::PSGI::req_to_psgi($req); -ok my $fh = $env->{'psgi.input'}; -ok my $body = HTTP::Body->new( $req->header('Content-Type'), $req->header('Content-Length') ); -ok my $tempdir = tempdir( 'XXXXXXX', CLEANUP => 1, DIR => File::Spec->tmpdir() ); -$body->tmpdir($tempdir); -binmode $fh, ':raw'; + ok my $env = HTTP::Message::PSGI::req_to_psgi($req); + ok my $fh = $env->{'psgi.input'}; + ok my $body = HTTP::Body->new( $req->header('Content-Type'), $req->header('Content-Length') ); + ok my $tempdir = tempdir( 'XXXXXXX', CLEANUP => 1, DIR => File::Spec->tmpdir() ); + $body->tmpdir($tempdir); -while ( $fh->read( my $buffer, 1024 ) ) { - $body->add($buffer); -} + binmode $fh, ':raw'; -is $body->param->{'arg0'}, 'helloworld'; -is $body->param->{'arg1'}, $string_in_utf8; -is $body->param->{'arg2'}[0], $string_in_shiftjis; -is $body->param->{'arg2'}[1], $string_in_shiftjis; + while ( $fh->read( my $buffer, 1024 ) ) { + $body->add($buffer); + } -cmp_deeply( - $body->part_data->{'arg0'}, - { - data => 'helloworld', - headers => { - 'Content-Disposition' => re(qr{^form-data\b}), - }, - done => 1, - name => 'arg0', - size => 10, - }, - 'arg0 part data correct', -); -cmp_deeply( - $body->part_data->{'arg1'}, - { - data => $string_in_utf8, - headers => { - 'Content-Disposition' => re(qr{^form-data\b}), - 'Content-Type' => 'text/plain; charset=UTF-8', - }, - done => 1, - name => 'arg1', - size => length($string_in_utf8), - }, - 'arg1 part data correct', -); + is $body->param->{'arg0'}, 'helloworld'; + is $body->param->{'arg1'}, $string_in_utf8; + is $body->param->{'arg2'}[0], $string_in_shiftjis; + is $body->param->{'arg2'}[1], $string_in_shiftjis; -cmp_deeply( - $body->part_data->{'arg2'}, - [ - ({ - data => $string_in_shiftjis, + cmp_deeply( + $body->part_data->{'arg0'}, + { + data => 'helloworld', + headers => { + 'Content-Disposition' => re(qr{^form-data\b}), + }, + done => 1, + name => 'arg0', + size => 10, + }, + 'arg0 part data correct', + ); + cmp_deeply( + $body->part_data->{'arg1'}, + { + data => $string_in_utf8, headers => { 'Content-Disposition' => re(qr{^form-data\b}), - 'Content-Type' => 'text/plain; charset=SHIFT_JIS', + 'Content-Type' => 'text/plain; charset=UTF-8', }, done => 1, - name => 'arg2', - size => length($string_in_shiftjis), - }) x 2, - ], - 'arg2 part data correct', -); + name => 'arg1', + size => length($string_in_utf8), + }, + 'arg1 part data correct', + ); + + cmp_deeply( + $body->part_data->{'arg2'}, + [ + ({ + data => $string_in_shiftjis, + headers => { + 'Content-Disposition' => re(qr{^form-data\b}), + 'Content-Type' => 'text/plain; charset=SHIFT_JIS', + }, + done => 1, + name => 'arg2', + size => length($string_in_shiftjis), + }) x 2, + ], + 'arg2 part data correct', + ); + +}; done_testing;