| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Test::More; |
| 4 |
use Test::Memory::Cycle; |
| 5 |
|
| 6 |
{ |
| 7 |
package My::RepeatableForm; |
| 8 |
use HTML::FormHandler::Moose; |
| 9 |
extends 'HTML::FormHandler'; |
| 10 |
|
| 11 |
has '+name' => ( default => 'testform' ); |
| 12 |
has_field 'reqname' => ( required => 1 ); |
| 13 |
has_field 'vegetables' => ( type => 'Multiple' ); |
| 14 |
sub options_vegetables { |
| 15 |
return ( |
| 16 |
1 => 'lettuce', |
| 17 |
2 => 'broccoli', |
| 18 |
3 => 'carrots', |
| 19 |
4 => 'peas', |
| 20 |
); |
| 21 |
} |
| 22 |
has_field 'entries' => ( |
| 23 |
type => 'Repeatable', |
| 24 |
required => 1, |
| 25 |
required_message => 'Request without entries not accepted' |
| 26 |
); |
| 27 |
has_field 'entries.rule_index' => ( type => 'PrimaryKey' ); |
| 28 |
has_field 'entries.foo' => ( |
| 29 |
type => 'Text', |
| 30 |
required => 1, |
| 31 |
); |
| 32 |
has_field 'entries.bar' => ( |
| 33 |
type => 'Text', |
| 34 |
required => 1, |
| 35 |
); |
| 36 |
has_field 'some_select' => ( type => 'Select', inactive => 1 ); |
| 37 |
|
| 38 |
sub update_model { |
| 39 |
my $self = shift; |
| 40 |
my $value = $self->field('some_select')->value; |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
my $form = new_ok( 'My::RepeatableForm' ); |
| 45 |
|
| 46 |
my $params = { |
| 47 |
reqname => 'Testrequest', |
| 48 |
'entries.1.foo' => 'test1', |
| 49 |
'entries.1.bar' => 'test1', |
| 50 |
'entries.2.foo' => 'test2', |
| 51 |
'entries.2.bar' => 'test2', |
| 52 |
}; |
| 53 |
memory_cycle_ok( $form, 'form has no memory cycles before process' ); |
| 54 |
ok( $form->process( params => $params ), 'form processed ok' ); |
| 55 |
memory_cycle_ok( $form, 'form has no memory cycles after process' ); |
| 56 |
|
| 57 |
done_testing; |
| 58 |
|