File: upload.t

package info (click to toggle)
libwww-mechanize-perl 2.03-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 988 kB
  • sloc: perl: 4,088; makefile: 6
file content (42 lines) | stat: -rw-r--r-- 948 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!perl -T

use strict;
use warnings;
use Test::More tests => 5;
use URI::file;

BEGIN { delete @ENV{ qw( http_proxy HTTP_PROXY PATH IFS CDPATH ENV BASH_ENV) }; }
use_ok( 'WWW::Mechanize' );

my $mech = WWW::Mechanize->new( cookie_jar => undef );
isa_ok( $mech, 'WWW::Mechanize' );

my $uri = URI::file->new_abs( 't/upload.html' )->as_string;
$mech->get( $uri );
ok( $mech->success, $uri );

my $form = $mech->form_number(1);
my $reqstring = $form->click->as_string;
$reqstring =~ s/\r//g;

# trim off possible extra newline
$reqstring =~ s/^\Z\n//m;

my $wanted = <<'EOT';
POST http://localhost/
Content-Length: 77
Content-Type: multipart/form-data; boundary=xYzZY

--xYzZY
Content-Disposition: form-data; name="submit"

Submit
--xYzZY--
EOT

is( $reqstring, $wanted, 'Proper posting' );

$mech->field('upload', 'dist.ini');
$reqstring = $form->click->as_string;
like( $reqstring, qr/WWW-Mechanize/, 'The uploaded file should be in the request');