Skip to content

Commit 143f882

Browse files
failing test for new Text validation issue
1 parent 175ae39 commit 143f882

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

t/fields/text-subclass.t

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use strict;
2+
use warnings;
3+
use Test::More;
4+
5+
{
6+
package MyApp::Field::DuplicateText;
7+
use HTML::FormHandler::Moose;
8+
extends 'HTML::FormHandler::Field::Text';
9+
10+
apply [ {
11+
transform => sub {
12+
my $value = shift;
13+
# collapses down to a single entry if passed a list where all
14+
# values are identical
15+
return $value->[0] if
16+
defined $value
17+
and ref $value eq 'ARRAY'
18+
and map { $value->[0] eq $_ } @$value;
19+
return $value;
20+
},
21+
}];
22+
}
23+
24+
25+
# tests the TextCSV field
26+
{
27+
package MyApp::Form::Test;
28+
use HTML::FormHandler::Moose;
29+
extends 'HTML::FormHandler';
30+
31+
has_field 'foo' => ( type => '+MyApp::Field::DuplicateText' );
32+
has_field 'bar' => ( type => '+MyApp::Field::DuplicateText' );
33+
}
34+
35+
my $form = MyApp::Form::Test->new;
36+
ok( $form );
37+
$form->process( params => { foo => '1', bar => ['2,2'] } );
38+
39+
TODO: {
40+
local $TODO = 'this test broke with commit 0cae37c6';
41+
42+
ok($form->validated, 'field of list values validates')
43+
or diag 'got errors: ', explain [ $form->errors_by_name ];
44+
45+
}
46+
47+
done_testing;

0 commit comments

Comments
 (0)