File: select.t

package info (click to toggle)
libwww-mechanize-perl 1.18-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 488 kB
  • ctags: 109
  • sloc: perl: 2,315; makefile: 39
file content (82 lines) | stat: -rw-r--r-- 2,565 bytes parent folder | download | duplicates (2)
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
#!perl -T

use warnings;
use strict;
use Test::More tests => 14;
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/select.html" )->as_string;
my $response = $mech->get( $uri );
ok( $response->is_success, "Fetched $uri" );

my ($sendsingle, @sendmulti, %sendsingle, %sendmulti,
    $rv, $return, @return, @singlereturn, $form);
# possible values are: aaa, bbb, ccc, ddd
$sendsingle = 'aaa';
@sendmulti = qw(bbb ccc);
@singlereturn = ($sendmulti[0]);
%sendsingle = (n => 1);
%sendmulti = (n => [2, 3]);

ok($mech->form_number(1), "set form to number 1");
$form = $mech->current_form();


# Multi-select

# pass multiple values to a multi select
$mech->select("multilist", \@sendmulti);
@return = $form->param("multilist");
is_deeply(\@return, \@sendmulti, "multi->multi value is " . join(' ', @return));

$mech->select("multilist", \%sendmulti);
@return = $form->param("multilist");
is_deeply(\@return, \@sendmulti, "multi->multi value is " . join(' ', @return));

# pass a single value to a multi select
$mech->select("multilist", $sendsingle);
$return = $form->param("multilist");
is($return, $sendsingle, "single->multi value is '$return'");

$mech->select("multilist", \%sendsingle);
$return = $form->param("multilist");
is($return, $sendsingle, "single->multi value is '$return'");


# Single select

# pass multiple values to a single select (only the _first_ should be set)
$mech->select("singlelist", \@sendmulti);
@return = $form->param("singlelist");
is_deeply(\@return, \@singlereturn, "multi->single value is " . join(' ', @return));

$mech->select("singlelist", \%sendmulti);
@return = $form->param("singlelist");
is_deeply(\@return, \@singlereturn, "multi->single value is " . join(' ', @return));


# pass a single value to a single select
$rv = $mech->select("singlelist", $sendsingle);
$return = $form->param("singlelist");
is($return, $sendsingle, "single->single value is '$return'");

$rv = $mech->select("singlelist", \%sendsingle);
$return = $form->param("singlelist");
is($return, $sendsingle, "single->single value is '$return'");

# test return value from $mech->select
is($rv, 1, 'return 1 after successful select');

EAT_THE_WARNING: { # Mech complains about the non-existent field
    local $SIG{__WARN__} = sub {};
    $rv = $mech->select('missing_list', 1);
}
is($rv, undef, 'return undef after failed select');