File: nested2.t

package info (click to toggle)
libhtml-formhandler-perl 0.40067-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,432 kB
  • ctags: 697
  • sloc: perl: 9,312; makefile: 2
file content (38 lines) | stat: -rw-r--r-- 951 bytes parent folder | download | duplicates (5)
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
use strict;
use warnings;
use Test::More;

{
   package Test::Form::Field::Phone;
   use HTML::FormHandler::Moose;
   extends 'HTML::FormHandler::Field::Compound';

   has_field 'id' => ( type => 'PrimaryKey' );
   has_field 'number';
   has_field 'comment';
}

{
   package Test::Form::Client;
   use HTML::FormHandler::Moose;
   extends 'HTML::FormHandler';

   has_field 'name' => (type => 'Text');
   has_field 'comment';
   has_field 'phones' => ( type => 'Repeatable' );
   has_field 'phones.contains' =>  ( type => '+Test::Form::Field::Phone');
}

my $form = Test::Form::Client->new;
$form->process(params=>{
      name => 'test client',
      phones => [
     {id=> 0, number => '123', comment => 'phone comment'}
      ]
   });
ok( $form, 'form built' );
is($form->field('phones.0.number')->value, '123', 'phone number is correct');
is($form->field('phones.0.comment')->id, 'phones.0.comment', 'phone comment id is correct');

done_testing;