Skip to content

Commit

Permalink
more tests for Mojo::UserAgent::Transactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 10, 2013
1 parent c8498ac commit c5459c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,5 +1,6 @@

3.77 2013-01-11
- Improved tests.
- Fixed small upgrade bug in Mojo::UserAgent::Transactor.

3.76 2013-01-10
Expand Down
23 changes: 21 additions & 2 deletions t/mojo/transactor.t
Expand Up @@ -3,6 +3,7 @@ use Mojo::Base -strict;
use Test::More;
use File::Spec::Functions 'catdir';
use FindBin;
use Mojo::Asset::File;
use Mojo::Transaction::WebSocket;
use Mojo::URL;
use Mojo::UserAgent::Transactor;
Expand Down Expand Up @@ -153,8 +154,8 @@ is_deeply [$tx->req->param('a')], [1, 2, 3], 'right values';
is_deeply [$tx->req->param('b')], [4], 'right values';

# Multipart form with real file and custom header
$tx = $t->form('http://kraih.com/foo',
{mytext => {file => catdir($FindBin::Bin, 'transactor.t'), DNT => 1}});
my $path = catdir $FindBin::Bin, 'transactor.t';
$tx = $t->form('http://kraih.com/foo', {mytext => {file => $path, DNT => 1}});
is $tx->req->url->to_abs, 'http://kraih.com/foo', 'right URL';
is $tx->req->method, 'POST', 'right method';
is $tx->req->headers->content_type, 'multipart/form-data',
Expand All @@ -164,10 +165,26 @@ like $tx->req->content->parts->[0]->headers->content_disposition,
like $tx->req->content->parts->[0]->headers->content_disposition,
qr/"transactor.t"/, 'right "Content-Disposition" value';
like $tx->req->content->parts->[0]->asset->slurp, qr/mytext/, 'right part';
ok $tx->req->content->parts->[0]->asset->is_file, 'stored in file';
ok !$tx->req->content->parts->[0]->headers->header('file'), 'no "file" header';
is $tx->req->content->parts->[0]->headers->dnt, 1, 'right "DNT" header';
is $tx->req->content->parts->[1], undef, 'no more parts';

# Multipart form with asset
$tx = $t->form('http://kraih.com/foo',
{mytext => {file => Mojo::Asset::File->new(path => $path)}});
is $tx->req->url->to_abs, 'http://kraih.com/foo', 'right URL';
is $tx->req->method, 'POST', 'right method';
is $tx->req->headers->content_type, 'multipart/form-data',
'right "Content-Type" value';
like $tx->req->content->parts->[0]->headers->content_disposition,
qr/"mytext"/, 'right "Content-Disposition" value';
like $tx->req->content->parts->[0]->headers->content_disposition,
qr/"transactor.t"/, 'right "Content-Disposition" value';
like $tx->req->content->parts->[0]->asset->slurp, qr/mytext/, 'right part';
ok $tx->req->content->parts->[0]->asset->is_file, 'stored in file';
is $tx->req->content->parts->[1], undef, 'no more parts';

# Multipart form with in-memory content
$tx = $t->form('http://kraih.com/foo' => {mytext => {content => 'lalala'}});
is $tx->req->url->to_abs, 'http://kraih.com/foo', 'right URL';
Expand All @@ -179,6 +196,8 @@ like $tx->req->content->parts->[0]->headers->content_disposition, qr/mytext/,
ok !$tx->req->content->parts->[0]->headers->header('content'),
'no "content" header';
is $tx->req->content->parts->[0]->asset->slurp, 'lalala', 'right part';
ok !$tx->req->content->parts->[0]->asset->is_file, 'stored in memory';
ok !$tx->req->content->parts->[0]->asset->auto_upgrade, 'no upgrade';
is $tx->req->content->parts->[1], undef, 'no more parts';

# Multipart form with filename
Expand Down

0 comments on commit c5459c6

Please sign in to comment.