PageRenderTime 40ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/xt/multiple_forms.t

http://github.com/gshank/html-formhandler
Unknown | 76 lines | 63 code | 13 blank | 0 comment | 0 complexity | 7ace6c23be4b1242dfce4398e88b56cc MD5 | raw file
  1. use Test::More tests => 9;
  2. use_ok( 'HTML::FormHandler' );
  3. {
  4. package My::Form::One;
  5. use HTML::FormHandler::Moose;
  6. extends 'HTML::FormHandler';
  7. # this form specifies the form name
  8. has '+name' => ( default => 'One' );
  9. has '+html_prefix' => ( default => 1 );
  10. has_field 'field_one';
  11. has_field 'field_two';
  12. has_field 'field_three';
  13. }
  14. my $form1 = My::Form::One->new;
  15. ok( $form1, 'get first form' );
  16. {
  17. package My::Form::Two;
  18. use Moose;
  19. extends 'HTML::FormHandler';
  20. # this form uses the default random form name generation
  21. has '+html_prefix' => ( default => 1 );
  22. sub field_list {
  23. [
  24. field_one => 'Text',
  25. field_two => 'Text',
  26. field_three => 'Text',
  27. ]
  28. }
  29. }
  30. my $form2 = My::Form::Two->new;
  31. ok( $form2, 'get second form' );
  32. my $params = {
  33. 'One.field_one' => 'First field in first form',
  34. 'One.field_two' => 'Second field in first form',
  35. 'One.field_three' => 'Third field in first form',
  36. $form2->field('field_one')->html_name =>
  37. 'First field in second form',
  38. $form2->field('field_two')->html_name =>
  39. 'Second field in second form',
  40. $form2->field('field_three')->html_name =>
  41. 'Third field in second form',
  42. };
  43. $form1->process( $params );
  44. ok( $form1->validated, 'validated first form' );
  45. is( $form1->field('field_one')->value, 'First field in first form',
  46. 'value of field in first form is correct' );
  47. my $fif_params = $form1->fif;
  48. is_deeply( $fif_params, {
  49. 'One.field_one' => 'First field in first form',
  50. 'One.field_two' => 'Second field in first form',
  51. 'One.field_three' => 'Third field in first form',
  52. }, 'fif params correct');
  53. $form2->process( $params );
  54. ok( $form2->validated, 'validated second form' );
  55. is( $form2->field('field_three')->value, 'Third field in second form',
  56. 'value of field in second form is correct' );
  57. $params = {
  58. 'One.field_one' => 'First field in first form',
  59. 'One.field_two' => 'Second field in first form',
  60. 'One.field_three' => 'Third field in first form',
  61. };
  62. $form2 = My::Form::Two->new( params => $params );
  63. ok( !$form2->has_params, 'has_params checks only params intented for the form');