File: submit_form.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 (94 lines) | stat: -rw-r--r-- 1,917 bytes parent folder | download
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
#!perl

use warnings;
use strict;

use Test::More;
use Test::Fatal;
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);
    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',
    );
}

done_testing();