File: find_inputs.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 (52 lines) | stat: -rw-r--r-- 1,438 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
43
44
45
46
47
48
49
50
51
52
#!perl -T

use warnings;
use strict;

use Test::More tests => 11;
use URI::file;

BEGIN {
    delete @ENV{qw(PATH IFS CDPATH ENV BASH_ENV)};  # Placates taint-unsafe Cwd.pm in 5.6.1
    use_ok( 'WWW::Mechanize' );
}

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

my $uri = URI::file->new_abs( 't/find_inputs.html' )->as_string;

$mech->get( $uri );
ok( $mech->success, "Fetched $uri" ) or die q{Can't get test page};

FIRST_FORM: {
    my @inputs = $mech->find_all_inputs();
    is( scalar @inputs, 3, 'Exactly three inputs' );

    my @submits = $mech->find_all_submits();
    is( scalar @submits, 2, 'Exactly two submits' );
}

SECOND_FORM: {
    $mech->form_number(2);
    my @inputs = $mech->find_all_inputs();
    is( scalar @inputs, 4, 'Exactly four inputs' );

    my @submits = $mech->find_all_submits();
    is( scalar @submits, 1, 'Exactly one submit' );
}

THIRD_FORM: {
    $mech->form_number(3);
    my @inputs = $mech->find_all_inputs();
    is( scalar @inputs, 5, 'Exactly five inputs' );

    my @relatives = $mech->find_all_inputs( name_regex => qr/^Your/ );
    is( scalar @relatives, 4, 'Found four relatives' );

    my @sisters = $mech->find_all_inputs( name => 'YourSister' );
    is( scalar @sisters, 2, 'Found two sisters' );

    my @submit_sisters = $mech->find_all_inputs( name => 'YourSister' );
    is( scalar @submit_sisters, 2, 'But no sisters are submits' );
}