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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
#!perl
use warnings;
use strict;
use Test::More;
use Test::Fatal qw( exception );
use Test::Warnings ':all';
use URI::file ();
use WWW::Mechanize ();
my $mech = WWW::Mechanize->new( cookie_jar => undef, autocheck => 0 );
my $uri = URI::file->new_abs('t/form_with_fields.html')->as_string;
$mech->get($uri);
{
$mech->get($uri);
like(
exception {
$mech->submit_form(
form_id => 'i-do-not-exist',
);
},
qr/There is no form with ID "i-do-not-exist"/,
'submit_form with no match on form_id',
);
}
{
$mech->get($uri);
is(
exception {
$mech->submit_form(
form_id => '6th_form',
);
},
undef,
'submit_form with valid form_id',
);
}
{
$mech->get($uri);
like(
exception {
$mech->submit_form(
form_thing => 'i-do-not-exist',
);
},
qr/Unknown submit_form parameter "form_thing"/,
'submit_form with invalid arg',
);
}
{
$mech->get($uri);
like(
exception {
$mech->submit_form(
form_number => 99,
);
},
qr/There is no form numbered 99/,
'submit_form with invalid form number',
);
}
{
$mech->get($uri);
like(
exception {
$mech->submit_form(
form_name => 99,
);
},
qr/There is no form named "99"/,
'submit_form with invalid form name',
);
}
{
$mech->get($uri);
like(
exception {
$mech->submit_form(
with_fields => [ 'foo', 'bar' ],
);
},
qr/with_fields arg to submit_form must be a hashref/,
'submit_form with invalid arg value for with_fields',
);
}
{
$mech->get($uri);
like(
exception {
$mech->submit_form(
fields => [ 'foo', 'bar' ],
);
},
qr/fields arg to submit_form must be a hashref/,
'submit_form with invalid arg value for fields',
);
}
{
$mech->get($uri);
like(
exception {
$mech->submit_form(
with_fields => {}, # left empty on purpose
)
},
qr/no fields provided/,
'submit_form with no fields',
);
}
done_testing();
|