File: form-maxlength.t

package info (click to toggle)
libhtml-form-perl 6.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 352 kB
  • sloc: perl: 2,052; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,815 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
#!/usr/bin/perl

use strict;
use warnings;
use Test::More tests => 12;
use HTML::Form;

my $html = do { local $/ = undef; <DATA> };
my $form = HTML::Form->parse( $html, 'foo.html' );
isa_ok( $form, 'HTML::Form' );
my $input = $form->find_input('passwd');
isa_ok( $input, 'HTML::Form::TextInput' );

sub set_value {
    my $input = shift;
    my $value = shift;
    my $len   = length($value);
    my $old   = $input->value;
    is( $input->value($value), $old,   "set value length=$len" );
    is( $input->value,         $value, "got value length=$len" );
}

{
    is( $input->{maxlength}, 8, 'got maxlength: 8' );

    set_value( $input, '1234' );
    set_value( $input, '1234567890' );
    ok( !$input->strict, "not strict by default" );
    $form->strict(1);
    ok( $input->strict, "input strict change when form strict change" );
    set_value( $input, '1234' );
    eval { set_value( $input, '1234567890' ); };
    like( $@, qr/^Input 'passwd' has maxlength '8' at /, "Exception raised" );
}

__DATA__

<form method="post" action="?" enctype="application/x-www-form-urlencoded" name="login">
<div style="display:none"><input type="hidden" name="node_id" value="109"></div>
<input type="hidden" name="op" value="login" />
<input type="hidden" name="lastnode_id" value="109" />
<table border="0"><tr><td><font size="2">
Login:</font></td><td>
<input type="text" name="user"  size=10 maxlength=34 />
</td></tr><tr><td><font size="2">
Password</font></td><td>
<input type="password" name="passwd"  size=10 MAXLENGTH=8 />

</td></tr></table><font size="2">
<input type="checkbox" name="expires" value="+10y" />remember me
<input type="submit" name="login" value="Login" />
</font><br />
<a href="?node=What%27s%20my%20password%3F">password reminder</a>
<br />
<a href="?node_id=101">Create A New User</a>
</form>